Skip to content

refactor: switch from invoke to Makefile and use ruff for formatting and linting #39

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

Merged
merged 1 commit into from
Aug 8, 2024
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
16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@ jobs:
cache: "pip"
- name: Install Dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
make install
- name: Check Formatting
run: |
source venv/bin/activate
inv lint-black
make lint_ruff
- name: Check Linting
run: |
source venv/bin/activate
inv lint-pylint
make lint_pylint
- name: Check Types
run: |
source venv/bin/activate
inv lint-mypy
make lint_mypy
- name: Test
run: |
source venv/bin/activate
inv test
make test
14 changes: 5 additions & 9 deletions .github/workflows/release_helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ jobs:
python-version: 3.8
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
make install
- name: Linting
run: |
. venv/bin/activate
inv lint
make lint
- name: Testing
run: |
. venv/bin/activate
inv test
make test

build:
needs: [create_release, lint]
Expand All @@ -75,11 +72,10 @@ jobs:
python-version: 3.8
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
make install
- name: Build
run: |
inv dist
make dist

release_package:
needs: [create_release, lint]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ __pycache__
dist/
build/
docs/_build
venv/
env/
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml

This file was deleted.

50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.PHONY = venv, lint, test, clean, release

venv:
python3.8 -m venv env

install: venv
env/bin/python -m pip install --upgrade pip
env/bin/pip install -e ".[dev]"

lint_ruff:
env/bin/ruff check epidatpy tests

lint_mypy:
env/bin/mypy epidatpy tests

lint_pylint:
env/bin/pylint epidatpy tests

lint: lint_ruff lint_mypy lint_pylint

format:
env/bin/ruff format epidatpy tests

test:
env/bin/pytest .

docs:
env/bin/sphinx-build -b html docs docs/_build
python -m webbrowser -t "docs/_build/index.html"

clean_docs:
rm -rf docs/_build

clean_build:
rm -rf build dist .eggs
find . -name '*.egg-info' -exec rm -rf {} +
find . -name '*.egg' -exec rm -f {} +

clean_python:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean: clean_docs clean_build clean_python

release: clean lint test
env/bin/python -m build --sdist --wheel

upload: release
env/bin/twine upload dist/*
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,17 @@ TODO

## Development

Prepare virtual environment and install dependencies
The following commands are available for developers:

```sh
python -m venv venv
source ./venv/bin/activate
pip install -e ".[dev]"
```

### Common Commands

```sh
source ./venv/bin/activate
inv format # format code
inv lint # check linting
inv docs # build docs
inv test # run unit tests
inv coverage # run unit tests with coverage
inv clean # clean build artifacts
inv dist # build distribution packages
inv release # upload the current version to pypi
make install # setup venv, install dependencies and local package
make test # run unit tests
make format # format code
make lint # check linting
make docs # build docs
make dist # build distribution packages
make release # upload the current version to pypi
make clean # clean build and docs artifacts
```

### Release Process
Expand Down
23 changes: 11 additions & 12 deletions epidatpy/_covidcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@

@dataclass
class WebLink:
"""
represents a web link
"""represents a web link
"""

alt: str
Expand All @@ -43,8 +42,7 @@ class WebLink:

@dataclass
class DataSignalGeoStatistics:
"""
COVIDcast signal statistics
"""COVIDcast signal statistics
"""

min: float
Expand All @@ -64,7 +62,11 @@ def define_covidcast_fields() -> List[EpidataFieldInfo]:
EpidataFieldInfo("signal", EpidataFieldType.text),
EpidataFieldInfo("geo_type", EpidataFieldType.categorical, categories=list(get_args(GeoType))),
EpidataFieldInfo("geo_value", EpidataFieldType.text),
EpidataFieldInfo("time_type", EpidataFieldType.categorical, categories=list(get_args(TimeType))),
EpidataFieldInfo(
"time_type",
EpidataFieldType.categorical,
categories=list(get_args(TimeType)),
),
EpidataFieldInfo("time_value", EpidataFieldType.date_or_epiweek),
EpidataFieldInfo("issue", EpidataFieldType.date),
EpidataFieldInfo("lag", EpidataFieldType.int),
Expand All @@ -80,8 +82,7 @@ def define_covidcast_fields() -> List[EpidataFieldInfo]:

@dataclass
class DataSignal(Generic[CALL_TYPE]):
"""
represents a COVIDcast data signal
"""represents a COVIDcast data signal
"""

_create_call: Callable[[Mapping[str, Optional[EpiRangeParam]]], CALL_TYPE]
Expand Down Expand Up @@ -160,7 +161,7 @@ def call(
lag: Optional[int] = None,
) -> CALL_TYPE:
"""Fetch Delphi's COVID-19 Surveillance Streams"""
if any((v is None for v in (geo_type, geo_values, time_values))):
if any(v is None for v in (geo_type, geo_values, time_values)):
raise InvalidArgumentException("`geo_type`, `time_values`, and `geo_values` are all required")
if issues is not None and lag is not None:
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
Expand Down Expand Up @@ -194,8 +195,7 @@ def __call__(

@dataclass
class DataSource(Generic[CALL_TYPE]):
"""
represents a COVIDcast data source
"""represents a COVIDcast data source
"""

_create_call: InitVar[Callable[[Mapping[str, Optional[EpiRangeParam]]], CALL_TYPE]]
Expand Down Expand Up @@ -247,8 +247,7 @@ def signal_df(self) -> DataFrame:

@dataclass
class CovidcastDataSources(Generic[CALL_TYPE]):
"""
COVIDcast data source helper.
"""COVIDcast data source helper.
"""

sources: Sequence[DataSource[CALL_TYPE]]
Expand Down
9 changes: 2 additions & 7 deletions epidatpy/_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def get_wildcard_equivalent_dates(time_value: EpiRangeParam, time_type: Literal[


class AEpiDataEndpoints(ABC, Generic[CALL_TYPE]):
"""
epidata endpoint list and fetcher
"""epidata endpoint list and fetcher
"""

@abstractmethod
Expand Down Expand Up @@ -87,8 +86,7 @@ def pub_covid_hosp_facility_lookup(
fips_code: Optional[str] = None,
) -> CALL_TYPE:
"""Lookup COVID hospitalization facility identifiers."""

if all((v is None for v in (state, ccn, city, zip, fips_code))):
if all(v is None for v in (state, ccn, city, zip, fips_code)):
raise InvalidArgumentException("one of `state`, `ccn`, `city`, `zip`, or `fips_code` is required")

return self._create_call(
Expand Down Expand Up @@ -121,7 +119,6 @@ def pub_covid_hosp_facility(
publication_dates: Optional[EpiRangeParam] = None,
) -> CALL_TYPE:
"""Fetch COVID hospitalization data for specific facilities."""

collection_weeks = get_wildcard_equivalent_dates(collection_weeks, "day")

# Confusingly, the endpoint expects `collection_weeks` to be in day format,
Expand Down Expand Up @@ -271,7 +268,6 @@ def pub_covid_hosp_state_timeseries(
as_of: Union[None, int, str] = None,
) -> CALL_TYPE:
"""Fetch COVID hospitalization data."""

if issues is not None and as_of is not None:
raise InvalidArgumentException("`issues` and `as_of` are mutually exclusive")

Expand Down Expand Up @@ -481,7 +477,6 @@ def pub_covidcast(

def pub_delphi(self, system: str, epiweek: Union[int, str]) -> CALL_TYPE:
"""Fetch Delphi's forecast."""

return self._create_call(
"delphi/",
{"system": system, "epiweek": epiweek},
Expand Down
Loading