Skip to content

Commit d0b8f0d

Browse files
committed
add poetry
1 parent 8fc1036 commit d0b8f0d

File tree

15 files changed

+153
-2993
lines changed

15 files changed

+153
-2993
lines changed

.github/workflows/lint_python.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010
- uses: actions/setup-python@v5
11+
- name: Install Poetry
12+
uses: snok/install-poetry@v1
13+
with:
14+
virtualenvs-create: true
15+
virtualenvs-in-project: true
1116
- name: Install dependencies
12-
run: pip install .[cpu,cli,dev]
13-
- run: mypy --install-types --non-interactive --ignore-missing-imports ./rembg
14-
- run: bandit --recursive --skip B101,B104,B310,B311,B303,B110 --exclude ./rembg/_version.py ./rembg
15-
- run: black --force-exclude rembg/_version.py --check --diff ./rembg
16-
- run: flake8 ./rembg --count --ignore=B008,C901,E203,E266,E731,F401,F811,F841,W503,E501,E402 --show-source --statistics --exclude ./rembg/_version.py
17-
- run: isort --check-only --profile black ./rembg
17+
run: poetry install --with dev --extras "cpu cli"
18+
- run: poetry run mypy --install-types --non-interactive --ignore-missing-imports ./rembg
19+
- run: poetry run bandit --recursive --skip B101,B104,B310,B311,B303,B110 --exclude ./rembg/_version.py ./rembg
20+
- run: poetry run black --force-exclude rembg/_version.py --check --diff ./rembg
21+
- run: poetry run flake8 ./rembg --count --ignore=B008,C901,E203,E266,E731,F401,F811,F841,W503,E501,E402 --show-source --statistics --exclude ./rembg/_version.py
22+
- run: poetry run isort --check-only --profile black ./rembg

