@@ -16,6 +16,9 @@ CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
1616LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
1717PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")
1818
19+ BLACK_VERSION = "black==19.10b0"
20+ BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"]
21+ DEFAULT_PYTHON_VERSION = "3.9"
1922
2023nox.sessions = [
2124 "unit",
@@ -24,6 +27,9 @@ nox.sessions = [
2427 "check_lower_bounds"
2528 # exclude update_lower_bounds from default
2629 "docs",
30+ "blacken",
31+ "lint",
32+ "lint_setup_py",
2733]
2834
2935@nox.session(python=['3.6', '3.7', '3.8', '3.9', '3.10'])
@@ -44,7 +50,7 @@ def unit(session):
4450 )
4551
4652
47- @nox.session(python='3.9' )
53+ @nox.session(python=DEFAULT_PYTHON_VERSION )
4854def cover(session):
4955 """Run the final coverage report.
5056 This outputs the coverage report aggregating coverage from the unit
@@ -103,7 +109,7 @@ def check_lower_bounds(session):
103109 str(LOWER_BOUND_CONSTRAINTS_FILE),
104110 )
105111
106- @nox.session(python='3.9' )
112+ @nox.session(python=DEFAULT_PYTHON_VERSION )
107113def docs(session):
108114 """Build the docs for this library."""
109115
@@ -123,4 +129,38 @@ def docs(session):
123129 os.path.join("docs", ""),
124130 os.path.join("docs", "_build", "html", ""),
125131 )
132+
133+
134+ @nox.session(python=DEFAULT_PYTHON_VERSION)
135+ def lint(session):
136+ """Run linters.
137+
138+ Returns a failure if the linters find linting errors or sufficiently
139+ serious code quality issues.
140+ """
141+ session.install("flake8", BLACK_VERSION)
142+ session.run(
143+ "black",
144+ "--check",
145+ *BLACK_PATHS,
146+ )
147+ session.run("flake8", "google", "tests", "samples")
148+
149+
150+ @nox.session(python=DEFAULT_PYTHON_VERSION)
151+ def blacken(session):
152+ """Run black. Format code to uniform standard."""
153+ session.install(BLACK_VERSION)
154+ session.run(
155+ "black",
156+ *BLACK_PATHS,
157+ )
158+
159+
160+ @nox.session(python=DEFAULT_PYTHON_VERSION)
161+ def lint_setup_py(session):
162+ """Verify that setup.py is valid (including RST check)."""
163+ session.install("docutils", "pygments")
164+ session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
165+
126166{% endblock %}
0 commit comments