From 4e1d2cb79b02d7496b1452f91c518630c207145e Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Thu, 28 May 2020 18:22:04 -0700 Subject: [PATCH] feat: allow custom python versions in noxfile (#585) Libraries on the microgenerator support a smaller range of Python versions (3.6+). --- synthtool/gcp/common.py | 12 ++++++++++++ .../gcp/templates/python_library/noxfile.py.j2 | 18 +++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py index ba085684c..66c7940d2 100644 --- a/synthtool/gcp/common.py +++ b/synthtool/gcp/common.py @@ -74,6 +74,18 @@ def py_library(self, **kwargs) -> Path: "instead." ) + # Set default Python versions for noxfile.py + if "default_python_version" not in kwargs: + kwargs["default_python_version"] = "3.7" + if "unit_test_python_versions" not in kwargs: + kwargs["unit_test_python_versions"] = ["2.7", "3.5", "3.6", "3.7", "3.8"] + if "system_test_python_versions" not in kwargs: + kwargs["system_test_python_versions"] = ["2.7", "3.7"] + + # Don't add samples templates if there are no samples + if "samples" not in kwargs: + self.excludes += ["samples/AUTHORING_GUIDE.md", "samples/CONTRIBUTING.md"] + return self._generic_library("python_library", **kwargs) def java_library(self, **kwargs) -> Path: diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index 46fcfadc9..46657f29b 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -26,10 +26,11 @@ import nox BLACK_VERSION = "black==19.3b0" BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] -if os.path.exists("samples"): - BLACK_PATHS.append("samples") +DEFAULT_PYTHON_VERSION="{{ default_python_version }}" +SYSTEM_TEST_PYTHON_VERSIONS=[{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}] +UNIT_TEST_PYTHON_VERSIONS=[{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %},{% endif %}{% endfor %}] -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): """Run linters. @@ -62,7 +63,7 @@ def blacken(session): ) -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def lint_setup_py(session): """Verify that setup.py is valid (including RST check).""" session.install("docutils", "pygments") @@ -90,14 +91,13 @@ def default(session): *session.posargs, ) - -@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"]) +@nox.session(python=UNIT_TEST_PYTHON_VERSIONS) def unit(session): """Run the unit test suite.""" default(session) -@nox.session(python=["2.7", "3.7"]) +@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" system_test_path = os.path.join("tests", "system.py") @@ -149,7 +149,7 @@ def samples(session): session.run("py.test", "--quiet", "samples", *session.posargs) {% endif %} -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def cover(session): """Run the final coverage report. @@ -161,7 +161,7 @@ def cover(session): session.run("coverage", "erase") -@nox.session(python="3.7") +@nox.session(python=DEFAULT_PYTHON_VERSION) def docs(session): """Build the docs for this library."""