diff --git a/synthtool/gcp/templates/python_library/.pre-commit-config.yaml b/synthtool/gcp/templates/python_library/.pre-commit-config.yaml index 19409cbd3..6a8e16950 100644 --- a/synthtool/gcp/templates/python_library/.pre-commit-config.yaml +++ b/synthtool/gcp/templates/python_library/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/pycqa/flake8 diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index 40651e382..5db859fa4 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -17,22 +17,24 @@ # Generated by synthtool. DO NOT EDIT! from __future__ import absolute_import + import os import pathlib import re import shutil +from typing import Dict, List import warnings import nox FLAKE8_VERSION = "flake8==6.1.0" -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" +BLACK_VERSION = "black[jupyter]==23.7.0" +ISORT_VERSION = "isort==5.11.0" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "{{ default_python_version }}" -UNIT_TEST_PYTHON_VERSIONS = [{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] +UNIT_TEST_PYTHON_VERSIONS: List[str] = [{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", "asyncmock", @@ -41,89 +43,89 @@ UNIT_TEST_STANDARD_DEPENDENCIES = [ "pytest-asyncio", ] {%- if unit_test_external_dependencies %} -UNIT_TEST_EXTERNAL_DEPENDENCIES = [{% for v in unit_test_external_dependencies %} +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [{% for v in unit_test_external_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_local_dependencies %} -UNIT_TEST_LOCAL_DEPENDENCIES = [{% for v in unit_test_local_dependencies %} +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [{% for v in unit_test_local_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_dependencies %} -UNIT_TEST_DEPENDENCIES = [{% for v in unit_test_dependencies %} +UNIT_TEST_DEPENDENCIES: List[str] = [{% for v in unit_test_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_extras %} -UNIT_TEST_EXTRAS = [{% for v in unit_test_extras %} +UNIT_TEST_EXTRAS: List[str] = [{% for v in unit_test_extras %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_EXTRAS = [] +UNIT_TEST_EXTRAS: List[str] = [] {%- endif %} {%- if unit_test_extras_by_python %} -UNIT_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if unit_test_extras_by_python %}{% for python_version, extras in unit_test_extras_by_python.items() %} +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {{ '{' }}{% if unit_test_extras_by_python %}{% for python_version, extras in unit_test_extras_by_python.items() %} "{{python_version}}": [{% for v in extras %} "{{v}}",{% endfor %} ],{% endfor %}{% endif %} } {%- else %} -UNIT_TEST_EXTRAS_BY_PYTHON = {} +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} {%- endif %} {% if system_test_python_versions %} -SYSTEM_TEST_PYTHON_VERSIONS = [{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = [{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] {%- else %} -SYSTEM_TEST_PYTHON_VERSIONS = [] +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = [] {%- endif %} -SYSTEM_TEST_STANDARD_DEPENDENCIES = [ +SYSTEM_TEST_STANDARD_DEPENDENCIES: List[str] = [ "mock", "pytest", "google-cloud-testutils", ] {%- if system_test_external_dependencies %} -SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [{% for v in system_test_external_dependencies %} +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [{% for v in system_test_external_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_local_dependencies %} -SYSTEM_TEST_LOCAL_DEPENDENCIES = [{% for v in system_test_local_dependencies %} +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [{% for v in system_test_local_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_dependencies %} -SYSTEM_TEST_DEPENDENCIES = [{% for v in system_test_dependencies %} +SYSTEM_TEST_DEPENDENCIES: List[str] = [{% for v in system_test_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_extras %} -SYSTEM_TEST_EXTRAS = [{% for v in system_test_extras %} +SYSTEM_TEST_EXTRAS: List[str] = [{% for v in system_test_extras %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_EXTRAS = [] +SYSTEM_TEST_EXTRAS: List[str] = [] {%- endif %} {%- if system_test_extras_by_python %} -SYSTEM_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if system_test_extras_by_python %}{% for python_version, extras in system_test_extras_by_python.items() %} +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {{ '{' }}{% if system_test_extras_by_python %}{% for python_version, extras in system_test_extras_by_python.items() %} "{{python_version}}": [{% for v in extras %} "{{v}}",{% endfor %} ],{% endfor %}{% endif %} } {%- else %} -SYSTEM_TEST_EXTRAS_BY_PYTHON = {} +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} {%- endif %} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -137,6 +139,7 @@ nox.options.sessions = [ "lint_setup_py", "blacken", "docs", + "format", ] # Error if a python version is missing diff --git a/synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2 b/synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2 index 0a37d3b1b..6000495e3 100644 --- a/synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2 @@ -21,17 +21,18 @@ import os import pathlib import re import shutil +from typing import Dict, List import warnings import nox -BLACK_VERSION = "black==22.3.0" -ISORT_VERSION = "isort==5.10.1" +BLACK_VERSION = "black[jupyter]==23.7.0" +ISORT_VERSION = "isort==5.11.0" LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "{{ default_python_version }}" -UNIT_TEST_PYTHON_VERSIONS = [{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] +UNIT_TEST_PYTHON_VERSIONS: List[str] = [{% for v in unit_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] UNIT_TEST_STANDARD_DEPENDENCIES = [ "mock", "asyncmock", @@ -40,47 +41,47 @@ UNIT_TEST_STANDARD_DEPENDENCIES = [ "pytest-asyncio", ] {%- if unit_test_external_dependencies %} -UNIT_TEST_EXTERNAL_DEPENDENCIES = [{% for v in unit_test_external_dependencies %} +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [{% for v in unit_test_external_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_local_dependencies %} -UNIT_TEST_LOCAL_DEPENDENCIES = [{% for v in unit_test_local_dependencies %} +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [{% for v in unit_test_local_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_dependencies %} -UNIT_TEST_DEPENDENCIES = [{% for v in unit_test_dependencies %} +UNIT_TEST_DEPENDENCIES: List[str] = [{% for v in unit_test_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES: List[str] = [] {%- endif %} {%- if unit_test_extras %} -UNIT_TEST_EXTRAS = [{% for v in unit_test_extras %} +UNIT_TEST_EXTRAS: List[str] = [{% for v in unit_test_extras %} "{{v}}",{% endfor %} ] {%- else %} -UNIT_TEST_EXTRAS = [] +UNIT_TEST_EXTRAS: List[str] = [] {%- endif %} {%- if unit_test_extras_by_python %} -UNIT_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if unit_test_extras_by_python %}{% for python_version, extras in unit_test_extras_by_python.items() %} +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {{ '{' }}{% if unit_test_extras_by_python %}{% for python_version, extras in unit_test_extras_by_python.items() %} "{{python_version}}": [{% for v in extras %} "{{v}}",{% endfor %} ],{% endfor %}{% endif %} } {%- else %} -UNIT_TEST_EXTRAS_BY_PYTHON = {} +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} {%- endif %} {% if system_test_python_versions %} -SYSTEM_TEST_PYTHON_VERSIONS = [{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = [{% for v in system_test_python_versions %}"{{v}}"{% if not loop.last %}, {% endif %}{% endfor %}] {%- else %} -SYSTEM_TEST_PYTHON_VERSIONS = [] +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = [] {%- endif %} SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", @@ -88,41 +89,41 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "google-cloud-testutils", ] {%- if system_test_external_dependencies %} -SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [{% for v in system_test_external_dependencies %} +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [{% for v in system_test_external_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_local_dependencies %} -SYSTEM_TEST_LOCAL_DEPENDENCIES = [{% for v in system_test_local_dependencies %} +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [{% for v in system_test_local_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_dependencies %} -SYSTEM_TEST_DEPENDENCIES = [{% for v in system_test_dependencies %} +SYSTEM_TEST_DEPENDENCIES: List[str] = [{% for v in system_test_dependencies %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES: List[str] = [] {%- endif %} {%- if system_test_extras %} -SYSTEM_TEST_EXTRAS = [{% for v in system_test_extras %} +SYSTEM_TEST_EXTRAS: List[str] = [{% for v in system_test_extras %} "{{v}}",{% endfor %} ] {%- else %} -SYSTEM_TEST_EXTRAS = [] +SYSTEM_TEST_EXTRAS: List[str] = [] {%- endif %} {%- if system_test_extras_by_python %} -SYSTEM_TEST_EXTRAS_BY_PYTHON = {{ '{' }}{% if system_test_extras_by_python %}{% for python_version, extras in system_test_extras_by_python.items() %} +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {{ '{' }}{% if system_test_extras_by_python %}{% for python_version, extras in system_test_extras_by_python.items() %} "{{python_version}}": [{% for v in extras %} "{{v}}",{% endfor %} ],{% endfor %}{% endif %} } {%- else %} -SYSTEM_TEST_EXTRAS_BY_PYTHON = {} +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} {%- endif %} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() diff --git a/tests/test_python_library.py b/tests/test_python_library.py index de17c8be0..5853decbf 100644 --- a/tests/test_python_library.py +++ b/tests/test_python_library.py @@ -35,7 +35,7 @@ {"unit_test_local_dependencies": ["../testutils", "../unitutils"]}, [ """\ -UNIT_TEST_LOCAL_DEPENDENCIES = [ +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [ "../testutils", "../unitutils", ]""", @@ -45,7 +45,7 @@ {"system_test_local_dependencies": ["../testutils", "../sysutils"]}, [ """\ -SYSTEM_TEST_LOCAL_DEPENDENCIES = [ +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [ "../testutils", "../sysutils", ]""", @@ -55,7 +55,7 @@ {"unit_test_extras": ["abc", "def"]}, [ """\ -UNIT_TEST_EXTRAS = [ +UNIT_TEST_EXTRAS: List[str] = [ "abc", "def", ]""", @@ -64,7 +64,7 @@ ( {"system_test_extras": ["abc", "def"]}, """\ -SYSTEM_TEST_EXTRAS = [ +SYSTEM_TEST_EXTRAS: List[str] = [ "abc", "def", ]""", @@ -73,7 +73,7 @@ {"unit_test_extras_by_python": {"3.8": ["abc", "def"]}}, [ """\ -UNIT_TEST_EXTRAS_BY_PYTHON = { +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = { "3.8": [ "abc", "def", @@ -85,7 +85,7 @@ {"system_test_extras_by_python": {"3.8": ["abc", "def"]}}, [ """\ -SYSTEM_TEST_EXTRAS_BY_PYTHON = { +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = { "3.8": [ "abc", "def", @@ -100,12 +100,12 @@ }, [ """\ -UNIT_TEST_EXTRAS = [ +UNIT_TEST_EXTRAS: List[str] = [ "tuv", "wxyz", ]""", """\ -UNIT_TEST_EXTRAS_BY_PYTHON = { +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = { "3.8": [ "abc", "def", @@ -120,12 +120,12 @@ }, [ """\ -SYSTEM_TEST_EXTRAS = [ +SYSTEM_TEST_EXTRAS: List[str] = [ "tuv", "wxyz", ]""", """\ -SYSTEM_TEST_EXTRAS_BY_PYTHON = { +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = { "3.8": [ "abc", "def",