Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 38 additions & 39 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ BLACK_VERSION = "black[jupyter]==23.7.0"
ISORT_VERSION = "isort==5.11.0"

{% if api.naming.module_namespace %}
FORMAT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "setup.py"]
LINT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "noxfile.py", "setup.py"]
{% else %}
FORMAT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests", "setup.py"]
LINT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests", "noxfile.py", "setup.py"]
{% endif %}

# We're most interested in ensuring that code is formatted properly
# and less concerned about the line length.
LINT_LINE_LENGTH = 150

# Add samples to the list of directories to format if the directory exists.
if os.path.isdir("samples"):
LINT_PATHS.append("samples")
FORMAT_PATHS.append("samples")

ALL_PYTHON = [
"3.7",
Expand Down Expand Up @@ -152,6 +159,7 @@ def lint(session):
"black",
"--check",
*LINT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)

{% if api.naming.module_namespace %}
Expand All @@ -167,7 +175,8 @@ def blacken(session):
session.install(BLACK_VERSION)
session.run(
"black",
*LINT_PATHS,
*FORMAT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)


Expand All @@ -183,11 +192,12 @@ def format(session):
session.run(
"isort",
"--fss",
*LINT_PATHS,
*FORMAT_PATHS,
)
session.run(
"black",
*LINT_PATHS,
*FORMAT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)


Expand All @@ -204,8 +214,7 @@ def install_unittest_dependencies(session, *constraints):

if UNIT_TEST_EXTERNAL_DEPENDENCIES:
warnings.warn(
"'unit_test_external_dependencies' is deprecated. Instead, please "
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
"'unit_test_external_dependencies' is deprecated. Instead, please use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
DeprecationWarning,
)
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
Expand Down Expand Up @@ -236,12 +245,15 @@ def unit(session, protobuf_implementation):

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
if protobuf_implementation == "cpp" and session.python in (
"3.11",
"3.12",
"3.13",
"3.14",
):
session.skip("cpp implementation is not supported in python 3.11+")

constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
install_unittest_dependencies(session, "-c", constraints_path)

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
Expand Down Expand Up @@ -304,9 +316,7 @@ def install_systemtest_dependencies(session, *constraints):
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")

Expand Down Expand Up @@ -383,8 +393,10 @@ def docs(session):
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b", "html", # builder
"-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory
"-b", # builder
"html",
"-d", # cache directory
os.path.join("docs", "_build", "doctrees", ""),
# paths to build:
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
Expand Down Expand Up @@ -452,7 +464,12 @@ def prerelease_deps(session, protobuf_implementation):

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
if protobuf_implementation == "cpp" and session.python in (
"3.11",
"3.12",
"3.13",
"3.14",
):
session.skip("cpp implementation is not supported in python 3.11+")

# Install all dependencies
Expand All @@ -463,11 +480,7 @@ def prerelease_deps(session, protobuf_implementation):
session.install(*unit_deps_all)

# Install dependencies for the system test environment
system_deps_all = (
SYSTEM_TEST_STANDARD_DEPENDENCIES
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
+ SYSTEM_TEST_EXTRAS
)
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
session.install(*system_deps_all)

# Because we test minimum dependency versions on the minimum Python
Expand All @@ -479,13 +492,8 @@ def prerelease_deps(session, protobuf_implementation):
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
constraints_deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]
# Ignore leading spaces and comment lines.
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]

# Install dependencies specified in `testing/constraints-X.txt`.
session.install(*constraints_deps)
Expand Down Expand Up @@ -556,11 +564,7 @@ def core_deps_from_source(session, protobuf_implementation):
session.install(*unit_deps_all)

# Install dependencies for the system test environment
system_deps_all = (
SYSTEM_TEST_STANDARD_DEPENDENCIES
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
+ SYSTEM_TEST_EXTRAS
)
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
session.install(*system_deps_all)

# Because we test minimum dependency versions on the minimum Python
Expand All @@ -572,13 +576,8 @@ def core_deps_from_source(session, protobuf_implementation):
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
constraints_deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]
# Ignore leading spaces and comment lines.
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]

# Install dependencies specified in `testing/constraints-X.txt`.
session.install(*constraints_deps)
Expand Down
76 changes: 37 additions & 39 deletions tests/integration/goldens/asset/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
BLACK_VERSION = "black[jupyter]==23.7.0"
ISORT_VERSION = "isort==5.11.0"

