From 97c25e97f31e59330822835154463ebe0a3a9bba Mon Sep 17 00:00:00 2001 From: Tres Seaver <tseaver@palladion.com> Date: Sun, 1 Aug 2021 15:23:56 -0400 Subject: [PATCH 1/5] fix: drop mention of Python 2.7 from templates Closes #1118. --- synthtool/gcp/common.py | 8 -------- synthtool/gcp/templates/python_library/noxfile.py.j2 | 2 +- .../scripts/readme-gen/templates/install_deps.tmpl.rst | 2 +- synthtool/gcp/templates/python_samples/noxfile.py.j2 | 4 ++-- synthtool/languages/python.py | 4 ++-- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py index 4f4532031..1f54ad3f4 100644 --- a/synthtool/gcp/common.py +++ b/synthtool/gcp/common.py @@ -225,17 +225,9 @@ def py_library(self, **kwargs) -> Path: kwargs["default_python_version"] = "3.8" if "unit_test_python_versions" not in kwargs: kwargs["unit_test_python_versions"] = ["3.6", "3.7", "3.8", "3.9"] - if "microgenerator" not in kwargs: - kwargs["unit_test_python_versions"] = ["2.7"] + kwargs[ - "unit_test_python_versions" - ] if "system_test_python_versions" not in kwargs: kwargs["system_test_python_versions"] = ["3.8"] - if "microgenerator" not in kwargs: - kwargs["system_test_python_versions"] = ["2.7"] + kwargs[ - "system_test_python_versions" - ] # If cov_level is not given, set it to None. if "cov_level" not in kwargs: diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index 8b3197d09..535fb27b9 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -193,7 +193,7 @@ def system(session): ) {% if samples_test %} -@nox.session(python=["2.7", "3.7"]) +@nox.session(python=["3.7"]) def samples(session): requirements_path = os.path.join("samples", "requirements.txt") requirements_exists = os.path.exists(requirements_path) diff --git a/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst b/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst index a0406dba8..275d64989 100644 --- a/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst +++ b/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst @@ -12,7 +12,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. +#. Create a virtualenv. Samples are compatible with Python 3.6+. .. code-block:: bash diff --git a/synthtool/gcp/templates/python_samples/noxfile.py.j2 b/synthtool/gcp/templates/python_samples/noxfile.py.j2 index 6a8ccdae2..bef9a8ec9 100644 --- a/synthtool/gcp/templates/python_samples/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_samples/noxfile.py.j2 @@ -39,7 +39,7 @@ BLACK_VERSION = "black==19.10b0" TEST_CONFIG = { # You can opt out from the test for specific Python versions. - 'ignored_versions': ["2.7"], + 'ignored_versions': [], # Old samples are opted out of enforcing Python type hints # All new samples should feature them @@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/synthtool/languages/python.py b/synthtool/languages/python.py index ff4c467e2..d309efb65 100644 --- a/synthtool/languages/python.py +++ b/synthtool/languages/python.py @@ -45,8 +45,8 @@ # See the License for the specific language governing permissions and # limitations under the License.""" -SAMPLES_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] -IGNORED_VERSIONS = ["2.7"] +SAMPLES_VERSIONS = ["3.6", "3.7", "3.8"] +IGNORED_VERSIONS = [] SAMPLES_TEMPLATE_PATH = Path(CommonTemplates()._template_root) / "python_samples" From 623e10104f1acd4233a7e6b1d3d7d2858fb33a87 Mon Sep 17 00:00:00 2001 From: Tres Seaver <tseaver@palladion.com> Date: Sun, 1 Aug 2021 15:35:38 -0400 Subject: [PATCH 2/5] chore: add type hint FBO lint --- synthtool/languages/python.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synthtool/languages/python.py b/synthtool/languages/python.py index d309efb65..266aeb64d 100644 --- a/synthtool/languages/python.py +++ b/synthtool/languages/python.py @@ -15,7 +15,7 @@ import re import sys from pathlib import Path -from typing import Any, Dict +from typing import Any, Dict, List import yaml @@ -46,7 +46,7 @@ # limitations under the License.""" SAMPLES_VERSIONS = ["3.6", "3.7", "3.8"] -IGNORED_VERSIONS = [] +IGNORED_VERSIONS: List[str] = [] SAMPLES_TEMPLATE_PATH = Path(CommonTemplates()._template_root) / "python_samples" From b1457b75355535697639d8a8a2f5666f6d147977 Mon Sep 17 00:00:00 2001 From: Tres Seaver <tseaver@palladion.com> Date: Mon, 2 Aug 2021 14:16:40 -0400 Subject: [PATCH 3/5] chore: typo Co-authored-by: Anthonios Partheniou <partheniou@google.com> --- synthtool/gcp/templates/python_samples/noxfile.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synthtool/gcp/templates/python_samples/noxfile.py.j2 b/synthtool/gcp/templates/python_samples/noxfile.py.j2 index bef9a8ec9..3be2a1b8b 100644 --- a/synthtool/gcp/templates/python_samples/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_samples/noxfile.py.j2 @@ -88,7 +88,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. -# All versions used to tested samples. +# All versions used to test samples. ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. From 39e8fc7f0fbb7b004da3338e960cc8285c7616cc Mon Sep 17 00:00:00 2001 From: Tres Seaver <tseaver@palladion.com> Date: Tue, 3 Aug 2021 14:43:16 -0400 Subject: [PATCH 4/5] chore: drop 'microgenerator' flag for async deps Reorder standard deps, external deps for clarity. --- synthtool/gcp/templates/python_library/noxfile.py.j2 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index 535fb27b9..788f0ea9b 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -87,10 +87,8 @@ def default(session): constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - {%- if microgenerator %} - session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - {% endif %} - session.install("mock", "pytest", "pytest-cov", {% for d in unit_test_external_dependencies %}"{{d}}",{% endfor %} "-c", constraints_path) + session.install("mock", "asyncmock", "pytest", "pytest-cov", "pytest-asyncio", "-c", constraints_path) + {% for d in unit_test_external_dependencies %}session.install("{{d}}", "-c", constraints_path){% endfor %} {% for dependency in unit_test_local_dependencies %}session.install("-e", "{{dependency}}", "-c", constraints_path) {% endfor %} {% for dependency in unit_test_dependencies %}session.install("-e", "{{dependency}}", "-c", constraints_path){% endfor %} From a59fb218f61714a392958dc4d8e87e9f1de1f922 Mon Sep 17 00:00:00 2001 From: Tres Seaver <tseaver@palladion.com> Date: Tue, 3 Aug 2021 14:45:46 -0400 Subject: [PATCH 5/5] chore: drop unused 'samples' session Samples are tested via separate noxfiles in all repos which have them. --- .../gcp/templates/python_library/noxfile.py.j2 | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index 788f0ea9b..cb6672d4b 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -190,20 +190,6 @@ def system(session): *session.posargs ) -{% if samples_test %} -@nox.session(python=["3.7"]) -def samples(session): - requirements_path = os.path.join("samples", "requirements.txt") - requirements_exists = os.path.exists(requirements_path) - - session.install("mock", "pytest") - if requirements_exists: - session.install("-r", requirements_path) - session.install("-e", ".") - - session.run("py.test", "--quiet", "samples", *session.posargs) -{% endif %} - @nox.session(python=DEFAULT_PYTHON_VERSION) def cover(session): """Run the final coverage report.