.github/workflows/publish_pypi.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
1315
- uses: actions/setup-python@v5
16+
- name: Install Poetry
17+
uses: snok/install-poetry@v1
18+
with:
19+
virtualenvs-create: true
20+
virtualenvs-in-project: true
1421
- name: Install dependencies
15-
run: pip install .[cpu,cli,dev]
16-
- name: Builds and uploads to PyPI
1722
run: |
18-
python3 setup.py sdist bdist_wheel
19-
python3 -m twine upload dist/*
23+
poetry self add "poetry-dynamic-versioning[plugin]"
24+
poetry install --with dev --extras "cpu cli"
25+
- name: Build and publish to PyPI
26+
run: |
27+
poetry build
28+
poetry publish
2029
env:
21-
TWINE_USERNAME: __token__
22-
TWINE_PASSWORD: ${{ secrets.PIPY_PASSWORD }}
30+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PIPY_PASSWORD }}

.github/workflows/test_install.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ jobs:
1515
uses: actions/setup-python@v5
1616
with:
1717
python-version: ${{ matrix.python-version }}
18+
- name: Install Poetry
19+
uses: snok/install-poetry@v1
20+
with:
21+
virtualenvs-create: true
22+
virtualenvs-in-project: true
1823
- name: Install dependencies
19-
run: pip install .[cpu,cli,dev]
24+
run: poetry install --with dev --extras "cpu cli"
2025
- name: Test installation with pytest
2126
run: |
2227
attempt=0
23-
until rembg d || [ $attempt -eq 5 ]; do
28+
until poetry run rembg d || [ $attempt -eq 5 ]; do
2429
attempt=$((attempt+1))
2530
echo "Attempt $attempt to download the models..."
2631
done
2732
if [ $attempt -eq 5 ]; then
2833
echo "downloading the models failed 5 times, exiting..."
2934
exit 1
3035
fi
31-
pytest
36+
poetry run pytest

.github/workflows/windows_installer.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ jobs:
99
name: Build the Inno Setup Installer
1010
runs-on: windows-latest
1111
steps:
12-
- uses: actions/setup-python@v5
1312
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
- name: Install Poetry
15+
run: |
16+
pip install poetry
17+
poetry --version
1418
- shell: pwsh
1519
run: ./_build-exe.ps1
1620
- name: Compile .ISS to .EXE Installer

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ __pycache__/
1818
.tox
1919
.cache
2020
.mypy_cache
21+
22+
# Poetry
23+
# For libraries, poetry.lock is often not committed
24+
# For applications, it should be committed
25+
poetry.lock

MANIFEST.in

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
include MANIFEST.in
21
include LICENSE.txt
32
include README.md
4-
include setup.py
53
include pyproject.toml
6-
include requirements.txt
7-
include requirements-gpu.txt
8-
9-
include versioneer.py
10-
include rembg/_version.py

_build-exe.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
# Install required packages
2-
pip install pyinstaller
3-
pip install -e ".[cli]"
1+
# Install Poetry if not already installed
2+
if (-not (Get-Command poetry -ErrorAction SilentlyContinue)) {
3+
pip install poetry
4+
}
5+
6+
# Install project dependencies with cli extras
7+
poetry install --extras "cli"
8+
9+
# Install pyinstaller in the poetry environment
10+
poetry run pip install pyinstaller
411

512
# Create PyInstaller spec file with specified data collections
6-
# pyi-makespec --collect-data=gradio_client --collect-data=gradio rembg.py
13+
# poetry run pyi-makespec --collect-data=gradio_client --collect-data=gradio rembg.py
714

815
# Run PyInstaller with the generated spec file
9-
pyinstaller rembg.spec
16+
poetry run pyinstaller rembg.spec

pyproject.toml

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,89 @@
1+
[tool.poetry]
2+
name = "rembg"
3+
version = "0.0.0" # Managed by poetry-dynamic-versioning
4+
description = "Remove image background"
5+
authors = ["Daniel Gatis <[email protected]>"]
6+
license = "MIT"
7+
readme = "README.md"
8+
homepage = "https://github.com/danielgatis/rembg"
9+
repository = "https://github.com/danielgatis/rembg"
10+
keywords = ["remove", "background", "u2net"]
11+
classifiers = [
12+
"License :: OSI Approved :: MIT License",
13+
"Topic :: Scientific/Engineering",
14+
"Topic :: Scientific/Engineering :: Mathematics",
15+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
16+
"Topic :: Software Development",
17+
"Topic :: Software Development :: Libraries",
18+
"Topic :: Software Development :: Libraries :: Python Modules",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3 :: Only",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
]
26+
packages = [{include = "rembg"}]
27+
28+
[tool.poetry.dependencies]
29+
python = "^3.10"
30+
jsonschema = "^4.25.0"
31+
numpy = "^2.2.0"
32+
opencv-python-headless = "^4.12.0"
33+
pillow = "^11.3.0"
34+
pooch = "^1.8.0"
35+
pymatting = "^1.1.14"
36+
scikit-image = "^0.25.0"
37+
scipy = "^1.15.0"
38+
tqdm = "^4.67.0"
39+
40+
# CPU backend (optional)
41+
onnxruntime = {version = "^1.23.0", optional = true}
42+
43+
# GPU backend (optional) - only available on Linux/Windows, not on macOS
44+
onnxruntime-gpu = {version = "^1.23.0", optional = true, markers = "sys_platform != 'darwin'"}
45+
46+
# ROCm backend (optional) - only available on Linux (latest is 1.22.x)
47+
onnxruntime-rocm = {version = "^1.22.0", optional = true, markers = "sys_platform == 'linux'"}
48+
49+
# CLI dependencies (optional)
50+
aiohttp = {version = "^3.13.0", optional = true}
51+
asyncer = {version = "^0.0.10", optional = true}
52+
click = {version = "^8.3.0", optional = true}
53+
fastapi = {version = "^0.120.0", optional = true}
54+
filetype = {version = "^1.2.0", optional = true}
55+
gradio = {version = "^5.49.0", optional = true}
56+
python-multipart = {version = "^0.0.20", optional = true}
57+
uvicorn = {version = "^0.38.0", optional = true}
58+
watchdog = {version = "^6.0.0", optional = true}
59+
60+
[tool.poetry.group.dev.dependencies]
61+
bandit = "^1.8.0"
62+
black = "^25.9.0"
63+
flake8 = "^7.3.0"
64+
imagehash = "^4.3.0"
65+
isort = "^7.0.0"
66+
mypy = "^1.18.0"
67+
pytest = "^8.4.0"
68+
69+
[tool.poetry.extras]
70+
cpu = ["onnxruntime"]
71+
gpu = ["onnxruntime-gpu"]
72+
rocm = ["onnxruntime-rocm"]
73+
cli = ["aiohttp", "asyncer", "click", "fastapi", "filetype", "gradio", "python-multipart", "uvicorn", "watchdog"]
74+
75+
[tool.poetry.scripts]
76+
rembg = "rembg.cli:main"
77+
178
[build-system]
2-
# These are the assumed default build requirements from pip:
3-
# https://pip.pypa.io/en/stable/reference/pip/#pep-517-and-518-support
4-
requires = ["setuptools>=65.5.1", "wheel"]
5-
build-backend = "setuptools.build_meta"
79+
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
80+
build-backend = "poetry_dynamic_versioning.backend"
681

7-
[versioneer]
8-
VCS = "git"
82+
[tool.poetry-dynamic-versioning]
83+
enable = true
84+
vcs = "git"
985
style = "pep440"
10-
versionfile_source = "rembg/_version.py"
11-
versionfile_build = "rembg/_version.py"
12-
tag_prefix = "v"
13-
parentdir_prefix = "rembg-"
86+
pattern = "^v(?P<base>\\d+\\.\\d+\\.\\d+)"
87+
88+
[tool.poetry-dynamic-versioning.substitution]
89+
files = ["rembg/__init__.py"]

rembg/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
from . import _version
1+
try:
2+
from importlib.metadata import version, PackageNotFoundError
23

3-
__version__ = _version.get_versions()["version"]
4+
try:
5+
__version__ = version("rembg")
6+
except PackageNotFoundError:
7+
__version__ = "0.0.0" # Fallback for development
8+
except ImportError:
9+
__version__ = "0.0.0" # Fallback for older Python versions
410

511
from .bg import remove
612
from .session_factory import new_session

0 commit comments

Comments
 (0)