1+ """Repo tasks."""
2+ import pathlib
3+
4+ import requests
15from 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