Skip to content

Commit e303170

Browse files
ci: fix flake8 errors for samples/snippets (#732)
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9701063 commit e303170

8 files changed

Lines changed: 62 additions & 52 deletions

File tree

packages/google-cloud-pubsub/.github/.OwlBot.lock.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:b2dc5f80edcf5d4486c39068c9fa11f7f851d9568eea4dcba130f994ea9b5e97
17-
# created: 2022-06-12T16:09:31.61859086Z
16+
digest: sha256:e7bb19d47c13839fe8c147e50e02e8b6cf5da8edd1af8b82208cd6f66cc2829c
17+
# created: 2022-07-05T18:31:20.838186805Z

packages/google-cloud-pubsub/.kokoro/test-samples-impl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export PYTHONUNBUFFERED=1
3333
env | grep KOKORO
3434

3535
# Install nox
36-
python3.6 -m pip install --upgrade --quiet nox
36+
python3.9 -m pip install --upgrade --quiet nox
3737

3838
# Use secrets acessor service account to get secrets
3939
if [[ -f "${KOKORO_GFILE_DIR}/secrets_viewer_service_account.json" ]]; then
@@ -76,7 +76,7 @@ for file in samples/**/requirements.txt; do
7676
echo "------------------------------------------------------------"
7777

7878
# Use nox to execute the tests for the project.
79-
python3.6 -m nox -s "$RUN_TESTS_SESSION"
79+
python3.9 -m nox -s "$RUN_TESTS_SESSION"
8080
EXIT=$?
8181

8282
# If this is a periodic build, send the test log to the FlakyBot.

packages/google-cloud-pubsub/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dependencies.
6060

6161
Supported Python Versions
6262
^^^^^^^^^^^^^^^^^^^^^^^^^
63-
Python >= 3.6
63+
Python >= 3.7
6464

6565
Deprecated Python Versions
6666
^^^^^^^^^^^^^^^^^^^^^^^^^^

packages/google-cloud-pubsub/noxfile.py

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -383,28 +383,15 @@ def docfx(session):
383383
def prerelease_deps(session):
384384
"""Run all tests with prerelease versions of dependencies installed."""
385385

386-
prerel_deps = [
387-
"protobuf",
388-
"googleapis-common-protos",
389-
"google-auth",
390-
"grpcio",
391-
"grpcio-status",
392-
"google-api-core",
393-
"proto-plus",
394-
# dependencies of google-auth
395-
"cryptography",
396-
"pyasn1",
397-
]
398-
399-
for dep in prerel_deps:
400-
session.install("--pre", "--no-deps", "--upgrade", dep)
401-
402-
# Remaining dependencies
403-
other_deps = ["requests"]
404-
session.install(*other_deps)
405-
386+
# Install all dependencies
387+
session.install("-e", ".[all, tests, tracing]")
406388
session.install(*UNIT_TEST_STANDARD_DEPENDENCIES)
407-
session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES)
389+
system_deps_all = (
390+
SYSTEM_TEST_STANDARD_DEPENDENCIES
391+
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
392+
+ SYSTEM_TEST_EXTRAS
393+
)
394+
session.install(*system_deps_all)
408395

409396
# Because we test minimum dependency versions on the minimum Python
410397
# version, the first version we test with in the unit tests sessions has a
@@ -418,19 +405,44 @@ def prerelease_deps(session):
418405
constraints_text = constraints_file.read()
419406

