From b890d981a5c7f1bc83769606e70ffb973b797e57 Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Thu, 29 Oct 2020 17:10:16 +0000 Subject: [PATCH] #165: Allow dependencies to be installed according to Poetry's dependencies - This will help keep consistent versions of flake8 etc being installed between developers, to prevent incosistent linting/safety outputs --- noxfile.py | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/noxfile.py b/noxfile.py index b3f84c54..902e03a9 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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")