Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI as strava_py #1

Merged
merged 2 commits into from
Feb 5, 2022
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The process for downloading data is described on the Strava website here: [https

### Process the data

The main function for importing and processing activity files expects a path to a directory of unzipped GPX and / or FIT files. If required, the [fit2gpx](https://github.com/dodo-saba/fit2gpx) package provides useful tools for pre-processing bulk files exported from Stava, e.g. unzipping activity files (see Use Case 3: Strava Bulk Export Tools).
The main function for importing and processing activity files expects a path to a directory of unzipped GPX and / or FIT files. If required, the [fit2gpx](https://github.com/dodo-saba/fit2gpx) package provides useful tools for pre-processing bulk files exported from Strava, e.g. unzipping activity files (see Use Case 3: Strava Bulk Export Tools).

```python
df = process_data(<path to folder with GPX and / or FIT files>)
Expand Down
50 changes: 50 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[metadata]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains the metadata for the package.

name = strava_py
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the name that would be used for PyPI. Currently https://pypi.org/project/strava_py/ is unused (and https://pypi.org/project/strava/ is taken).

version = 0.0.1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's possible to use things like https://github.com/pypa/setuptools_scm to make it automatically take the version number from Git tags, but let's start off simple.)

description = Create artistic visualisations with your exercise data
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/marcusvolz/strava_py
author = Marcus Volz
license = MIT
license_file = LICENSE
classifiers =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can freely choose classifiers from https://pypi.org/classifiers/. These don't have a huge lot of use, but are listed on a package's PyPI page and can be browsed: https://pypi.org/project/Pillow/

Development Status :: 3 - Alpha
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Artistic Software
Topic :: Multimedia :: Graphics
Topic :: Scientific/Engineering :: Visualization
keywords =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also used on PyPI. Like classifiers, can be useful for people using the PyPI API.

strava
artistic visualisations
artistic
visualisation
exercise data
exercise
project_urls =
Source=https://github.com/marcusvolz/strava_py

[options]
packages = find:
install_requires =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List the dependent packages here, so they get installed when people install our package.

fit2gpx
gpxpy
matplotlib
pandas
seaborn
python_requires = >=3.7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pick a minimum supported Python version. pip uses this to make sure to install only for the known supported versions.

3.7 is the lowest currently supported: https://endoflife.date/python

package_dir = =src
zip_safe = True

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
strava_py = strava_py.cli:main
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this strava_py is the name for the CLI, what the user runs on the command line. Doesn't need to be the same as name= above, but less confusing if they are the same.

3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()
Empty file added src/strava_py/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions src/strava_py/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from strava_py import cli

if __name__ == "__main__":
cli.main()
28 changes: 28 additions & 0 deletions src/strava_py/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import argparse
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used for parsing (and validating) arguments for us.



def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("path", help="Input path to folder with GPX and / or FIT files")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No dashes here, so path is a required argument.

parser.add_argument(
"-o", "--output_file", default="plot.png", help="Output PNG file"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dashes indicate an optional argument with two forms: short -o and long --output_file. If not specified, the default is used.

)
args = parser.parse_args()

# Normally imports go at the top, but scientific libraries can be slow to import
# so let's validate arguments first
from strava_py.plot_facets import plot_facets
from strava_py.process_data import process_data

print("Processing data...")
df = process_data(args.path)

print("Plotting facets...")
plot_facets(df, output_file=args.output_file)
print(f"Saved to {args.output_file}")


if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.