Skip to content

Commit 4e1d2cb

Browse files
authored
feat: allow custom python versions in noxfile (#585)
Libraries on the microgenerator support a smaller range of Python versions (3.6+).
1 parent e99975b commit 4e1d2cb

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

synthtool/gcp/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ def py_library(self, **kwargs) -> Path:
7474
"instead."
7575
)
7676

77+
# Set default Python versions for noxfile.py
78+
if "default_python_version" not in kwargs:
79+
kwargs["default_python_version"] = "3.7"
80+
if "unit_test_python_versions" not in kwargs:
81+
kwargs["unit_test_python_versions"] = ["2.7", "3.5", "3.6", "3.7", "3.8"]
82+
if "system_test_python_versions" not in kwargs:
83+
kwargs["system_test_python_versions"] = ["2.7", "3.7"]
84+
85+
# Don't add samples templates if there are no samples
86+
if "samples" not in kwargs:
87+
self.excludes += ["samples/AUTHORING_GUIDE.md", "samples/CONTRIBUTING.md"]
88+
7789
return self._generic_library("python_library", **kwargs)
7890

7991
def java_library(self, **kwargs) -> Path:

synthtool/gcp/templates/python_library/noxfile.py.j2

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import nox
2626
BLACK_VERSION = "black==19.3b0"
2727
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
2828

29-
if os.path.exists("samples"):
30-
BLACK_PATHS.append("samples")
29+
DEFAULT_PYTHON_VERSION="{{ default_python_version }}"
30+
SYSTEM_TEST_PYTHON_VERSIONS=[{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}]
31+
UNIT_TEST_PYTHON_VERSIONS=[{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}]
3132

32-
@nox.session(python="3.7")
33+
@nox.session(python=DEFAULT_PYTHON_VERSION)
3334
def lint(session):
3435
"""Run linters.
3536

@@ -62,7 +63,7 @@ def blacken(session):
6263
)
6364

6465

65-
@nox.session(python="3.7")
66+
@nox.session(python=DEFAULT_PYTHON_VERSION)
6667
def lint_setup_py(session):
6768
"""Verify that setup.py is valid (including RST check)."""
6869
session.install("docutils", "pygments")
@@ -90,14 +91,13 @@ def default(session):
9091
*session.posargs,
9192
)
9293

93-
94-
@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"])
94+
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
9595
def unit(session):
9696
"""Run the unit test suite."""
9797
default(session)
9898

9999

100-
@nox.session(python=["2.7", "3.7"])
100+
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
101101
def system(session):
102102
"""Run the system test suite."""
103103
system_test_path = os.path.join("tests", "system.py")
@@ -149,7 +149,7 @@ def samples(session):
149149
session.run("py.test", "--quiet", "samples", *session.posargs)
150150
{% endif %}
151151

152-
@nox.session(python="3.7")
152+
@nox.session(python=DEFAULT_PYTHON_VERSION)
153153
def cover(session):
154154
"""Run the final coverage report.
155155

@@ -161,7 +161,7 @@ def cover(session):
161161

162162
session.run("coverage", "erase")
163163

164-
@nox.session(python="3.7")
164+
@nox.session(python=DEFAULT_PYTHON_VERSION)
165165
def docs(session):
166166
"""Build the docs for this library."""
167167

0 commit comments

Comments
 (0)