Skip to content

Commit

Permalink
feat: Introduce compatibility with native namespace packages (#1036)
Browse files Browse the repository at this point in the history
* feat: Introduce compatibility with native namespace packages

* update .coveragerc to reflect changes

* remove replacement in owlbot.py

* exclude coverage for .nox/* and /tmp/*
  • Loading branch information
parthea authored Dec 1, 2023
1 parent b28dc9b commit 5d80ab0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
7 changes: 6 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Generated by synthtool. DO NOT EDIT!
[run]
branch = True
omit =
/tmp/*
.nox/*

[report]
fail_under = 100
Expand All @@ -29,7 +32,9 @@ exclude_lines =
# Ignore abstract methods
raise NotImplementedError
omit =
/tmp/*
.nox/*
*/gapic/*.py
*/proto/*.py
*/core/*.py
*/site-packages/*.py
*/site-packages/*.py
8 changes: 0 additions & 8 deletions google/__init__.py

This file was deleted.

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

This file was deleted.

6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def default(session):
session.run(
"py.test",
"--quiet",
"--cov=google.cloud.spanner",
"--cov=google.cloud",
"--cov=tests.unit",
f"--junitxml=unit_{session.python}_sponge_log.xml",
"--cov=google",
"--cov=tests/unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
Expand Down
10 changes: 0 additions & 10 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@ def place_before(path, text, *before_text, escape=None):
escape="()",
)

s.replace(
"noxfile.py",
"""f"--junitxml=unit_{session.python}_sponge_log.xml",
"--cov=google",
"--cov=tests/unit",""",
"""\"--cov=google.cloud.spanner",
"--cov=google.cloud",
"--cov=tests.unit",""",
)

s.replace(
"noxfile.py",
r"""session.install\("-e", "."\)""",
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,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 @@ -97,7 +93,6 @@
],
platforms="Posix; MacOS X; Windows",
packages=packages,
namespace_packages=namespaces,
install_requires=dependencies,
extras_require=extras,
python_requires=">=3.7",
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 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-spanner``.
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-spanner``.
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)

0 comments on commit 5d80ab0

Please sign in to comment.