FORMAT_PATHS = ["docs", "google", "tests", "setup.py"]
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]

# We're most interested in ensuring that code is formatted properly
# and less concerned about the line length.
LINT_LINE_LENGTH = 150

# Add samples to the list of directories to format if the directory exists.
if os.path.isdir("samples"):
LINT_PATHS.append("samples")
FORMAT_PATHS.append("samples")

ALL_PYTHON = [
"3.7",
Expand Down Expand Up @@ -155,6 +161,7 @@ def lint(session):
"black",
"--check",
*LINT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)

session.run("flake8", "google", "tests")
Expand All @@ -166,7 +173,8 @@ def blacken(session):
session.install(BLACK_VERSION)
session.run(
"black",
*LINT_PATHS,
*FORMAT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)


Expand All @@ -182,11 +190,12 @@ def format(session):
session.run(
"isort",
"--fss",
*LINT_PATHS,
*FORMAT_PATHS,
)
session.run(
"black",
*LINT_PATHS,
*FORMAT_PATHS,
f"--line-length={LINT_LINE_LENGTH}",
)


Expand All @@ -203,8 +212,7 @@ def install_unittest_dependencies(session, *constraints):

if UNIT_TEST_EXTERNAL_DEPENDENCIES:
warnings.warn(
"'unit_test_external_dependencies' is deprecated. Instead, please "
"use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
"'unit_test_external_dependencies' is deprecated. Instead, please use 'unit_test_dependencies' or 'unit_test_local_dependencies'.",
DeprecationWarning,
)
session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints)
Expand Down Expand Up @@ -235,12 +243,15 @@ def unit(session, protobuf_implementation):

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
if protobuf_implementation == "cpp" and session.python in (
"3.11",
"3.12",
"3.13",
"3.14",
):
session.skip("cpp implementation is not supported in python 3.11+")

constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
install_unittest_dependencies(session, "-c", constraints_path)

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
Expand Down Expand Up @@ -298,9 +309,7 @@ def install_systemtest_dependencies(session, *constraints):
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
def system(session):
"""Run the system test suite."""
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
constraints_path = str(CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt")
system_test_path = os.path.join("tests", "system.py")
system_test_folder_path = os.path.join("tests", "system")

Expand Down Expand Up @@ -377,8 +386,10 @@ def docs(session):
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b", "html", # builder
"-d", os.path.join("docs", "_build", "doctrees", ""), # cache directory
"-b", # builder
"html",
"-d", # cache directory
os.path.join("docs", "_build", "doctrees", ""),
# paths to build:
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
Expand Down Expand Up @@ -446,7 +457,12 @@ def prerelease_deps(session, protobuf_implementation):

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
if protobuf_implementation == "cpp" and session.python in (
"3.11",
"3.12",
"3.13",
"3.14",
):
session.skip("cpp implementation is not supported in python 3.11+")

# Install all dependencies
Expand All @@ -457,11 +473,7 @@ def prerelease_deps(session, protobuf_implementation):
session.install(*unit_deps_all)

# Install dependencies for the system test environment
system_deps_all = (
SYSTEM_TEST_STANDARD_DEPENDENCIES
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
+ SYSTEM_TEST_EXTRAS
)
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
session.install(*system_deps_all)

# Because we test minimum dependency versions on the minimum Python
Expand All @@ -473,13 +485,8 @@ def prerelease_deps(session, protobuf_implementation):
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
constraints_deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]
# Ignore leading spaces and comment lines.
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]

# Install dependencies specified in `testing/constraints-X.txt`.
session.install(*constraints_deps)
Expand Down Expand Up @@ -550,11 +557,7 @@ def core_deps_from_source(session, protobuf_implementation):
session.install(*unit_deps_all)

# Install dependencies for the system test environment
system_deps_all = (
SYSTEM_TEST_STANDARD_DEPENDENCIES
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
+ SYSTEM_TEST_EXTRAS
)
system_deps_all = SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + SYSTEM_TEST_EXTRAS
session.install(*system_deps_all)

# Because we test minimum dependency versions on the minimum Python
Expand All @@ -566,13 +569,8 @@ def core_deps_from_source(session, protobuf_implementation):
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
constraints_deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]
# Ignore leading spaces and comment lines.
constraints_deps = [match.group(1) for match in re.finditer(r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE)]

# Install dependencies specified in `testing/constraints-X.txt`.
session.install(*constraints_deps)
Expand Down
Loading
Loading