Skip to content

Commit

Permalink
chore: [autoapprove] Update black and isort to latest versions (#…
Browse files Browse the repository at this point in the history
…1811)

fix: Update `black` and `isort` to latest versions
- Add `black[jupyter]` because several samples directories include jupyter notebooks
- Add type hinting to avoid lint errors/warnings

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
holtskinner and parthea committed Oct 9, 2023
1 parent b7858ba commit 0c7b033
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 29 additions & 26 deletions synthtool/gcp/templates/python_library/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
Expand All @@ -137,6 +139,7 @@ nox.options.sessions = [
"lint_setup_py",
"blacken",
"docs",
"format",
]

# Error if a python version is missing
Expand Down
51 changes: 26 additions & 25 deletions synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -40,89 +41,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 = [
"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()
Expand Down
20 changes: 10 additions & 10 deletions tests/test_python_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{"unit_test_local_dependencies": ["../testutils", "../unitutils"]},
[
"""\
UNIT_TEST_LOCAL_DEPENDENCIES = [
UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [
"../testutils",
"../unitutils",
]""",
Expand All @@ -45,7 +45,7 @@
{"system_test_local_dependencies": ["../testutils", "../sysutils"]},
[
"""\
SYSTEM_TEST_LOCAL_DEPENDENCIES = [
SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [
"../testutils",
"../sysutils",
]""",
Expand All @@ -55,7 +55,7 @@
{"unit_test_extras": ["abc", "def"]},
[
"""\
UNIT_TEST_EXTRAS = [
UNIT_TEST_EXTRAS: List[str] = [
"abc",
"def",
]""",
Expand All @@ -64,7 +64,7 @@
(
{"system_test_extras": ["abc", "def"]},
"""\
SYSTEM_TEST_EXTRAS = [
SYSTEM_TEST_EXTRAS: List[str] = [
"abc",
"def",
]""",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0c7b033

Please sign in to comment.