Skip to content
Open
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"]
LINT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "noxfile.py", "setup.py"]
{% else %}
FORMAT_PATHS = ["docs", "{{ api.naming.versioned_module_name }}", "tests"]
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
22 changes: 10 additions & 12 deletions gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import io
import os
import re

import setuptools # type: ignore
import setuptools # type: ignore

package_root = os.path.abspath(os.path.dirname(__file__))

name = '{{ api.naming.warehouse_package_name }}'
name = "{{ api.naming.warehouse_package_name }}"

{% set warehouse_description = api.naming.warehouse_package_name.replace('-',' ')|title %}

Expand All @@ -22,9 +22,9 @@ description = "{{ warehouse_description }} API client library"

version = None

with open(os.path.join(package_root, '{{ package_path }}/gapic_version.py')) as fp:
with open(os.path.join(package_root, "{{ package_path }}/gapic_version.py")) as fp:
version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read())
assert (len(version_candidates) == 1)
assert len(version_candidates) == 1
version = version_candidates[0]

if version[0] == "0":
Expand Down Expand Up @@ -52,14 +52,16 @@ dependencies = [
{% endif %}
{% endfor %}
]
extras = {
{% if rest_async_io_enabled %}
extras = {
"async_rest": [
"google-api-core[grpc] >= 2.21.0, < 3.0.0",
"google-auth[aiohttp] >= 2.35.0, <3.0.0"
"google-auth[aiohttp] >= 2.35.0, <3.0.0",
],
{% endif %}
}
{% else %}
extras = {}
{% endif %}
url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/{{ api.naming.warehouse_package_name }}"

package_root = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -68,11 +70,7 @@ readme_filename = os.path.join(package_root, "README.rst")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()

packages = [
package
for package in setuptools.find_namespace_packages()
if package.startswith("{{ api.naming.namespace_packages|first }}")
]
packages = [package for package in setuptools.find_namespace_packages() if package.startswith("{{ api.naming.namespace_packages|first }}")]

setuptools.setup(
name=name,
Expand Down
Loading