420407
# Ignore leading whitespace and comment lines.
421-
deps = [
408+
constraints_deps = [
422409
match.group(1)
423410
for match in re.finditer(
424411
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
425412
)
426413
]
427414

428-
# Don't overwrite prerelease packages.
429-
deps = [dep for dep in deps if dep not in prerel_deps]
430-
# We use --no-deps to ensure that pre-release versions aren't overwritten
431-
# by the version ranges in setup.py.
432-
session.install(*deps)
433-
session.install("--no-deps", "-e", ".[all]")
415+
session.install(*constraints_deps)
416+
417+
if os.path.exists("samples/snippets/requirements.txt"):
418+
session.install("-r", "samples/snippets/requirements.txt")
419+
420+
if os.path.exists("samples/snippets/requirements-test.txt"):
421+
session.install("-r", "samples/snippets/requirements-test.txt")
422+
423+
prerel_deps = [
424+
"protobuf",
425+
# dependency of grpc
426+
"six",
427+
"googleapis-common-protos",
428+
"grpcio",
429+
"grpcio-status",
430+
"google-api-core",
431+
"proto-plus",
432+
"google-cloud-testutils",
433+
# dependencies of google-cloud-testutils"
434+
"click",
435+
]
436+
437+
for dep in prerel_deps:
438+
session.install("--pre", "--no-deps", "--upgrade", dep)
439+
440+
# Remaining dependencies
441+
other_deps = [
442+
"requests",
443+
"google-auth",
444+
]
445+
session.install(*other_deps)
434446

435447
# Print out prerelease package versions
436448
session.run(
@@ -439,5 +451,16 @@ def prerelease_deps(session):
439451
session.run("python", "-c", "import grpc; print(grpc.__version__)")
440452

441453
session.run("py.test", "tests/unit")
442-
session.run("py.test", "tests/system")
443-
session.run("py.test", "samples/snippets")
454+
455+
system_test_path = os.path.join("tests", "system.py")
456+
system_test_folder_path = os.path.join("tests", "system")
457+
458+
# Only run system tests if found.
459+
if os.path.exists(system_test_path) or os.path.exists(system_test_folder_path):
460+
session.run("py.test", "tests/system")
461+
462+
snippets_test_path = os.path.join("samples", "snippets")
463+
464+
# Only run samples tests if found.
465+
if os.path.exists(snippets_test_path):
466+
session.run("py.test", "samples/snippets")

packages/google-cloud-pubsub/owlbot.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,6 @@
341341
"pip install google-pubsub",
342342
"pip install google-cloud-pubsub",
343343
)
344-
345-
s.move(
346-
library,
347-
excludes=[
348-
"docs/**/*",
349-
"nox.py",
350-
"README.rst",
351-
"setup.py",
352-
f"google/cloud/pubsub_{library.name}/__init__.py",
353-
f"google/cloud/pubsub_{library.name}/types.py",
354-
],
355-
)
356-
357344
s.remove_staging_dirs()
358345

359346
# ----------------------------------------------------------------------------
@@ -367,7 +354,7 @@
367354
system_test_python_versions=["3.10"],
368355
system_test_external_dependencies=["psutil"],
369356
)
370-
s.move(templated_files, excludes=[".coveragerc", ".github/CODEOWNERS"])
357+
s.move(templated_files, excludes=["README.rst", ".coveragerc", ".github/CODEOWNERS"])
371358
python.configure_previous_major_version_branches()
372359
# ----------------------------------------------------------------------------
373360
# Samples templates

packages/google-cloud-pubsub/samples/snippets/noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
8989

9090
# DO NOT EDIT - automatically generated.
9191
# All versions used to test samples.
92-
ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
92+
ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"]
9393

9494
# Any default versions that should be ignored.
9595
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]

packages/google-cloud-pubsub/samples/snippets/subscriber_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _publish_messages(
141141
publisher_client: pubsub_v1.PublisherClient,
142142
topic: str,
143143
message_num: int = 5,
144-
**attrs: Any,
144+
**attrs: Any, # noqa: ANN401
145145
) -> List[str]:
146146
message_ids = []
147147
for n in range(message_num):

packages/google-cloud-pubsub/scripts/readme-gen/templates/install_deps.tmpl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Install Dependencies
1212
.. _Python Development Environment Setup Guide:
1313
https://cloud.google.com/python/setup
1414

15-
#. Create a virtualenv. Samples are compatible with Python 3.6+.
15+
#. Create a virtualenv. Samples are compatible with Python 3.7+.
1616

1717
.. code-block:: bash
1818

0 commit comments

Comments
 (0)