Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: pip install .[cpu,cli,dev]
- run: mypy --install-types --non-interactive --ignore-missing-imports ./rembg
- run: bandit --recursive --skip B101,B104,B310,B311,B303,B110 --exclude ./rembg/_version.py ./rembg
- run: black --force-exclude rembg/_version.py --check --diff ./rembg
- run: flake8 ./rembg --count --ignore=B008,C901,E203,E266,E731,F401,F811,F841,W503,E501,E402 --show-source --statistics --exclude ./rembg/_version.py
- run: isort --check-only --profile black ./rembg
run: poetry install --with dev --extras "cpu cli"
- run: poetry run mypy --install-types --non-interactive --ignore-missing-imports ./rembg
- run: poetry run bandit --recursive --skip B101,B104,B310,B311,B303,B110 --exclude ./rembg/_version.py ./rembg
- run: poetry run black --force-exclude rembg/_version.py --check --diff ./rembg
- 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
- run: poetry run isort --check-only --profile black ./rembg
20 changes: 14 additions & 6 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: pip install .[cpu,cli,dev]
- name: Builds and uploads to PyPI
run: |
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install --with dev --extras "cpu cli"
- name: Build and publish to PyPI
run: |
poetry build
poetry publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PIPY_PASSWORD }}
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PIPY_PASSWORD }}
11 changes: 8 additions & 3 deletions .github/workflows/test_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: pip install .[cpu,cli,dev]
run: poetry install --with dev --extras "cpu cli"
- name: Test installation with pytest
run: |
attempt=0
until rembg d || [ $attempt -eq 5 ]; do
until poetry run rembg d || [ $attempt -eq 5 ]; do
attempt=$((attempt+1))
echo "Attempt $attempt to download the models..."
done
if [ $attempt -eq 5 ]; then
echo "downloading the models failed 5 times, exiting..."
exit 1
fi
pytest
poetry run pytest
6 changes: 5 additions & 1 deletion .github/workflows/windows_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ jobs:
name: Build the Inno Setup Installer
runs-on: windows-latest
steps:
- uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install Poetry
run: |
pip install poetry
poetry --version
- shell: pwsh
run: ./_build-exe.ps1
- name: Compile .ISS to .EXE Installer
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ __pycache__/
.tox
.cache
.mypy_cache

# Poetry
# For libraries, poetry.lock is often not committed
# For applications, it should be committed
poetry.lock
7 changes: 0 additions & 7 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
include MANIFEST.in
include LICENSE.txt
include README.md
include setup.py
include pyproject.toml
include requirements.txt
include requirements-gpu.txt

include versioneer.py
include rembg/_version.py
17 changes: 12 additions & 5 deletions _build-exe.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Install required packages
pip install pyinstaller
pip install -e ".[cli]"
# Install Poetry if not already installed
if (-not (Get-Command poetry -ErrorAction SilentlyContinue)) {
pip install poetry
}

# Install project dependencies with cli extras
poetry install --extras "cli"

# Install pyinstaller in the poetry environment
poetry run pip install pyinstaller

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

# Run PyInstaller with the generated spec file
pyinstaller rembg.spec
poetry run pyinstaller rembg.spec
96 changes: 86 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,89 @@
[tool.poetry]
name = "rembg"
version = "0.0.0" # Managed by poetry-dynamic-versioning
description = "Remove image background"
authors = ["Daniel Gatis <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/danielgatis/rembg"
repository = "https://github.com/danielgatis/rembg"
keywords = ["remove", "background", "u2net"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
packages = [{include = "rembg"}]

[tool.poetry.dependencies]
python = "^3.10"
jsonschema = "^4.25.0"
numpy = "^2.2.0"
opencv-python-headless = "^4.12.0"
pillow = "^11.3.0"
pooch = "^1.8.0"
pymatting = "^1.1.14"
scikit-image = "^0.25.0"
scipy = "^1.15.0"
tqdm = "^4.67.0"

# CPU backend (optional)
onnxruntime = {version = "^1.23.0", optional = true}

# GPU backend (optional) - only available on Linux/Windows, not on macOS
onnxruntime-gpu = {version = "^1.23.0", optional = true, markers = "sys_platform != 'darwin'"}

# ROCm backend (optional) - only available on Linux (latest is 1.22.x)
onnxruntime-rocm = {version = "^1.22.0", optional = true, markers = "sys_platform == 'linux'"}

# CLI dependencies (optional)
aiohttp = {version = "^3.13.0", optional = true}
asyncer = {version = "^0.0.10", optional = true}
click = {version = "^8.3.0", optional = true}
fastapi = {version = "^0.120.0", optional = true}
filetype = {version = "^1.2.0", optional = true}
gradio = {version = "^5.49.0", optional = true}
python-multipart = {version = "^0.0.20", optional = true}
uvicorn = {version = "^0.38.0", optional = true}
watchdog = {version = "^6.0.0", optional = true}

[tool.poetry.group.dev.dependencies]
bandit = "^1.8.0"
black = "^25.9.0"
flake8 = "^7.3.0"
imagehash = "^4.3.0"
isort = "^7.0.0"
mypy = "^1.18.0"
pytest = "^8.4.0"

[tool.poetry.extras]
cpu = ["onnxruntime"]
gpu = ["onnxruntime-gpu"]
rocm = ["onnxruntime-rocm"]
cli = ["aiohttp", "asyncer", "click", "fastapi", "filetype", "gradio", "python-multipart", "uvicorn", "watchdog"]

[tool.poetry.scripts]
rembg = "rembg.cli:main"

[build-system]
# These are the assumed default build requirements from pip:
# https://pip.pypa.io/en/stable/reference/pip/#pep-517-and-518-support
requires = ["setuptools>=65.5.1", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[versioneer]
VCS = "git"
[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "pep440"
versionfile_source = "rembg/_version.py"
versionfile_build = "rembg/_version.py"
tag_prefix = "v"
parentdir_prefix = "rembg-"
pattern = "^v(?P<base>\\d+\\.\\d+\\.\\d+)"

[tool.poetry-dynamic-versioning.substitution]
files = ["rembg/__init__.py"]
10 changes: 8 additions & 2 deletions rembg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from . import _version
try:
from importlib.metadata import PackageNotFoundError, version

__version__ = _version.get_versions()["version"]
try:
__version__ = version("rembg")
except PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development
except ImportError:
__version__ = "0.0.0" # Fallback for older Python versions

from .bg import remove
from .session_factory import new_session
Loading