Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

Split depedencies (#471)

Daniel Gatisbcb45a27ea03
diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml
index 1073150..ac8b27d 100644
--- a/.github/workflows/lint_python.yml
+++ b/.github/workflows/lint_python.yml
@@ -10,9 +10,8 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.11
- - run: pip install --upgrade pip wheel
- - run: pip install --upgrade setuptools
- - run: pip install bandit black flake8 flake8-bugbear flake8-comprehensions isort safety mypy
+ - name: Install dependencies
+ run: pip install .[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
diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml
index b24a48a..eaaf4c9 100644
--- a/.github/workflows/publish_pypi.yml
+++ b/.github/workflows/publish_pypi.yml
@@ -13,11 +13,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.11
- - name: "Installs dependencies"
- run: |
- python3 -m pip install --upgrade pip
- python3 -m pip install setuptools wheel twine
- - name: "Builds and uploads to PyPI"
+ - name: Install dependencies
+ run: pip install .[cli,dev]
+ - name: Builds and uploads to PyPI
run: |
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml
index 4c12863..763f2a2 100644
--- a/.github/workflows/test-install.yml
+++ b/.github/workflows/test-install.yml
@@ -15,11 +15,8 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- - name: Install package
- run: |
- python -m pip install --upgrade pip
- pip install .
- pip install pytest
+ - name: Install dependencies
+ run: pip install .[cli,dev]
- name: Test installation with pytest
run: |
pytest
diff --git a/.github/workflows/test-specific-environment.yml b/.github/workflows/test-specific-environment.yml
deleted file mode 100644
index 4b287bf..0000000
--- a/.github/workflows/test-specific-environment.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-name: Test in specific environment
-
-on: [push]
-
-jobs:
- build:
- runs-on: ubuntu-latest
- strategy:
- matrix:
- python-version: ["3.8", "3.9", "3.10", "3.11"]
-
- steps:
- - uses: actions/checkout@v3
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v4
- with:
- python-version: ${{ matrix.python-version }}
- - name: Set up environment
- run: |
- python -m pip install --upgrade pip
- pip install pytest
- pip install -r requirements.txt
- - name: Test with pytest
- run: |
- PYTHONPATH=$PYTHONPATH:. pytest .
diff --git a/README.md b/README.md
index 805ff2c..5b3f48e 100644
--- a/README.md
+++ b/README.md
@@ -80,7 +80,8 @@ python: >3.7, <3.12
CPU support:
```bash
-pip install rembg
+pip install rembg # for library
+pip install rembg[cli] # for library + cli
```
GPU support:
@@ -96,7 +97,8 @@ Go to https://onnxruntime.ai and check the installation matrix.
If yes, just run:
```bash
-pip install rembg[gpu]
+pip install rembg[gpu] # for library
+pip install rembg[gpu,cli] # for library + cli
```
## Usage as a cli
diff --git a/rembg/cli.py b/rembg/cli.py
index bd3ac26..e986261 100644
--- a/rembg/cli.py
+++ b/rembg/cli.py
@@ -1,14 +1,33 @@
-import click
+import pkg_resources
-from . import _version
-from .commands import command_functions
-
[email protected]_option(version=_version.get_versions()["version"])
def main() -> None:
- pass
+ package_distribution = pkg_resources.get_distribution("rembg")
+
+ for extra in package_distribution.extras:
+ if extra == "cli":
+ requirements = package_distribution.requires(extras=(extra,))
+ for requirement in requirements:
+ try:
+ pkg_resources.require(requirement.project_name)
+ except pkg_resources.DistributionNotFound:
+ print(f"Missing dependency: '{requirement.project_name}'")
+ print(
+ "Please, install rembg with the cli feature: pip install rembg[cli]"
+ )
+ exit(1)
+
+ import click
+
+ from . import _version
+ from .commands import command_functions
+
+ @click.group()
+ @click.version_option(version=_version.get_versions()["version"])
+ def _main() -> None:
+ pass
+ for command in command_functions:
+ _main.add_command(command)
-for command in command_functions:
- main.add_command(command)
+ _main()
diff --git a/requirements-gpu.txt b/requirements-gpu.txt
deleted file mode 100644
index 617e84d..0000000
--- a/requirements-gpu.txt
+++ /dev/null
@@ -1 +0,0 @@
-onnxruntime-gpu
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 63962f4..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-aiohttp
-asyncer
-click
-fastapi
-filetype
-gradio
-imagehash
-numpy
-onnxruntime
-opencv-python-headless
-pillow
-pooch
-pymatting
-python-multipart
-scikit-image
-scipy
-tqdm
-uvicorn
-watchdog
diff --git a/setup.py b/setup.py
index 22a2fa4..542d2a2 100644
--- a/setup.py
+++ b/setup.py
@@ -11,6 +11,52 @@ here = pathlib.Path(__file__).parent.resolve()
long_description = (here / "README.md").read_text(encoding="utf-8")
+install_requires = [
+ "numpy",
+ "onnxruntime",
+ "opencv-python-headless",
+ "pillow",
+ "pooch",
+ "pymatting",
+ "scikit-image",
+ "scipy",
+]
+
+extras_require = {
+ "dev": [
+ "bandit",
+ "black",
+ "flake8",
+ "imagehash",
+ "isort",
+ "mypy",
+ "pytest",
+ "setuptools",
+ "twine",
+ "wheel",
+ ],
+ "gpu": ["onnxruntime-gpu"],
+ "cli": [
+ "aiohttp",
+ "asyncer",
+ "click",
+ "fastapi",
+ "filetype",
+ "gradio",
+ "python-multipart",
+ "tqdm",
+ "uvicorn",
+ "watchdog",
+ ],
+}
+
+entry_points = {
+ "console_scripts": [
+ "rembg=rembg.cli:main",
+ ],
+}
+
+
setup(
name="rembg",
description="Remove image background",
@@ -35,37 +81,11 @@ setup(
"Programming Language :: Python :: 3.11",
],
keywords="remove, background, u2net",
- packages=["rembg", "rembg.sessions", "rembg.commands"],
python_requires=">=3.8, <3.12",
- install_requires=[
- "aiohttp",
- "asyncer",
- "click",
- "fastapi",
- "filetype",
- "gradio",
- "imagehash",
- "numpy",
- "onnxruntime",
- "opencv-python-headless",
- "pillow",
- "pooch",
- "pymatting",
- "python-multipart",
- "scikit-image",
- "scipy",
- "tqdm",
- "uvicorn",
- "watchdog",
- ],
- entry_points={
- "console_scripts": [
- "rembg=rembg.cli:main",
- ],
- },
- extras_require={
- "gpu": ["onnxruntime-gpu"],
- },
+ packages=find_packages(),
+ install_requires=install_requires,
+ entry_points=entry_points,
+ extras_require=extras_require,
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
)