diff --git a/google/iam/__init__.py b/google/iam/__init__.py deleted file mode 100644 index ad1e9d1..0000000 --- a/google/iam/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2022 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__("pkg_resources").declare_namespace(__name__) diff --git a/setup.py b/setup.py index ef0abae..d8d9ac9 100644 --- a/setup.py +++ b/setup.py @@ -39,15 +39,10 @@ packages = [ package - for package in setuptools.PEP420PackageFinder.find() + for package in setuptools.find_namespace_packages() if package.startswith("google") ] -namespaces = ["google"] -if "google.iam" in packages: - namespaces.append("google.iam") - - setuptools.setup( name=name, version=version, @@ -74,7 +69,6 @@ platforms="Posix; MacOS X; Windows", packages=packages, python_requires=">=3.7", - namespace_packages=namespaces, install_requires=dependencies, include_package_data=True, zip_safe=False, diff --git a/google/__init__.py b/tests/unit/test_google_iam.py similarity index 66% rename from google/__init__.py rename to tests/unit/test_google_iam.py index ad1e9d1..fabccb4 100644 --- a/google/__init__.py +++ b/tests/unit/test_google_iam.py @@ -1,10 +1,10 @@ -# Copyright 2022 Google LLC +# 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 +# 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, @@ -12,4 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -__import__("pkg_resources").declare_namespace(__name__) +from google.iam.v1 import policy_pb2 + +def test_create_policy(): + # Check that the import works + # and that an Policy instance can be instantiated + policy_pb2.Policy() \ No newline at end of file diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py new file mode 100644 index 0000000..f239c8b --- /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 ``grpc-google-iam-v1``. + 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.iam`` namespace package should not be masked + # by the presence of ``grpc-google-iam-v1``. + google_iam = tmp_path / "google" / "iam" + google_iam.mkdir() + google_iam.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.iam.othermod"] + subprocess.check_call(cmd, env=env)