Skip to content

Commit

Permalink
feat: allow custom python versions in noxfile (#585)
Browse files Browse the repository at this point in the history
Libraries on the microgenerator support a smaller range of Python versions (3.6+).
  • Loading branch information
busunkim96 authored May 29, 2020
1 parent e99975b commit 4e1d2cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 12 additions & 0 deletions synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions synthtool/gcp/templates/python_library/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.

Expand All @@ -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."""

Expand Down

0 comments on commit 4e1d2cb

Please sign in to comment.