Skip to content

Commit de47b20

Browse files
committed
repo+lint: switch utilities
* switch to Makefile instead of invoke for tasks (better env handling) * switch from black to ruff for linting and formatting * run through ruff linting and formatting * remove aiohttp, black, coverage, invoke, pre-commit, wheel from dependencies * update ci, README
1 parent d3cb7bc commit de47b20

File tree

13 files changed

+122
-278
lines changed

13 files changed

+122
-278
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,16 @@ jobs:
1818
cache: "pip"
1919
- name: Install Dependencies
2020
run: |
21-
python -m venv venv
22-
source venv/bin/activate
23-
pip install -e ".[dev]"
21+
make install
2422
- name: Check Formatting
2523
run: |
26-
source venv/bin/activate
27-
inv lint-black
24+
make lint_ruff
2825
- name: Check Linting
2926
run: |
30-
source venv/bin/activate
31-
inv lint-pylint
27+
make lint_pylint
3228
- name: Check Types
3329
run: |
34-
source venv/bin/activate
35-
inv lint-mypy
30+
make lint_mypy
3631
- name: Test
3732
run: |
38-
source venv/bin/activate
39-
inv test
33+
make test

.github/workflows/release_helper.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,13 @@ jobs:
5252
python-version: 3.8
5353
- name: Install build dependencies
5454
run: |
55-
python -m pip install --upgrade pip
56-
pip install -e ".[dev]"
55+
make install
5756
- name: Linting
5857
run: |
59-
. venv/bin/activate
60-
inv lint
58+
make lint
6159
- name: Testing
6260
run: |
63-
. venv/bin/activate
64-
inv test
61+
make test
6562
6663
build:
6764
needs: [create_release, lint]
@@ -75,11 +72,10 @@ jobs:
7572
python-version: 3.8
7673
- name: Install build dependencies
7774
run: |
78-
python -m pip install --upgrade pip
79-
pip install -e ".[dev]"
75+
make install
8076
- name: Build
8177
run: |
82-
inv dist
78+
make dist
8379
8480
release_package:
8581
needs: [create_release, lint]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ __pycache__
88
dist/
99
build/
1010
docs/_build
11-
venv/
11+
env/

