Skip to content

Commit

Permalink
Split depedencies (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgatis authored Jun 19, 2023
1 parent 3cbad20 commit bcb45a2
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 99 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 0 additions & 25 deletions .github/workflows/test-specific-environment.yml

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
37 changes: 28 additions & 9 deletions rembg/cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import click
import pkg_resources

from . import _version
from .commands import command_functions


@click.group()
@click.version_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()
1 change: 0 additions & 1 deletion requirements-gpu.txt

This file was deleted.

19 changes: 0 additions & 19 deletions requirements.txt

This file was deleted.

80 changes: 50 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,52 @@

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",
Expand All @@ -35,37 +81,11 @@
"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(),
)

0 comments on commit bcb45a2

Please sign in to comment.