Skip to content

Commit 695affd

Browse files
committed
feat: Introduce compatibility with native namespace packages
1 parent 58b3152 commit 695affd

File tree

8 files changed

+15
-66
lines changed

8 files changed

+15
-66
lines changed

.coveragerc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ exclude_lines =
1212
pragma: NO COVER
1313
# Ignore debug-only repr
1414
def __repr__
15-
# Ignore pkg_resources exceptions.
16-
# This is added at the module level as a safeguard for if someone
17-
# generates the code and tries to run it without pip installing. This
18-
# makes it virtually impossible to test properly.
19-
except pkg_resources.DistributionNotFound

google/__init__.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

google/cloud/__init__.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

google/cloud/bigquery/magics/magics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@
110110
from google.cloud.bigquery.magics import line_arg_parser as lap
111111

112112

113-
IPYTHON_USER_AGENT = "ipython-{}".format(IPython.__version__)
113+
# Add `# type: ignore` to silence mypy error `Cannot determine type of "__version__" [has-type]`
114+
# The IPython source file below does not have type hints.
115+
# https://github.com/ipython/ipython/blob/86d44b7f4674d5bf830afea5e6235c28a4b56bfd/IPython/__init__.py#L65
116+
IPYTHON_USER_AGENT = "ipython-{}".format(IPython.__version__) # type: ignore
114117

115118

116119
class Context(object):

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def mypy(session):
137137
"types-requests",
138138
"types-setuptools",
139139
)
140-
session.run("mypy", "google/cloud", "--show-traceback")
140+
session.run("mypy", "-p", "google", "--show-traceback")
141141

142142

143143
@nox.session(python=DEFAULT_PYTHON_VERSION)

samples/magics/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
if typing.TYPE_CHECKING:
21-
from IPython.core.interactiveshell import TerminalInteractiveShell
21+
from IPython.terminal.interactiveshell import TerminalInteractiveShell
2222

2323
interactiveshell = pytest.importorskip("IPython.terminal.interactiveshell")
2424
tools = pytest.importorskip("IPython.testing.tools")
@@ -40,5 +40,8 @@ def ipython_interactive(
4040
4141
for the duration of the test scope.
4242
"""
43-
with ipython.builtin_trap:
43+
# Remove ` # type: ignore` once
44+
# https://github.com/ipython/ipython/issues/14181 is fixed.
45+
# Also see https://github.com/ipython/ipython/blob/86d44b7f4674d5bf830afea5e6235c28a4b56bfd/IPython/core/interactiveshell.py#L1838.
46+
with ipython.builtin_trap: # type: ignore
4447
yield ipython

samples/snippets/jupyter_tutorial_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def ipython_interactive(
4545
4646
for the duration of the test scope.
4747
"""
48-
with ipython.builtin_trap:
48+
# Remove `# type: ignore` once
49+
# https://github.com/ipython/ipython/issues/14181 is fixed.
50+
# Also see https://github.com/ipython/ipython/blob/86d44b7f4674d5bf830afea5e6235c28a4b56bfd/IPython/core/interactiveshell.py#L1838.
51+
with ipython.builtin_trap: # type: ignore
4952
yield ipython
5053

5154

setup.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,10 @@
108108
# benchmarks, etc.
109109
packages = [
110110
package
111-
for package in setuptools.PEP420PackageFinder.find()
111+
for package in setuptools.find_namespace_packages()
112112
if package.startswith("google")
113113
]
114114

115-
# Determine which namespaces are needed.
116-
namespaces = ["google"]
117-
if "google.cloud" in packages:
118-
namespaces.append("google.cloud")
119-
120-
121115
setuptools.setup(
122116
name=name,
123117
version=version,
@@ -143,7 +137,6 @@
143137
],
144138
platforms="Posix; MacOS X; Windows",
145139
packages=packages,
146-
namespace_packages=namespaces,
147140
install_requires=dependencies,
148141
extras_require=extras,
149142
python_requires=">=3.7",

0 commit comments

Comments
 (0)