Skip to content

Commit 2e07ece

Browse files
authored
Add poetry (#797)
1 parent df72e3d commit 2e07ece

16 files changed

Lines changed: 216 additions & 3014 deletions

File tree

.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 }}

.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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Rembg is a tool to remove images background.
3636
## Requirements
3737

3838
```text
39-
python: >=3.10, <3.14
39+
python: >=3.11, <3.14
4040
```
4141

4242
## Installation

_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: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,98 @@
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 <danielgatis@gmail.com>"]
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.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
24+
]
25+
packages = [{include = "rembg"}]
26+
27+
[tool.poetry.dependencies]
28+
python = "^3.11"
29+
jsonschema = "^4.25.1"
30+
numpy = "^2.3.0"
31+
pillow = "^12.1.0"
32+
pooch = "^1.8.2"
33+
pymatting = "^1.1.14"
34+
scikit-image = "^0.26.0"
35+
scipy = "^1.16.3"
36+
tqdm = "^4.67.1"
37+
38+
# CPU backend (optional)
39+
onnxruntime = {version = "^1.23.2", optional = true}
40+
41+
# GPU backend (optional) - only available on Linux/Windows, not on macOS
42+
onnxruntime-gpu = {version = "^1.23.2", optional = true, markers = "sys_platform != 'darwin'"}
43+
44+
# ROCm backend (optional) - only available on Linux (latest is 1.22.x)
45+
onnxruntime-rocm = {version = "^1.22.0", optional = true, markers = "sys_platform == 'linux'"}
46+
47+
# CLI dependencies (optional)
48+
aiohttp = {version = "^3.13.2", optional = true}
49+
asyncer = {version = "^0.0.12", optional = true}
50+
click = {version = "^8.3.1", optional = true}
51+
fastapi = {version = "^0.128.0", optional = true}
52+
filetype = {version = "^1.2.0", optional = true}
53+
gradio = {version = "^6.2.0", optional = true}
54+
python-multipart = {version = "^0.0.21", optional = true}
55+
sniffio = {version = "^1.3.1", optional = true}
56+
uvicorn = {version = "^0.40.0", optional = true}
57+
watchdog = {version = "^6.0.0", optional = true}
58+
59+
# Dev dependencies (optional, for pip install .[dev])
60+
bandit = {version = "^1.9.2", optional = true}
61+
black = {version = "^25.12.0", optional = true}
62+
flake8 = {version = "^7.3.0", optional = true}
63+
imagehash = {version = "^4.3.2", optional = true}
64+
isort = {version = "^7.0.0", optional = true}
65+
mypy = {version = "^1.19.1", optional = true}
66+
pytest = {version = "^9.0.2", optional = true}
67+
68+
[tool.poetry.group.dev.dependencies]
69+
bandit = "^1.9.2"
70+
black = "^25.12.0"
71+
flake8 = "^7.3.0"
72+
imagehash = "^4.3.2"
73+
isort = "^7.0.0"
74+
mypy = "^1.19.1"
75+
pytest = "^9.0.2"
76+
77+
[tool.poetry.extras]
78+
cpu = ["onnxruntime"]
79+
gpu = ["onnxruntime-gpu"]
80+
rocm = ["onnxruntime-rocm"]
81+
cli = ["aiohttp", "asyncer", "click", "fastapi", "filetype", "gradio", "python-multipart", "sniffio", "uvicorn", "watchdog"]
82+
dev = ["bandit", "black", "flake8", "imagehash", "isort", "mypy", "pytest"]
83+
84+
[tool.poetry.scripts]
85+
rembg = "rembg.cli:main"
86+
187
[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"
88+
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
89+
build-backend = "poetry_dynamic_versioning.backend"
690

7-
[versioneer]
8-
VCS = "git"
91+
[tool.poetry-dynamic-versioning]
92+
enable = true
93+
vcs = "git"
994
style = "pep440"
10-
versionfile_source = "rembg/_version.py"
11-
versionfile_build = "rembg/_version.py"
12-
tag_prefix = "v"
13-
parentdir_prefix = "rembg-"
95+
pattern = "^v(?P<base>\\d+\\.\\d+\\.\\d+)"
96+
97+
[tool.poetry-dynamic-versioning.substitution]
98+
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 PackageNotFoundError, version
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)