Skip to content

Commit

Permalink
feat: use native namespaces instead of pkg_resources (#812)
Browse files Browse the repository at this point in the history
* feat: use native namespaces instead of pkg_resources

* linting

* Added packaging test for native namespace support.

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people committed Nov 29, 2023
1 parent d73cc56 commit 10ad75d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 50 deletions.
22 changes: 0 additions & 22 deletions google/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions google/cloud/__init__.py

This file was deleted.

7 changes: 1 addition & 6 deletions setup.py
Expand Up @@ -55,14 +55,10 @@

packages = [
package
for package in setuptools.PEP420PackageFinder.find()
for package in setuptools.find_namespace_packages()
if package.startswith("google")
]

namespaces = ["google"]
if "google.cloud" in packages:
namespaces.append("google.cloud")

setuptools.setup(
name=name,
version=version,
Expand All @@ -89,7 +85,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,
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/test_packaging.py
@@ -0,0 +1,56 @@
# 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-logging``.

google = tmp_path / "google"
google.mkdir()
google.joinpath("othermod.py").write_text("")

google_otherpkg = tmp_path / "google" / "otherpkg"
google_otherpkg.mkdir()
google_otherpkg.joinpath("__init__.py").write_text("")

# The ``google.cloud`` namespace package should not be masked
# by the presence of ``google-cloud-logging``.
google_cloud = tmp_path / "google" / "cloud"
google_cloud.mkdir()
google_cloud.joinpath("othermod.py").write_text("")

google_cloud_otherpkg = tmp_path / "google" / "cloud" / "otherpkg"
google_cloud_otherpkg.mkdir()
google_cloud_otherpkg.joinpath("__init__.py").write_text("")

env = dict(os.environ, PYTHONPATH=str(tmp_path))

for pkg in [
"google.othermod",
"google.cloud.othermod",
"google.otherpkg",
"google.cloud.otherpkg",
"google.cloud.logging",
]:
cmd = [sys.executable, "-c", f"import {pkg}"]
subprocess.check_output(cmd, env=env)

for module in ["google.othermod", "google.cloud.othermod"]:
cmd = [sys.executable, "-m", module]
subprocess.check_output(cmd, env=env)

0 comments on commit 10ad75d

Please sign in to comment.