Skip to content

Commit

Permalink
refactor: unify settings and build to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Jul 9, 2024
1 parent dea55ae commit 8714281
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 308 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4
Expand All @@ -19,3 +18,6 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
39 changes: 0 additions & 39 deletions .github/workflows/ci.yaml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ci

on: push

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
- name: Check Formatting
run: |
source venv/bin/activate
inv lint-black
- name: Check Linting
run: |
source venv/bin/activate
inv lint-pylint
- name: Check Types
run: |
source venv/bin/activate
inv lint-mypy
- name: Test
run: |
source venv/bin/activate
inv test
2 changes: 1 addition & 1 deletion .github/workflows/release_helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
base: dev
title: "chore: sync main->dev"
labels: chore
# reviewers:
# reviewers:
assignees: melange396
body: |
Syncing Main->Dev.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.mypy_cache
*.pyc
__pycache__
/venv
/docs/_build
.coverage
.pytest_cache
.DS_Store
*.egg-info
/dist
.DS_Store
dist/
build/
docs/_build
venv/
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ Install with the following commands:
# Latest dev version
pip install -e "git+https://github.com/cmu-delphi/epidatpy.git#egg=epidatpy"

# PyPI version
# PyPI version (not yet available)
pip install epidatpy
```

## Usage

TODO

## Development Environment
## Development

Prepare virtual environment and install dependencies

```sh
python -m venv venv
source ./venv/bin/activate
pip install --use-feature=2020-resolver -r requirements.txt -r requirements-dev.txt
pip install -e ".[dev]"
```

### Common Commands
Expand All @@ -44,7 +44,7 @@ inv dist # build distribution packages
inv release # upload the current version to pypi
```

## Release Process
### Release Process

The release consists of multiple steps which can be all done via the GitHub website:

Expand Down
57 changes: 41 additions & 16 deletions epidatpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
"""Fetch data from Delphi's API."""

# Make the linter happy about the unused variables
__all__ = [
"get_api_key",
"__version__",
"CovidcastDataSources",
"DataSignal",
"DataSignalGeoStatistics",
"DataSource",
"GeoType",
"TimeType",
"WebLink",
"AEpiDataEndpoints",
"AEpiDataCall",
"EpiDataFormatType",
"EpiDataResponse",
"EpiRange",
"EpiRangeDict",
"EpiRangeLike",
"EpiRangeParam",
"IntParam",
"InvalidArgumentException",
"StringParam",
]
__author__ = "Delphi Research Group"


from ._auth import get_api_key
from ._constants import __version__
from ._covidcast import (
CovidcastDataSources,
DataSignal,
DataSignalGeoStatistics,
DataSource,
GeoType,
TimeType,
WebLink,
)
from ._endpoints import AEpiDataEndpoints
from ._model import (
AEpiDataCall,
EpiDataFormatType,
EpiDataResponse,
EpiRange,
EpiRangeDict,
EpiDataResponse,
EpiRangeLike,
InvalidArgumentException,
EpiRangeParam,
IntParam,
InvalidArgumentException,
StringParam,
EpiDataFormatType,
AEpiDataCall,
)
from ._covidcast import (
DataSignal,
DataSource,
WebLink,
DataSignalGeoStatistics,
CovidcastDataSources,
GeoType,
TimeType,
)
from ._auth import get_api_key

__author__ = "Delphi Group"
1 change: 0 additions & 1 deletion epidatpy/_constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Final


__version__: Final = "0.5.0"
HTTP_HEADERS: Final = {"User-Agent": f"epidatpy/{__version__}"}
BASE_URL: Final = "https://api.delphi.cmu.edu/epidata/"
21 changes: 13 additions & 8 deletions epidatpy/_covidcast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import Field, InitVar, dataclass, field, fields
from functools import cached_property
from typing import (
Any,
Callable,
Expand All @@ -13,21 +14,21 @@
Sequence,
Tuple,
Union,
overload,
get_args,
overload,
)
from functools import cached_property

from pandas import DataFrame

from ._model import (
EpiRangeLike,
CALL_TYPE,
EpidataFieldInfo,
EpidataFieldType,
EpiRangeLike,
EpiRangeParam,
InvalidArgumentException,
)


GeoType = Literal["nation", "msa", "hrr", "hhs", "state", "county"]
TimeType = Literal["day", "week"]

Expand Down Expand Up @@ -119,11 +120,13 @@ class DataSignal(Generic[CALL_TYPE]):
geo_types: Dict[GeoType, DataSignalGeoStatistics] = field(default_factory=dict)

def __post_init__(self) -> None:
self.link = [WebLink(alt=l["alt"], href=l["href"]) if isinstance(l, dict) else l for l in self.link]
self.link = [
WebLink(alt=link["alt"], href=link["href"]) if isinstance(link, dict) else link for link in self.link
]
stats_fields = fields(DataSignalGeoStatistics)
self.geo_types = {
k: DataSignalGeoStatistics(**_limit_fields(l, stats_fields)) if isinstance(l, dict) else l
for k, l in self.geo_types.items()
k: DataSignalGeoStatistics(**_limit_fields(v, stats_fields)) if isinstance(v, dict) else v
for k, v in self.geo_types.items()
}

@staticmethod
Expand Down Expand Up @@ -222,7 +225,9 @@ def __post_init__(
self,
_create_call: Callable[[Mapping[str, Union[None, EpiRangeLike, Iterable[EpiRangeLike]]]], CALL_TYPE],
) -> None:
self.link = [WebLink(alt=l["alt"], href=l["href"]) if isinstance(l, dict) else l for l in self.link]
self.link = [
WebLink(alt=link["alt"], href=link["href"]) if isinstance(link, dict) else link for link in self.link
]
signal_fields = fields(DataSignal)
self.signals = [
DataSignal(_create_call=_create_call, **_limit_fields(s, signal_fields)) if isinstance(s, dict) else s
Expand Down
Loading

0 comments on commit 8714281

Please sign in to comment.