diff --git a/synthtool/gcp/common.py b/synthtool/gcp/common.py index b1fbb6564..622591d47 100644 --- a/synthtool/gcp/common.py +++ b/synthtool/gcp/common.py @@ -238,7 +238,7 @@ def py_library(self, **kwargs) -> Path: if "default_python_version" not in kwargs: kwargs["default_python_version"] = "3.8" if "unit_test_python_versions" not in kwargs: - kwargs["unit_test_python_versions"] = ["3.6", "3.7", "3.8", "3.9", "3.10"] + kwargs["unit_test_python_versions"] = ["3.7", "3.8", "3.9", "3.10"] if "system_test_python_versions" not in kwargs: kwargs["system_test_python_versions"] = ["3.8"] diff --git a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/common.cfg b/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/common.cfg deleted file mode 100644 index 555b92cf8..000000000 --- a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/common.cfg +++ /dev/null @@ -1,51 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Specify which tests to run -env_vars: { - key: "RUN_TESTS_SESSION" - value: "py-3.6" -} - -# Declare build specific Cloud project. -env_vars: { - key: "BUILD_SPECIFIC_GCLOUD_PROJECT" - value: "python-docs-samples-tests-py36" -} - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples.sh" -} -{% if custom_samples_dockerfile %} -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/{{ metadata['repo']['repo'].split('/')[1] }}-samples-docker" -} - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_DOCKERFILE" - value: ".kokoro/docker/samples/Dockerfile" -} -{% else %} -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker" -} -{% endif %} -# Download secrets for samples -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/continuous.cfg b/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/continuous.cfg deleted file mode 100644 index 7218af149..000000000 --- a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/continuous.cfg +++ /dev/null @@ -1,7 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -env_vars: { - key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "True" -} - diff --git a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic-head.cfg b/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic-head.cfg deleted file mode 100644 index da31f1cdf..000000000 --- a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic-head.cfg +++ /dev/null @@ -1,18 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -env_vars: { - key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "True" -} - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/{{ metadata['repo']['repo'].split('/')[1] }}/.kokoro/test-samples-against-head.sh" -} -{% if custom_samples_dockerfile %} -# Upload the docker image after successful builds. -env_vars: { - key: "TRAMPOLINE_IMAGE_UPLOAD" - value: "true" -} -{% endif %} \ No newline at end of file diff --git a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic.cfg b/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic.cfg deleted file mode 100644 index f7ea9d9b9..000000000 --- a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/periodic.cfg +++ /dev/null @@ -1,13 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -env_vars: { - key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "False" -} -{% if custom_samples_dockerfile %} -# Upload the docker image after successful builds. -env_vars: { - key: "TRAMPOLINE_IMAGE_UPLOAD" - value: "true" -} -{% endif %} \ No newline at end of file diff --git a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/presubmit.cfg b/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/presubmit.cfg deleted file mode 100644 index a1c8d9759..000000000 --- a/synthtool/gcp/templates/python_library/.kokoro/samples/python3.6/presubmit.cfg +++ /dev/null @@ -1,6 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -env_vars: { - key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "True" -} \ No newline at end of file diff --git a/synthtool/gcp/templates/python_library/README.rst b/synthtool/gcp/templates/python_library/README.rst new file mode 100644 index 000000000..2ab58971b --- /dev/null +++ b/synthtool/gcp/templates/python_library/README.rst @@ -0,0 +1,103 @@ +Python Client for {{ metadata['repo']['name_pretty'] }} API +======================{% for i in range(metadata['repo']['name_pretty']|length) %}={% endfor %} + +|{{ metadata['repo']['release_level'] }}| |pypi| |versions| + +`{{ metadata['repo']['name_pretty'] }} API`_: {% if metadata['repo']['api_description'] %}{{metadata['repo']['api_description'] }}{% endif %} + +- `Client Library Documentation`_ +- `Product Documentation`_ + +.. |{{ metadata['repo']['release_level'] }}| image:: https://img.shields.io/badge/support-{{ metadata['repo']['release_level'] }}-{% if metadata['repo']['release_level'] == 'stable' %}gold{% else %}orange{% endif %}.svg + :target: https://github.com/googleapis/google-cloud-python/blob/main/README.rst#stability-levels +.. |pypi| image:: https://img.shields.io/pypi/v/{{ metadata['repo']['distribution_name'] }}.svg + :target: https://pypi.org/project/{{ metadata['repo']['distribution_name'] }}/ +.. |versions| image:: https://img.shields.io/pypi/pyversions/{{ metadata['repo']['distribution_name'] }}.svg + :target: https://pypi.org/project/{{ metadata['repo']['distribution_name'] }}/ +.. _{{ metadata['repo']['name_pretty'] }} API: {{ metadata['repo']['product_documentation'] }} +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/{{ metadata['repo']['api_shortname'] }}/latest +.. _Product Documentation: {{ metadata['repo']['product_documentation'] }} + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the {{ metadata['repo']['name_pretty'] }} API.`_ +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the {{ metadata['repo']['name_pretty'] }} API.: {{ metadata['repo']['product_documentation'] }} +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Code samples and snippets +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Code samples and snippets live in the `samples/` folder. + + +Supported Python Versions +^^^^^^^^^^^^^^^^^^^^^^^^^ +Our client libraries are compatible with all current [active](https://devguide.python.org/devcycle/#in-development-main-branch) and [maintenance](https://devguide.python.org/devcycle/#maintenance-branches) versions of +Python. + +Python >= 3.7 + +Unsupported Python Versions +^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Python <= 3.6 + +If you are using an [end-of-life](https://devguide.python.org/devcycle/#end-of-life-branches) +version of Python, we recommend that you update as soon as possible to an actively supported version. + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install {{ metadata['repo']['distribution_name'] }} + + +Windows +^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install {{ metadata['repo']['distribution_name'] }} + +Next Steps +~~~~~~~~~~ + +- Read the `Client Library Documentation`_ for {{ metadata['repo']['name_pretty'] }} API + to see other available methods on the client. +- Read the `{{ metadata['repo']['name_pretty'] }} API Product documentation`_ to learn + more about the product and see How-to Guides. +- View this `README`_ to see the full list of Cloud + APIs that we cover. + +.. _{{ metadata['repo']['name_pretty'] }} API Product documentation: {{ metadata['repo']['product_documentation'] }} +.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst diff --git a/synthtool/gcp/templates/python_library/noxfile.py.j2 b/synthtool/gcp/templates/python_library/noxfile.py.j2 index a09cb3d85..541149d0f 100644 --- a/synthtool/gcp/templates/python_library/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_library/noxfile.py.j2 @@ -346,28 +346,11 @@ def docfx(session): def prerelease_deps(session): """Run all tests with prerelease versions of dependencies installed.""" - prerel_deps = [ - "protobuf", - "googleapis-common-protos", - "google-auth", - "grpcio", - "grpcio-status", - "google-api-core", - "proto-plus", - # dependencies of google-auth - "cryptography", - "pyasn1", - ] - - for dep in prerel_deps: - session.install("--pre", "--no-deps", "--upgrade", dep) - - # Remaining dependencies - other_deps = ["requests"] - session.install(*other_deps) - + # Install all dependencies + session.install("-e", ".[all, tests, tracing]") session.install(*UNIT_TEST_STANDARD_DEPENDENCIES) - session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES) + 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 # version, the first version we test with in the unit tests sessions has a @@ -381,19 +364,44 @@ def prerelease_deps(session): constraints_text = constraints_file.read() # Ignore leading whitespace and comment lines. - deps = [ + constraints_deps = [ match.group(1) for match in re.finditer( r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE ) ] - # Don't overwrite prerelease packages. - deps = [dep for dep in deps if dep not in prerel_deps] - # We use --no-deps to ensure that pre-release versions aren't overwritten - # by the version ranges in setup.py. - session.install(*deps) - session.install("--no-deps", "-e", ".[all]") + session.install(*constraints_deps) + + if os.path.exists("samples/snippets/requirements.txt"): + session.install("-r", "samples/snippets/requirements.txt") + + if os.path.exists("samples/snippets/requirements-test.txt"): + session.install("-r", "samples/snippets/requirements-test.txt") + + prerel_deps = [ + "protobuf", + # dependency of grpc + "six", + "googleapis-common-protos", + "grpcio", + "grpcio-status", + "google-api-core", + "proto-plus", + "google-cloud-testutils", + # dependencies of google-cloud-testutils" + "click", + ] + + for dep in prerel_deps: + session.install("--pre", "--no-deps", "--upgrade", dep) + + # Remaining dependencies + other_deps = [ + "requests", + "google-auth", + ] + session.install(*other_deps) # Print out prerelease package versions session.run( @@ -402,5 +410,16 @@ def prerelease_deps(session): session.run("python", "-c", "import grpc; print(grpc.__version__)") session.run("py.test", "tests/unit") - session.run("py.test", "tests/system") - session.run("py.test", "samples/snippets") + + system_test_path = os.path.join("tests", "system.py") + system_test_folder_path = os.path.join("tests", "system") + + # Only run system tests if found. + if os.path.exists(system_test_path) or os.path.exists(system_test_folder_path): + session.run("py.test", "tests/system") + + snippets_test_path = os.path.join("samples", "snippets") + + # Only run samples tests if found. + if os.path.exists(snippets_test_path): + session.run("py.test", "samples/snippets") diff --git a/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst b/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst index 275d64989..6f069c6c8 100644 --- a/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst +++ b/synthtool/gcp/templates/python_library/scripts/readme-gen/templates/install_deps.tmpl.rst @@ -12,7 +12,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 3.6+. +#. Create a virtualenv. Samples are compatible with Python 3.7+. .. code-block:: bash diff --git a/synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/cleanup/requirements.txt b/synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/cleanup/requirements.txt index 8cb0d0ce8..d598bf861 100644 --- a/synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/cleanup/requirements.txt +++ b/synthtool/gcp/templates/python_notebooks_testing_pipeline/.cloud-build/cleanup/requirements.txt @@ -1 +1 @@ -google-cloud-aiplatform==1.15.0 \ No newline at end of file +google-cloud-aiplatform==1.15.0 diff --git a/synthtool/gcp/templates/python_samples/install_deps.tmpl.rst b/synthtool/gcp/templates/python_samples/install_deps.tmpl.rst index 275d64989..6f069c6c8 100644 --- a/synthtool/gcp/templates/python_samples/install_deps.tmpl.rst +++ b/synthtool/gcp/templates/python_samples/install_deps.tmpl.rst @@ -12,7 +12,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 3.6+. +#. Create a virtualenv. Samples are compatible with Python 3.7+. .. code-block:: bash diff --git a/synthtool/gcp/templates/python_samples/noxfile.py.j2 b/synthtool/gcp/templates/python_samples/noxfile.py.j2 index 38bb0a572..5fcb9d746 100644 --- a/synthtool/gcp/templates/python_samples/noxfile.py.j2 +++ b/synthtool/gcp/templates/python_samples/noxfile.py.j2 @@ -89,7 +89,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to test samples. -ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] diff --git a/tests/fixtures/python_library/setup.py b/tests/fixtures/python_library/setup.py index 4657b2278..c4fb30196 100644 --- a/tests/fixtures/python_library/setup.py +++ b/tests/fixtures/python_library/setup.py @@ -88,7 +88,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -101,7 +100,7 @@ namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, - python_requires=">=3.6", + python_requires=">=3.7", scripts=["scripts/fixup_keywords.py"], include_package_data=True, zip_safe=False, diff --git a/tests/fixtures/python_library_w_version_py/setup.py b/tests/fixtures/python_library_w_version_py/setup.py index 4657b2278..c4fb30196 100644 --- a/tests/fixtures/python_library_w_version_py/setup.py +++ b/tests/fixtures/python_library_w_version_py/setup.py @@ -88,7 +88,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -101,7 +100,7 @@ namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, - python_requires=">=3.6", + python_requires=">=3.7", scripts=["scripts/fixup_keywords.py"], include_package_data=True, zip_safe=False,