Skip to content

Commit

Permalink
#165: Allow dependencies to be installed according to Poetry's depen…
Browse files Browse the repository at this point in the history
…dencies

- This will help keep consistent versions of flake8 etc being installed between developers, to prevent incosistent linting/safety outputs
  • Loading branch information
MRichards99 committed Oct 29, 2020
1 parent a478ab1 commit b890d98
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions noxfile.py
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")

0 comments on commit b890d98

Please sign in to comment.