-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#165: Allow dependencies to be installed according to Poetry's depen…
…dencies - This will help keep consistent versions of flake8 etc being installed between developers, to prevent incosistent linting/safety outputs
- Loading branch information
1 parent
a478ab1
commit b890d98
Showing
1 changed file
with
37 additions
and
9 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 |
---|---|---|
@@ -1,31 +1,59 @@ | ||
import nox | ||
import tempfile | ||
|
||
# Separating Black away from the rest of the sessions | ||
nox.options.sessions = "lint" | ||
code_locations = "common", "src", "test", "util", "noxfile.py" | ||
nox.options.sessions = "lint", "safety" | ||
code_locations = "datagateway_api", "test", "util", "noxfile.py" | ||
|
||
|
||
@nox.session(python="3.6") | ||
def install_with_constraints(session, *args, **kwargs): | ||
with tempfile.NamedTemporaryFile() as requirements: | ||
session.run( | ||
"poetry", | ||
"export", | ||
"--dev", | ||
"--format=requirements.txt", | ||
f"--output={requirements.name}", | ||
external=True, | ||
) | ||
session.install(f"--constraint={requirements.name}", *args, **kwargs) | ||
|
||
|
||
@nox.session(python=["3.6", "3.7", "3.8", "3.9"], reuse_venv=True) | ||
def format(session): | ||
args = session.posargs or code_locations | ||
session.install("black") | ||
install_with_constraints(session, "black") | ||
session.run("black", *args, external=True) | ||
|
||
|
||
@nox.session(python="3.6") | ||
@nox.session(python="3.6", reuse_venv=True) | ||
def lint(session): | ||
args = session.posargs or code_locations | ||
session.install( | ||
install_with_constraints( | ||
session, | ||
"flake8", | ||
"flake8-bandit", | ||
"flake8-black", | ||
"flake8-bugbear", | ||
"flake8-import-order", | ||
"flake8-builtins", | ||
#"flake8-logging-format", # TODO - Add this to env | ||
#"flake8-commas", | ||
) | ||
session.run("flake8", *args) | ||
|
||
|
||
@nox.session(python="3.6") | ||
@nox.session(python="3.6", reuse_venv=True) | ||
def safety(session): | ||
session.install("safety") | ||
session.run("safety", "check", "-r", "requirements.txt", "--full-report") | ||
install_with_constraints(session, "safety") | ||
with tempfile.NamedTemporaryFile() as requirements: | ||
session.run( | ||
"poetry", | ||
"export", | ||
"--dev", | ||
"--format=requirements.txt", | ||
"--without-hashes", | ||
f"--output={requirements.name}", | ||
external=True, | ||
) | ||
session.run("safety", "check", f"--file={requirements.name}", "--full-report") |