1+ """Repo tasks."""
2+ import pathlib
3+ import sys
4+
5+ import requests
16from invoke import task
27
38
@@ -12,9 +17,6 @@ def update_gdoc(
1217 sources_url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXo-qePhrYGAoZqewVnS1kt9tfnUTLgtkV7a-1q7yg4FoZk0NNGuB1H6k10ah1Xz5B8l1S1RB17N6/pub?gid=0&single=true&output=csv" ,
1318 signal_url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vRfXo-qePhrYGAoZqewVnS1kt9tfnUTLgtkV7a-1q7yg4FoZk0NNGuB1H6k10ah1Xz5B8l1S1RB17N6/pub?gid=329338228&single=true&output=csv" ,
1419):
15- import requests
16- import pathlib
17-
1820 base_dir = pathlib .Path ("./src/server/endpoints/covidcast_utils/" )
1921
2022 def _migrate_file (url : str , filename : str ):
@@ -26,3 +28,41 @@ def _migrate_file(url: str, filename: str):
2628
2729 _migrate_file (sources_url , "db_sources.csv" )
2830 _migrate_file (signal_url , "db_signals.csv" )
31+
32+
33+ @task
34+ def lint (c , incremental = True , format = True , revision = "origin/dev" , diff = False ): # pylint: disable=redefined-builtin
35+ """Lint and format.
36+
37+ Additional linter settings can be found in `pyproject.toml` (this invocation
38+ will use those settings as well).
39+
40+ Parameters
41+ ----------
42+ incremental : bool
43+ Only lint changed files.
44+ format : bool
45+ Apply formatting changes.
46+ revision : str
47+ Revision to compare against.
48+ diff : bool
49+ Only show formatting changes, do not apply.
50+ """
51+ if not incremental :
52+ reponse = input ("This will format all files in this repo, continue? [y/N]" )
53+ if reponse .lower () not in ("y" , "yes" ):
54+ return
55+
56+ diff = "--diff" if diff else ""
57+ if incremental :
58+ if format :
59+ c .run (f"darker --revision { revision } ... { diff } --flynt --isort --color --check ." )
60+ out = c .run (f"git diff -U0 { revision } | lint-diffs" )
61+ if out .stdout .strip () != "=== pylint: mine=0, always=0" :
62+ print (out .stdout )
63+ sys .exit (1 )
64+ else :
65+ if format :
66+ c .run (f"black { diff } ." )
67+ c .run (f"isort { diff } ." )
68+ c .run ("pylint src/ tests/ integrations/" )
0 commit comments