Skip to content

Commit

Permalink
refactor: cli tools are installed via extra **cli**
Browse files Browse the repository at this point in the history
  • Loading branch information
kschweiger committed Jan 26, 2024
1 parent 6f5df7a commit 59a05b5
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
python-version: '3.11'
- name: Install package and run cli
run: |
pip install --no-cache-dir --extra-index-url https://pypi.org/simple/ -i https://test.pypi.org/simple/ geo-track-analyzer
pip install --no-cache-dir --extra-index-url https://pypi.org/simple/ -i https://test.pypi.org/simple/ geo-track-analyzer[cli]
enhance-elevation --help
publish-index:
name: Publish Python 🐍 distribution 📦 to PyPI
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
- id: poetry-lock
args: ["--no-update"]
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements/prod.txt", "--without-hashes"]
args: ["-f", "requirements.txt", "-o", "requirements/prod.txt", "--without-hashes", "--all-extras"]
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements/test.txt", "--without-hashes", "--only", "test"]
- id: poetry-export
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

The focus of this package lies on analyzing and visualizing tracks of cycling or similar activities. Depending on the usecase settings like `stopped_speed_threshold` or `max_speed_percentile` may not be appropriate.

Installing the package with **cli** extra, I.e. using `pip install geo-track-analyzer[cli]`, add utility tools. See the [documentation](https://kschweiger.github.io/track_analyzer/cli.html) for details.

## From files

Tracks my be initialized from ``.gpx`` and ``.fit`` files using the ``GPXFileTrack`` and ``FITTrack`` object, respectively.
Expand Down
2 changes: 2 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ To use Geo-Track-Analyzer, first install it using pip:
$ pip install geo-track-analyzer
Installing the package with **cli** extra, I.e. using ``pip install geo-track-analyzer[cli]``, add utility tools. See the :ref:`Command line interfaces` page for details.

Analyze geospacial tracks
-------------------------

Expand Down
3 changes: 3 additions & 0 deletions geo_track_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .cli import extract_track, update_elevation
from .enhancer import (
ElevationEnhancer,
Enhancer,
Expand All @@ -21,4 +22,6 @@
"OpenElevationEnhancer",
"OpenTopoElevationEnhancer",
"get_enhancer",
"update_elevation",
"extract_track",
]
31 changes: 31 additions & 0 deletions geo_track_analyzer/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def generate_error_text(entry_point: str) -> str:
return (
f"The {entry_point} command line interface can not be run because of missing "
"dependencies. Make sure that the package was installed with the **cli** "
"extra. Use: pip install geo-track-analyzer[cli]"
)


try:
from .update_elevation import main as update_elevation
except ImportError:

def update_elevation() -> None:
import sys

print(generate_error_text("enhance-elevation"))
sys.exit(1)


try:
from .extract_track import main as extract_track
except ImportError:

def extract_track() -> None:
import sys

print(generate_error_text("extract-fit-track"))
sys.exit(1)


__all__ = ["update_elevation", "extract_track"]
335 changes: 171 additions & 164 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ pandas = "^2.1.4"
fitparse = "^1.2.0"
pydantic = "^2.5.3"
pydantic-numpy = "^4.1.3"
click = "^8.1.7"
rich = "^13.7.0"
click = { version = "^8.1.7", optional = true }
rich = { version = "^13.7.0", optional = true }

[tool.poetry.extras]
cli = ["click", "rich"]


[tool.poetry.group.dev]
optional = true
Expand Down Expand Up @@ -60,8 +64,8 @@ sphinx-rtd-theme = "^2.0.0"
sphinx-github-changelog = "^1.2.1"

[tool.poetry.scripts]
extract-fit_track = 'geo_track_analyzer.cli.extract_track:main'
enhance-elevation = 'geo_track_analyzer.cli.update_elevation:main'
extract-fit-track = 'geo_track_analyzer:extract_track'
enhance-elevation = 'geo_track_analyzer:update_elevation'

[[tool.poetry.source]]
name = "PyPI"
Expand Down
8 changes: 4 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ git-changelog==2.4.0 ; python_version >= "3.10" and python_version < "3.13"
greenlet==3.0.3 ; python_version >= "3.10" and python_version < "3.13"
identify==2.5.33 ; python_version >= "3.10" and python_version < "3.13"
idna==3.6 ; python_version >= "3.10" and python_version < "3.13"
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "3.13"
jinja2==3.1.3 ; python_version >= "3.10" and python_version < "3.13"
jinxed==1.2.1 ; python_version >= "3.10" and python_version < "3.13" and platform_system == "Windows"
markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "3.13"
markupsafe==2.1.4 ; python_version >= "3.10" and python_version < "3.13"
mccabe==0.7.0 ; python_version >= "3.10" and python_version < "3.13"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "3.13"
mypy==1.8.0 ; python_version >= "3.10" and python_version < "3.13"
Expand All @@ -34,12 +34,12 @@ pygments==2.17.2 ; python_version >= "3.10" and python_version < "3.13"
pyxdg==0.28 ; python_version >= "3.10" and python_version < "3.13"
pyyaml==6.0.1 ; python_version >= "3.10" and python_version < "3.13"
requests==2.31.0 ; python_version >= "3.10" and python_version < "3.13"
ruff==0.1.11 ; python_version >= "3.10" and python_version < "3.13"
ruff==0.1.14 ; python_version >= "3.10" and python_version < "3.13"
semver==3.0.2 ; python_version >= "3.10" and python_version < "3.13"
setuptools==69.0.3 ; python_version >= "3.10" and python_version < "3.13"
six==1.16.0 ; python_version >= "3.10" and python_version < "3.13"
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
types-requests==2.31.0.20240106 ; python_version >= "3.10" and python_version < "3.13"
types-requests==2.31.0.20240125 ; python_version >= "3.10" and python_version < "3.13"
typing-extensions==4.9.0 ; python_version >= "3.10" and python_version < "3.13"
urllib3==2.1.0 ; python_version >= "3.10" and python_version < "3.13"
virtualenv==20.25.0 ; python_version >= "3.10" and python_version < "3.13"
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ markdown-it-py==3.0.0 ; python_version >= "3.10" and python_version < "3.13"
mdurl==0.1.2 ; python_version >= "3.10" and python_version < "3.13"
numpy==1.26.3 ; python_version >= "3.10" and python_version < "3.13"
packaging==23.2 ; python_version >= "3.10" and python_version < "3.13"
pandas==2.1.4 ; python_version >= "3.10" and python_version < "3.13"
pandas==2.2.0 ; python_version >= "3.10" and python_version < "3.13"
plotly==5.18.0 ; python_version >= "3.10" and python_version < "3.13"
pydantic-core==2.14.6 ; python_version >= "3.10" and python_version < "3.13"
pydantic-numpy==4.1.3 ; python_version >= "3.10" and python_version < "3.13"
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coverage[toml]==7.4.0 ; python_version >= "3.10" and python_version < "3.13"
exceptiongroup==1.2.0 ; python_version >= "3.10" and python_version < "3.11"
iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "3.13"
packaging==23.2 ; python_version >= "3.10" and python_version < "3.13"
pluggy==1.3.0 ; python_version >= "3.10" and python_version < "3.13"
pluggy==1.4.0 ; python_version >= "3.10" and python_version < "3.13"
pytest-cov==4.1.0 ; python_version >= "3.10" and python_version < "3.13"
pytest-dependency==0.6.0 ; python_version >= "3.10" and python_version < "3.13"
pytest-mock==3.12.0 ; python_version >= "3.10" and python_version < "3.13"
Expand Down

0 comments on commit 59a05b5

Please sign in to comment.