Skip to content

Commit 94bd8ce

Browse files
committed
feat: add incremental linting
1 parent be62d66 commit 94bd8ce

File tree

7 files changed

+108
-7
lines changed

7 files changed

+108
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
docker network create --driver bridge delphi-net
6666
docker run --rm -d -p 13306:3306 --network delphi-net --name delphi_database_epidata --cap-add=sys_nice delphi_database_epidata
6767
docker run --rm -d -p 6379:6379 --network delphi-net --env "REDIS_PASSWORD=1234" --name delphi_redis delphi_redis
68-
68+
6969
7070
- run: |
7171
wget https://raw.githubusercontent.com/eficode/wait-for/master/wait-for

.github/workflows/lint.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
darker:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- uses: actions/setup-python@v4
16+
- uses: akaihola/[email protected]
17+
with:
18+
options: "--check --diff --isort --color"
19+
version: "~=1.7.2"
20+
21+
lint-diffs:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Commit Range
25+
id: commit-range
26+
uses: akaihola/darker/.github/actions/[email protected]
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-python@v4
29+
with:
30+
python-version: '3.8'
31+
cache: 'pip'
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install -r requirements.lint.txt
36+
- name: Lint
37+
run: |
38+
inv lint --diff --no-format --revision=${{ steps.commit-range.outputs.commit-range }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ __pycache__/
1111
/node_modules
1212
.mypy_cache
1313
/missing_db_signals.csv
14+
venv
15+
env

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ $ cd repos
6464
$ pip install -e . --config-settings editable_mode=strict
6565
```
6666

67+
## Linting and Formatting
68+
69+
We use [darker](https://github.com/akaihola/darker) and
70+
[lint-diffs](https://github.com/AtakamaLLC/lint-diffs/) to incrementally bring
71+
this repo up to PEP8 compliance. There is CI to ensure that all new code is
72+
compliant. To run the linter locally:
73+
74+
```sh
75+
# Install lint dependencies
76+
pip install -r requirements.lint.txt
77+
# Run lint
78+
inv lint
79+
```
80+
6781
# COVIDcast
6882

6983
At the present, our primary focus is developing and expanding the

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
[tool.black]
2-
line-length = 100
2+
line-length = 120
33
target-version = ['py38']
4-
include = 'server,tests/server'
4+
5+
[tool.isort]
6+
profile = "black"
7+
known_third_party = ["pytest"]
58

69
[tool.pylint]
10+
# Settings copied from
11+
# cmu-delphi/covidcast-indicators/_delphi_utils_python/.pylintrc
712
[tool.pylint.'MESSAGES CONTROL']
8-
max-line-length = 100
13+
max-line-length = 120
914
disable = [
1015
'logging-format-interpolation',
1116
# Allow pytest functions to be part of a class

requirements.lint.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
darker[flynt]~=1.7.2
2+
invoke>=1.4.1
3+
isort==5.12.0
4+
lint_diffs==0.1.22
5+
pylint==2.8.3
6+
requests

tasks.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Repo tasks."""
2+
import pathlib
3+
4+
import requests
15
from invoke import task
26

37

@@ -12,9 +16,6 @@ def update_gdoc(
1216
sources_url="https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXo-qePhrYGAoZqewVnS1kt9tfnUTLgtkV7a-1q7yg4FoZk0NNGuB1H6k10ah1Xz5B8l1S1RB17N6/pub?gid=0&single=true&output=csv",
1317
signal_url="https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXo-qePhrYGAoZqewVnS1kt9tfnUTLgtkV7a-1q7yg4FoZk0NNGuB1H6k10ah1Xz5B8l1S1RB17N6/pub?gid=329338228&single=true&output=csv",
1418
):
15-
import requests
16-
import pathlib
17-
1819
base_dir = pathlib.Path("./src/server/endpoints/covidcast_utils/")
1920

2021
def _migrate_file(url: str, filename: str):
@@ -26,3 +27,38 @@ def _migrate_file(url: str, filename: str):
2627

2728
_migrate_file(sources_url, "db_sources.csv")
2829
_migrate_file(signal_url, "db_signals.csv")
30+
31+
32+
@task
33+
def lint(c, incremental=True, lint=True, format=True, revision="origin/dev", diff=False):
34+
"""Lint and format.
35+
36+
Additional linter settings can be found in `pyproject.toml` (this invocation
37+
will use those settings as well).
38+
39+
Parameters
40+
----------
41+
incremental : bool
42+
Only lint changed files.
43+
revision : str
44+
Revision to compare against.
45+
diff : bool
46+
Only show formatting changes, do not apply.
47+
"""
48+
if not incremental:
49+
reponse = input("This will format all files in this repo, continue? [y/N]")
50+
if reponse.lower() not in ("y", "yes"):
51+
return
52+
53+
diff = "--diff" if diff else ""
54+
if incremental:
55+
if format:
56+
c.run(f"darker --revision {revision}... {diff} --flynt --isort --color --check .")
57+
if lint:
58+
c.run(f"git diff -U0 {revision} | lint-diffs")
59+
else:
60+
if format:
61+
c.run(f"black {diff} .")
62+
c.run(f"isort {diff} .")
63+
if lint:
64+
c.run("pylint src/ tests/ integrations/")

0 commit comments

Comments
 (0)