Skip to content

Commit

Permalink
Use StrEnum for units
Browse files Browse the repository at this point in the history
  • Loading branch information
liskin committed Nov 21, 2023
1 parent 67b7041 commit fc36381
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/strava_gear/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .input.activities import read_input_csv
from .input.activities import read_strava_offline
from .input.rules import read_rules
from .report import Units
from .report import reports


Expand Down Expand Up @@ -54,7 +55,7 @@
'--show-vert/--hide-vert', default=False, show_default=True,
help="Show vertical (elevation gain)")
@click.option(
'--units', type=click.Choice(["metric", "imperial"]), default="metric", show_default=True,
'--units', type=click.Choice(list(Units)), default=Units.METRIC, show_default=True,

Check failure on line 58 in src/strava_gear/cli.py

View workflow job for this annotation

GitHub Actions / check-distro (ubuntu:latest)

No overload variant of "list" matches argument type "Type[Units]"
help="Show data in metric or imperial")
def main(
rules_input: TextIO,
Expand All @@ -66,7 +67,7 @@ def main(
show_name: bool,
show_first_last: bool,
show_vert: bool,
units: str,
units: Units,
):
if csv:
aliases, activities = read_input_csv(csv)
Expand Down
20 changes: 18 additions & 2 deletions src/strava_gear/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import defaultdict
import csv
from enum import StrEnum

Check failure on line 3 in src/strava_gear/report.py

View workflow job for this annotation

GitHub Actions / check (3.8)

Module "enum" has no attribute "StrEnum"

Check failure on line 3 in src/strava_gear/report.py

View workflow job for this annotation

GitHub Actions / check (3.9)

Module "enum" has no attribute "StrEnum"

Check failure on line 3 in src/strava_gear/report.py

View workflow job for this annotation

GitHub Actions / check (3.10)

Module "enum" has no attribute "StrEnum"

Check failure on line 3 in src/strava_gear/report.py

View workflow job for this annotation

GitHub Actions / check-distro (debian:oldstable)

Module "enum" has no attribute "StrEnum"

Check failure on line 3 in src/strava_gear/report.py

View workflow job for this annotation

GitHub Actions / check-distro (ubuntu:latest)

Module "enum" has no attribute "StrEnum"
from enum import auto
from functools import partial
from typing import Dict
from typing import Final
Expand All @@ -16,13 +18,27 @@
FOOT_IN_METERS: Final[float] = 0.3048


def report(f, res: Result, output, tablefmt: str, show_name: bool, show_first_last: bool, show_vert: bool, units: str):
class Units(StrEnum):
METRIC = auto()
IMPERIAL = auto()


def report(
f,
res: Result,
output,
tablefmt: str,
show_name: bool,
show_first_last: bool,
show_vert: bool,
units: Units,
):
def cols(d: Dict) -> Dict:
if not show_name:
del d["name"]
if not show_first_last:
del d["first … last"]
if units == "imperial":
if units == Units.IMPERIAL:
del d["km"]
del d["vert m"]
if not show_vert:
Expand Down

0 comments on commit fc36381

Please sign in to comment.