Skip to content

Commit

Permalink
Packaging : rend l'installation de tinify optionnelle (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Aug 28, 2023
2 parents 1d98a80 + 99fe107 commit 04596dc
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
python -m pip install -U build
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Build a binary wheel and a source tarball
run: >-
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
python -m pip install -U -r requirements/packaging.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Generates Executable
run: python -O ./builder/pyinstaller_build_macos.py
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
python -m pip install -U -r requirements/packaging.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Generates Executable
run: python -O ./builder/pyinstaller_build_ubuntu.py
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
python -m pip install -U -r requirements/packaging.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Generates MS Version Info
run: python .\builder\version_info_templater.py
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
python -m pip install -U -r requirements.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Génère les exemples de sortie
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
python -m pip install -U -r requirements/testing.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: Unit tests
run: pytest
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
python -m pip install -U -r requirements.txt
- name: Install project as a package
run: python -m pip install -e .
run: python -m pip install -e .[all]

- name: CLI - Echoing version
run: geotribu --version
Expand Down
4 changes: 2 additions & 2 deletions docs/development/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ source .venv/bin/activate
python -m pip install -U pip setuptools wheel
# installation des dépendances de base
python -m pip install -U -r requirements.txt
# installation du projet en mode développement
python -m pip install -e .
# installation du projet en mode développement avec toutes les dépendances fonctionnelles
python -m pip install -e .[all,dev,doc,test]
```
2 changes: 1 addition & 1 deletion docs/usage/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MacOS version is not tested and is just here to encourage beta-testing and feedb
### Installer

```sh
pip install --user --upgrade geotribu
pip install --upgrade geotribu
```

L'outil est désormais disponible en ligne de commande. Voir les [exemples](/usage/examples).
Expand Down
12 changes: 11 additions & 1 deletion geotribu_cli/images/images_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from pathlib import Path

# package
from geotribu_cli.__about__ import __package_name__
from geotribu_cli.console import console
from geotribu_cli.constants import GeotribuDefaults
from geotribu_cli.images.optim_tinify import optimize_with_tinify
from geotribu_cli.images.optim_tinify import TINIFY_INSTALLED, optimize_with_tinify
from geotribu_cli.utils.check_path import check_path
from geotribu_cli.utils.start_uri import open_uri
from geotribu_cli.utils.str2bool import str2bool
Expand Down Expand Up @@ -109,6 +110,15 @@ def run(args: argparse.Namespace):

# check Tinify API KEY
if args.tool_to_use == "tinypng":
if not TINIFY_INSTALLED:
logger.critical(
"Tinify n'est pas installé, le service ne peut donc pas être utilisé. "
"Pour l'utiliser, installer l'outil avec les dépendances "
f"supplémentaires : pip install {__package_name__}[img-remote] ou "
f"pip install {__package_name__}[all]"
)
sys.exit(1)

if not getenv("TINIFY_API_KEY"):
logger.critical(
"La clé d'API de Tinify n'est pas configurée en variable "
Expand Down
7 changes: 6 additions & 1 deletion geotribu_cli/images/optim_tinify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
from urllib.parse import unquote, urlsplit

# 3rd party
import tinify
try:
import tinify

TINIFY_INSTALLED = True
except ImportError:
TINIFY_INSTALLED = False

# package
from geotribu_cli.constants import GeotribuDefaults
Expand Down
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ orjson>=3.8,<3.10
packaging>=20,<24
rich_argparse>=0.6,<1.4
python-frontmatter>=1,<2
tinify>=1.6,<2
typing-extensions>=4,<5 ; python_version < '3.11'
1 change: 1 addition & 0 deletions requirements/extra.img-remote.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tinify>=1.6,<2
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ def load_requirements(requirements_files: Union[Path, list[Path]]) -> list:
include_package_data=True,
install_requires=load_requirements(HERE / "requirements/base.txt"),
extras_require={
# tooling
"dev": load_requirements(HERE / "requirements/development.txt"),
"doc": load_requirements(HERE / "requirements/documentation.txt"),
"test": load_requirements(HERE / "requirements/testing.txt"),
# functional
"all": load_requirements(
list(HERE.joinpath("requirements").glob("extra.*.txt"))
),
"img-remote": load_requirements(HERE / "requirements/extra.img-remote.txt"),
},
# cli
entry_points={
Expand Down

0 comments on commit 04596dc

Please sign in to comment.