From 6255550775398f91fe6fbc8e9e21c9f2b8b923f3 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 12 Dec 2023 12:03:14 -0500 Subject: [PATCH 1/4] build: Add python 3.12 tests --- google/__init__.py | 24 ----------------------- google/cloud/__init__.py | 24 ----------------------- noxfile.py | 4 +++- setup.py | 13 +++++++++---- tests/unit/test_packaging.py | 37 ++++++++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 53 deletions(-) delete mode 100644 google/__init__.py delete mode 100644 google/cloud/__init__.py create mode 100644 tests/unit/test_packaging.py diff --git a/google/__init__.py b/google/__init__.py deleted file mode 100644 index 9a1b64a..0000000 --- a/google/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py deleted file mode 100644 index 9a1b64a..0000000 --- a/google/cloud/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/noxfile.py b/noxfile.py index 6ae7f19..15546c4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -18,6 +18,8 @@ import nox +UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + nox.options.sessions = [ "unit", "blacken", @@ -96,7 +98,7 @@ def default(session): *session.posargs, ) -@nox.session(python="3.8") +@nox.session(python=UNIT_TEST_PYTHON_VERSIONS) def unit(session): """Run the unit test suite.""" default(session) diff --git a/setup.py b/setup.py index f401c21..859406e 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ import os import setuptools -from setuptools import setup, find_packages +from setuptools import find_namespace_packages name = "google-cloud-audit-log" description = "Google Cloud Audit Protos" @@ -34,6 +34,13 @@ readme = readme_file.read() +# Only include packages under the 'google' namespace. Do not include tests, +# benchmarks, etc. +packages = [ + package for package in setuptools.find_packages() if package.startswith("google") +] + + setuptools.setup( name=name, version=version, @@ -45,7 +52,6 @@ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -59,10 +65,9 @@ long_description_content_type="text/markdown", install_requires=dependencies, license="Apache-2.0", - packages=find_packages(), + packages=packages, package_data={"": ["*.proto"]}, python_requires=">=3.7", - namespace_packages=["google", "google.cloud"], url="https://github.com/googleapis/python-audit-log", include_package_data=True, ) diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py new file mode 100644 index 0000000..72789a1 --- /dev/null +++ b/tests/unit/test_packaging.py @@ -0,0 +1,37 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import subprocess +import sys + + +def test_namespace_package_compat(tmp_path): + # The ``google`` namespace package should not be masked + # by the presence of ``google-cloud-audit-log``. + google = tmp_path / "google" + google.mkdir() + google.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.othermod"] + subprocess.check_call(cmd, env=env) + + # The ``google.cloud`` namespace package should not be masked + # by the presence of ``google-cloud-audit-log`. + google_cloud = tmp_path / "google" / "cloud" + google_cloud.mkdir() + google_cloud.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.cloud.othermod"] + subprocess.check_call(cmd, env=env) From bb2445f5026f34ba005412d3ce4d8c76a7ce4a2d Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 10 Feb 2024 19:13:29 +0000 Subject: [PATCH 2/4] fix build --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 859406e..0544c9a 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,7 @@ long_description_content_type="text/markdown", install_requires=dependencies, license="Apache-2.0", - packages=packages, + packages=find_namespace_packages(exclude=("tests*", "testing*")), package_data={"": ["*.proto"]}, python_requires=">=3.7", url="https://github.com/googleapis/python-audit-log", From c77678f4d115ee4938d84473242a264c997059e9 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 10 Feb 2024 14:32:23 -0500 Subject: [PATCH 3/4] refactor tests --- noxfile.py | 22 +++++++++++++++------- setup.py | 7 ------- testing/constraints-3.10.txt | 13 +++++++++++++ testing/constraints-3.11.txt | 13 +++++++++++++ testing/constraints-3.12.txt | 13 +++++++++++++ testing/constraints-3.7.txt | 22 ++++++++++++++++++++++ testing/constraints-3.8.txt | 13 +++++++++++++ testing/constraints-3.9.txt | 13 +++++++++++++ 8 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 testing/constraints-3.10.txt create mode 100644 testing/constraints-3.11.txt create mode 100644 testing/constraints-3.12.txt create mode 100644 testing/constraints-3.7.txt create mode 100644 testing/constraints-3.8.txt create mode 100644 testing/constraints-3.9.txt diff --git a/noxfile.py b/noxfile.py index 15546c4..a9d9039 100644 --- a/noxfile.py +++ b/noxfile.py @@ -18,8 +18,6 @@ import nox -UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] - nox.options.sessions = [ "unit", "blacken", @@ -31,6 +29,12 @@ BLACK_VERSION = "black==19.3b0" +CURRENT_DIRECTORY = Path(__file__).parent.absolute() + +DEFAULT_PYTHON_VERSION = "3.8" + +UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + # NOTE: Pin the version of grpcio-tools to 1.48.2 for compatibility with # Protobuf 3.19.5. Please ensure that the minimum required version of # protobuf in setup.py is compatible with the pb2 files generated @@ -38,7 +42,7 @@ GRPCIO_TOOLS_VERSION = "grpcio-tools==1.48.2" -@nox.session(python="3.8") +@nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): """Run black. Format code to uniform standard. @@ -48,7 +52,7 @@ def blacken(session): -@nox.session(python="3.8") +@nox.session(python=DEFAULT_PYTHON_VERSION) def generate_protos(session): """Generates the protos using protoc. Some notes on the `google` directory: @@ -72,7 +76,7 @@ def generate_protos(session): *protos, ) -@nox.session(python="3.8") +@nox.session(python=DEFAULT_PYTHON_VERSION) def lint_setup_py(session): """Verify that setup.py is valid""" session.install("docutils", "pygments") @@ -82,13 +86,17 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. session.install("mock", "pytest", "pytest-cov") - session.install("-e", ".") + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + session.install("-e", ".", "-c", constraints_path) # Run py.test against the unit tests. session.run( "py.test", "--quiet", - "--cov=google.cloud", + "--cov=google", "--cov=tests.unit", "--cov-append", "--cov-config=.coveragerc", diff --git a/setup.py b/setup.py index 0544c9a..0fd7a4d 100644 --- a/setup.py +++ b/setup.py @@ -34,13 +34,6 @@ readme = readme_file.read() -# Only include packages under the 'google' namespace. Do not include tests, -# benchmarks, etc. -packages = [ - package for package in setuptools.find_packages() if package.startswith("google") -] - - setuptools.setup( name=name, version=version, diff --git a/testing/constraints-3.10.txt b/testing/constraints-3.10.txt new file mode 100644 index 0000000..6d5e14b --- /dev/null +++ b/testing/constraints-3.10.txt @@ -0,0 +1,13 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/testing/constraints-3.11.txt b/testing/constraints-3.11.txt new file mode 100644 index 0000000..6d5e14b --- /dev/null +++ b/testing/constraints-3.11.txt @@ -0,0 +1,13 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/testing/constraints-3.12.txt b/testing/constraints-3.12.txt new file mode 100644 index 0000000..6d5e14b --- /dev/null +++ b/testing/constraints-3.12.txt @@ -0,0 +1,13 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt new file mode 100644 index 0000000..9bdf088 --- /dev/null +++ b/testing/constraints-3.7.txt @@ -0,0 +1,22 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +protobuf==3.19.5 +googleapis-common-protos==1.56.2 diff --git a/testing/constraints-3.8.txt b/testing/constraints-3.8.txt new file mode 100644 index 0000000..6d5e14b --- /dev/null +++ b/testing/constraints-3.8.txt @@ -0,0 +1,13 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/testing/constraints-3.9.txt b/testing/constraints-3.9.txt new file mode 100644 index 0000000..6d5e14b --- /dev/null +++ b/testing/constraints-3.9.txt @@ -0,0 +1,13 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. From 433522ce2796ed15c4239f8a1eaae74b774834a9 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Wed, 14 Aug 2024 13:20:59 -0400 Subject: [PATCH 4/4] Add comment --- tests/unit/test_packaging.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py index 72789a1..80b0aa0 100644 --- a/tests/unit/test_packaging.py +++ b/tests/unit/test_packaging.py @@ -17,6 +17,8 @@ import sys +# See https://docs.pytest.org/en/stable/how-to/tmp_path.html#the-tmp-path-fixture +# for more information on the `tmp_path` fixture of pytest def test_namespace_package_compat(tmp_path): # The ``google`` namespace package should not be masked # by the presence of ``google-cloud-audit-log``.