.pre-commit-config.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.PHONY = venv, lint, test, clean, release
2+
3+
venv:
4+
python3.8 -m venv env
5+
6+
install: venv
7+
env/bin/python -m pip install --upgrade pip
8+
env/bin/pip install -e ".[dev]"
9+
10+
lint_ruff:
11+
env/bin/ruff check epidatpy tests
12+
13+
lint_mypy:
14+
env/bin/mypy epidatpy tests
15+
16+
lint_pylint:
17+
env/bin/pylint epidatpy tests
18+
19+
lint: lint_ruff lint_mypy lint_pylint
20+
21+
format:
22+
env/bin/ruff format epidatpy tests
23+
24+
test:
25+
env/bin/pytest .
26+
27+
docs:
28+
env/bin/sphinx-build -b html docs docs/_build
29+
python -m webbrowser -t "docs/_build/index.html"
30+
31+
clean_docs:
32+
rm -rf docs/_build
33+
34+
clean_build:
35+
rm -rf build dist .eggs
36+
find . -name '*.egg-info' -exec rm -rf {} +
37+
find . -name '*.egg' -exec rm -f {} +
38+
39+
clean_python:
40+
find . -name '*.pyc' -exec rm -f {} +
41+
find . -name '*.pyo' -exec rm -f {} +
42+
find . -name '__pycache__' -exec rm -fr {} +
43+
44+
clean: clean_docs clean_build clean_python
45+
46+
release: clean lint test
47+
env/bin/python -m build --sdist --wheel
48+
49+
upload: release
50+
env/bin/twine upload dist/*

README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,17 @@ TODO
2222

2323
## Development
2424

25-
Prepare virtual environment and install dependencies
25+
The following commands are available for developers:
2626

2727
```sh
28-
python -m venv venv
29-
source ./venv/bin/activate
30-
pip install -e ".[dev]"
31-
```
32-
33-
### Common Commands
34-
35-
```sh
36-
source ./venv/bin/activate
37-
inv format # format code
38-
inv lint # check linting
39-
inv docs # build docs
40-
inv test # run unit tests
41-
inv coverage # run unit tests with coverage
42-
inv clean # clean build artifacts
43-
inv dist # build distribution packages
44-
inv release # upload the current version to pypi
28+
make install # setup venv, install dependencies and local package
29+
make test # run unit tests
30+
make format # format code
31+
make lint # check linting
32+
make docs # build docs
33+
make dist # build distribution packages
34+
make release # upload the current version to pypi
35+
make clean # clean build and docs artifacts
4536
```
4637

4738
### Release Process

epidatpy/_covidcast.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
@dataclass
3535
class WebLink:
36-
"""
37-
represents a web link
36+
"""represents a web link
3837
"""
3938

4039
alt: str
@@ -43,8 +42,7 @@ class WebLink:
4342

4443
@dataclass
4544
class DataSignalGeoStatistics:
46-
"""
47-
COVIDcast signal statistics
45+
"""COVIDcast signal statistics
4846
"""
4947

5048
min: float
@@ -64,7 +62,11 @@ def define_covidcast_fields() -> List[EpidataFieldInfo]:
6462
EpidataFieldInfo("signal", EpidataFieldType.text),
6563
EpidataFieldInfo("geo_type", EpidataFieldType.categorical, categories=list(get_args(GeoType))),
6664
EpidataFieldInfo("geo_value", EpidataFieldType.text),
67-
EpidataFieldInfo("time_type", EpidataFieldType.categorical, categories=list(get_args(TimeType))),
65+
EpidataFieldInfo(
66+
"time_type",
67+
EpidataFieldType.categorical,
68+
categories=list(get_args(TimeType)),
69+
),
6870
EpidataFieldInfo("time_value", EpidataFieldType.date_or_epiweek),
6971
EpidataFieldInfo("issue", EpidataFieldType.date),
7072
EpidataFieldInfo("lag", EpidataFieldType.int),
@@ -80,8 +82,7 @@ def define_covidcast_fields() -> List[EpidataFieldInfo]:
8082

8183
@dataclass
8284
class DataSignal(Generic[CALL_TYPE]):
83-
"""
84-
represents a COVIDcast data signal
85+
"""represents a COVIDcast data signal
8586
"""
8687

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

195196
@dataclass
196197
class DataSource(Generic[CALL_TYPE]):
197-
"""
198-
represents a COVIDcast data source
198+
"""represents a COVIDcast data source
199199
"""
200200

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

248248
@dataclass
249249
class CovidcastDataSources(Generic[CALL_TYPE]):
250-
"""
251-
COVIDcast data source helper.
250+
"""COVIDcast data source helper.
252251
"""
253252

254253
sources: Sequence[DataSource[CALL_TYPE]]

epidatpy/_endpoints.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def get_wildcard_equivalent_dates(time_value: EpiRangeParam, time_type: Literal[
3636

3737

3838
class AEpiDataEndpoints(ABC, Generic[CALL_TYPE]):
39-
"""
40-
epidata endpoint list and fetcher
39+
"""epidata endpoint list and fetcher
4140
"""
4241

4342
@abstractmethod
@@ -87,8 +86,7 @@ def pub_covid_hosp_facility_lookup(
8786
fips_code: Optional[str] = None,
8887
) -> CALL_TYPE:
8988
"""Lookup COVID hospitalization facility identifiers."""
90-
91-
if all((v is None for v in (state, ccn, city, zip, fips_code))):
89+
if all(v is None for v in (state, ccn, city, zip, fips_code)):
9290
raise InvalidArgumentException("one of `state`, `ccn`, `city`, `zip`, or `fips_code` is required")
9391

9492
return self._create_call(
@@ -121,7 +119,6 @@ def pub_covid_hosp_facility(
121119
publication_dates: Optional[EpiRangeParam] = None,
122120
) -> CALL_TYPE:
123121
"""Fetch COVID hospitalization data for specific facilities."""
124-
125122
collection_weeks = get_wildcard_equivalent_dates(collection_weeks, "day")
126123

127124
# Confusingly, the endpoint expects `collection_weeks` to be in day format,
@@ -271,7 +268,6 @@ def pub_covid_hosp_state_timeseries(
271268
as_of: Union[None, int, str] = None,
272269
) -> CALL_TYPE:
273270
"""Fetch COVID hospitalization data."""
274-
275271
if issues is not None and as_of is not None:
276272
raise InvalidArgumentException("`issues` and `as_of` are mutually exclusive")
277273

@@ -481,7 +477,6 @@ def pub_covidcast(
481477

482478
def pub_delphi(self, system: str, epiweek: Union[int, str]) -> CALL_TYPE:
483479
"""Fetch Delphi's forecast."""
484-
485480
return self._create_call(
486481
"delphi/",
487482
{"system": system, "epiweek": epiweek},

0 commit comments

Comments
 (0)