This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnoxfile.py
132 lines (103 loc) · 3.61 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""Run common tasks using nox."""
import pathlib
import sys
import mkdocs.commands.build
import mkdocs.commands.gh_deploy
import mkdocs.commands.serve
import mkdocs.config
import mkdocs.utils
import nox
from nox.sessions import Session
from pygments.lexers import LEXERS
sys.path.append(str(pathlib.Path(__file__).resolve().parent))
from edgeql_lexer import EdgeQLLexer # isort:skip
LEXERS["EdgeQLLexer"] = (
"edgeql_lexer",
EdgeQLLexer.name,
EdgeQLLexer.aliases,
EdgeQLLexer.filenames,
(),
)
def _process_add_single_comma_path(session: Session, path: pathlib.Path) -> None:
if path.is_dir():
for new_path in path.iterdir():
_process_add_single_comma_path(session, new_path)
return
if path.suffix not in {".py", ".pyi"}:
return
session.run(
"add-trailing-comma",
"--py36-plus",
"--exit-zero-even-if-changed",
str(path),
)
def _process_add_single_comma(session: Session, *paths: str) -> None:
for target in paths:
path = pathlib.Path(target)
_process_add_single_comma_path(session, path)
@nox.session(python=False, name="format")
def run_formatters(session: Session) -> None:
"""Run all project formatters.
Formatters to run:
1. isort with autoflake to remove all unused imports.
2. black for sinle style in all project.
3. add-trailing-comma to adding or removing comma from line.
4. isort for properly imports sorting.
"""
targets = ("edgeql_queries", "tests", "example", "noxfile.py")
# we need to run isort here, since autoflake is unable to understand unused imports
# when they are multiline.
# see https://github.com/myint/autoflake/issues/8
session.run("isort", "--recursive", "--force-single-line-imports", *targets)
session.run(
"autoflake",
"--recursive",
"--remove-all-unused-imports",
"--remove-unused-variables",
"--in-place",
*targets,
)
session.run("black", *targets)
_process_add_single_comma(session, *targets)
session.run("isort", *targets)
# sort edgeql_queries imports like as it was third-party library
session.run(
"isort",
"--thirdparty=edgeql_queries",
"--thirdparty=asyncpg",
"--project=app",
"example",
"docs/src",
)
@nox.session(python=False)
def lint(session: Session) -> None:
"""Run all project linters.
Linters to run:
1. black for code format style.
2. mypy for type checking.
3. flake8 for common python code style issues.
"""
targets = ("edgeql_queries",)
black_targets = targets + ("tests", "example", "noxfile.py")
flake8_targets = targets + ("tests",)
session.run("black", "--check", "--diff", *black_targets)
session.run("mypy", *targets)
session.run("flake8", *flake8_targets)
@nox.session(python=False)
def test(session: Session) -> None:
"""Run pytest."""
session.run("pytest", "--cov-config=setup.cfg")
@nox.session(python=False, name="docs-build")
def docs_build(_session: Session) -> None:
"""Build docs for deploing them on GitHub Pages or Netlify."""
mkdocs.commands.build.build(_get_docs_config())
@nox.session(python=False, name="docs-serve")
def docs_serve(_session: Session) -> None:
"""Run local website with documentation."""
mkdocs.commands.serve.serve()
@nox.session(python=False, name="docs-gh-deploy")
def docs_gh_deploy(_session: Session) -> None:
"""Deploy docs on GitHub Pages."""
mkdocs.commands.gh_deploy.gh_deploy(_get_docs_config())
def _get_docs_config() -> dict:
return mkdocs.config.load_config(site_dir="./site")