forked from ansible/ansible-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add noxfile to run python linters and pip-compile
Currently, this only lints the noxfile itself and the issue labeler script. We can expand the noxfile to build docs and lint other new files in hacking. Relates: ansible#54
- Loading branch information
Showing
8 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[isort] | ||
profile = black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import nox | ||
|
||
LINT_FILES = ("hacking/pr_labeler/label.py", "noxfile.py") | ||
PINNED = os.environ.get("PINNED", "true").lower() in {"1", "true"} | ||
nox.options.sessions = ("lint",) | ||
|
||
|
||
def install(session: nox.Session, *args, req: str, **kwargs): | ||
if PINNED: | ||
kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = f"tests/{req}.txt" | ||
session.install("-r", f"tests/{req}.in", *args, **kwargs) | ||
|
||
|
||
@nox.session | ||
def static(session: nox.Session): | ||
""" | ||
Run static checkers | ||
""" | ||
install(session, req="static") | ||
session.run("ruff", *session.posargs, *LINT_FILES) | ||
|
||
|
||
@nox.session | ||
def formatters(session: nox.Session): | ||
""" | ||
Reformat code | ||
""" | ||
install(session, req="formatters") | ||
session.run("isort", *session.posargs, *LINT_FILES) | ||
session.run("black", *session.posargs, *LINT_FILES) | ||
|
||
|
||
@nox.session | ||
def formatters_check(session: nox.Session): | ||
""" | ||
Check code formatting without making changes | ||
""" | ||
install(session, req="formatters") | ||
session.run("isort", "--check", *session.posargs, *LINT_FILES) | ||
session.run("black", "--check", *session.posargs, *LINT_FILES) | ||
|
||
|
||
@nox.session | ||
def typing(session: nox.Session): | ||
install(session, req="typing") | ||
session.run("mypy", *session.posargs, *LINT_FILES) | ||
|
||
|
||
@nox.session | ||
def lint(session: nox.Session): | ||
session.notify("static") | ||
session.notify("formatters") | ||
|
||
|
||
requirements_files = list( | ||
{path.name.replace(".in", "") for path in Path("tests").glob("*in")} | ||
- {"constraints", "constraints-base"} | ||
) | ||
|
||
|
||
@nox.session(name="pip-compile", python=["3.10"]) | ||
@nox.parametrize(["req"], requirements_files, requirements_files) | ||
def pip_compile(session: nox.Session, req: str): | ||
session.install("pip-tools") | ||
# fmt: off | ||
session.run( | ||
"pip-compile", | ||
"--resolver", "backtracking", | ||
"--upgrade", | ||
"--allow-unsafe", | ||
"--quiet", | ||
"--strip-extras", | ||
"--output-file", f"tests/{req}.txt", | ||
f"tests/{req}.in", | ||
) | ||
# fmt: on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
black | ||
isort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile --allow-unsafe --output-file=tests/formatters.txt --strip-extras tests/formatters.in | ||
# | ||
black==23.7.0 | ||
# via -r tests/formatters.in | ||
click==8.1.6 | ||
# via black | ||
isort==5.12.0 | ||
# via -r tests/formatters.in | ||
mypy-extensions==1.0.0 | ||
# via black | ||
packaging==23.1 | ||
# via black | ||
pathspec==0.11.2 | ||
# via black | ||
platformdirs==3.10.0 | ||
# via black | ||
tomli==2.0.1 | ||
# via black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile --allow-unsafe --output-file=tests/static.txt --strip-extras tests/static.in | ||
# | ||
ruff==0.0.284 | ||
# via -r tests/static.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-r ../hacking/pr_labeler/requirements.txt | ||
mypy | ||
nox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# by the following command: | ||
# | ||
# pip-compile --allow-unsafe --output-file=tests/typing.txt --strip-extras tests/typing.in | ||
# | ||
argcomplete==3.1.1 | ||
# via nox | ||
certifi==2023.7.22 | ||
# via requests | ||
cffi==1.15.1 | ||
# via | ||
# cryptography | ||
# pynacl | ||
charset-normalizer==3.2.0 | ||
# via requests | ||
click==8.1.6 | ||
# via typer | ||
codeowners==0.6.0 | ||
# via -r tests/../hacking/pr_labeler/requirements.txt | ||
colorlog==6.7.0 | ||
# via nox | ||
cryptography==41.0.3 | ||
# via pyjwt | ||
deprecated==1.2.14 | ||
# via pygithub | ||
distlib==0.3.7 | ||
# via virtualenv | ||
filelock==3.12.2 | ||
# via virtualenv | ||
idna==3.4 | ||
# via requests | ||
mypy==1.5.0 | ||
# via -r tests/typing.in | ||
mypy-extensions==1.0.0 | ||
# via mypy | ||
nox==2023.4.22 | ||
# via -r tests/typing.in | ||
packaging==23.1 | ||
# via nox | ||
platformdirs==3.10.0 | ||
# via virtualenv | ||
pycparser==2.21 | ||
# via cffi | ||
pygithub==1.59.1 | ||
# via -r tests/../hacking/pr_labeler/requirements.txt | ||
pyjwt==2.8.0 | ||
# via pygithub | ||
pynacl==1.5.0 | ||
# via pygithub | ||
requests==2.31.0 | ||
# via pygithub | ||
tomli==2.0.1 | ||
# via mypy | ||
typer==0.9.0 | ||
# via -r tests/../hacking/pr_labeler/requirements.txt | ||
typing-extensions==4.7.1 | ||
# via | ||
# codeowners | ||
# mypy | ||
# typer | ||
urllib3==2.0.4 | ||
# via requests | ||
virtualenv==20.24.2 | ||
# via nox | ||
wrapt==1.15.0 | ||
# via deprecated |