diff --git a/noxfile.py b/noxfile.py index 6ae7f19..a9d9039 100644 --- a/noxfile.py +++ b/noxfile.py @@ -29,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 @@ -36,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. @@ -46,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: @@ -70,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") @@ -80,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", @@ -96,7 +106,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..0fd7a4d 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" @@ -45,7 +45,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 +58,9 @@ long_description_content_type="text/markdown", install_requires=dependencies, license="Apache-2.0", - packages=find_packages(), + packages=find_namespace_packages(exclude=("tests*", "testing*")), 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/google/__init__.py b/testing/constraints-3.10.txt similarity index 64% rename from google/__init__.py rename to testing/constraints-3.10.txt index 9a1b64a..6d5e14b 100644 --- a/google/__init__.py +++ b/testing/constraints-3.10.txt @@ -1,24 +1,13 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC +# 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. - -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/testing/constraints-3.11.txt similarity index 64% rename from google/cloud/__init__.py rename to testing/constraints-3.11.txt index 9a1b64a..6d5e14b 100644 --- a/google/cloud/__init__.py +++ b/testing/constraints-3.11.txt @@ -1,24 +1,13 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC +# 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 # -# https://www.apache.org/licenses/LICENSE-2.0 +# 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. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) 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. diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py new file mode 100644 index 0000000..80b0aa0 --- /dev/null +++ b/tests/unit/test_packaging.py @@ -0,0 +1,39 @@ +# 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 + + +# 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``. + 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)