Skip to content

Commit

Permalink
Replace namespace packages with non-namespace packages (#543)
Browse files Browse the repository at this point in the history
Our current tests for the `EggPluginManager` and
`EggBasketPluginManager` build eggs for testing purposes. The packages
that those eggs are built from are all old-style `pkg_resources`-based
namespace packages. That's causing warnings, because the newest version
of `setuptools` doesn't want to support old-style namespace packages any
more.

This PR converts the namespace packages to normal, non-namespace
packages and removes the machinery that `setuptools` is warning about
(specifically, the uses of `declare_namespace`).

I did first try to convert the old-style namespace packages to new-style
PEP 420-based namespace packages, but the `EggBasketPluginManager` is
not currently compatible with new-style namespace packages, and it's
hard to see how it could be made compatible, given that it's based on
putting eggs on `sys.path`. Since we're planning to get rid of the
`EggBasketPluginManager` anyway, it doesn't seem worth putting in a
heroic effort to make things work.

## Detailed changes

- The namespace package `acme.foo` is converted to a package with
distribution name `acme-foo` and import name `acme_foo`. The plugin id
is left as-is.
- Analogous changes are applied to `acme.bar`, `acme.baz` and
`acme.bad`.

Fixes #523
  • Loading branch information
mdickinson committed Mar 17, 2023
1 parent ebf8402 commit 518dadd
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 91 deletions.
Expand Up @@ -7,4 +7,3 @@
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
__import__("pkg_resources").declare_namespace(__name__)
Expand Up @@ -11,20 +11,19 @@
from setuptools import setup, find_packages

setup(
name="acme.bar",
name="acme-bad",
version="0.1a1",
author="Enthought, Inc",
author_email="info@enthought.com",
license="BSD",
zip_safe=True,
packages=find_packages(),
packages=find_packages(include="acme_bad*"),
include_package_data=True,
namespace_packages=["acme", "acme.bar"],
install_requires=["acme.foo"],
install_requires=["acme-foo"],
entry_points="""
[envisage.plugins]
acme.bar = acme.bar.bar_plugin:BarPlugin
acme.bad = acme_bad.bad_plugin:BadPlugin
""",
)
11 changes: 0 additions & 11 deletions envisage/tests/bad_eggs/acme.bad/acme/__init__.py

This file was deleted.

Expand Up @@ -7,5 +7,3 @@
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

__import__("pkg_resources").declare_namespace(__name__)
Expand Up @@ -11,20 +11,19 @@
from setuptools import setup, find_packages

setup(
name="acme.baz",
name="acme-bar",
version="0.1a1",
author="Enthought, Inc",
author_email="info@enthought.com",
license="BSD",
zip_safe=True,
packages=find_packages(),
packages=find_packages(include="acme_bar*"),
include_package_data=True,
namespace_packages=["acme", "acme.baz"],
install_requires=["acme.bar"],
install_requires=["acme-foo"],
entry_points="""
[envisage.plugins]
acme.baz = acme.baz.baz_plugin:BazPlugin
acme.bar = acme_bar.bar_plugin:BarPlugin
""",
)
Expand Up @@ -7,5 +7,3 @@
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

__import__("pkg_resources").declare_namespace(__name__)
Expand Up @@ -11,20 +11,19 @@
from setuptools import setup, find_packages

setup(
name="acme.bad",
name="acme-baz",
version="0.1a1",
author="Enthought, Inc",
author_email="info@enthought.com",
license="BSD",
zip_safe=True,
packages=find_packages(),
packages=find_packages(include="acme_baz*"),
include_package_data=True,
namespace_packages=["acme", "acme.bad"],
install_requires=["acme.foo"],
install_requires=["acme-bar"],
entry_points="""
[envisage.plugins]
acme.bad = acme.bad.bad_plugin:BadPlugin
acme.baz = acme_baz.baz_plugin:BazPlugin
""",
)
Expand Up @@ -7,5 +7,3 @@
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

__import__("pkg_resources").declare_namespace(__name__)
Expand Up @@ -11,20 +11,19 @@
from setuptools import setup, find_packages

setup(
name="acme.foo",
name="acme-foo",
version="0.1a1",
author="Enthought, Inc",
author_email="info@enthought.com",
license="BSD",
zip_safe=True,
packages=find_packages(),
packages=find_packages(include="acme_foo*"),
include_package_data=True,
namespace_packages=["acme", "acme.foo"],
install_requires=[],
entry_points="""
[envisage.plugins]
acme.foo = acme.foo.foo_plugin:FooPlugin
acme.foo = acme_foo.foo_plugin:FooPlugin
""",
)
11 changes: 0 additions & 11 deletions envisage/tests/eggs/acme.baz/acme/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions envisage/tests/eggs/acme.baz/acme/baz/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions envisage/tests/eggs/acme.foo/acme/foo/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion envisage/tests/test_egg_based.py
Expand Up @@ -59,7 +59,7 @@ def setUpClass(cls):
cls.egg_dir = tempfile.mkdtemp()
eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "eggs")
for egg_name in ["acme.bar", "acme.baz", "acme.foo"]:
for egg_name in ["acme-bar", "acme-baz", "acme-foo"]:
build_egg(
egg_dir=join(eggs_root_dir, egg_name),
dist_dir=cls.egg_dir,
Expand Down
16 changes: 8 additions & 8 deletions envisage/tests/test_egg_basket_plugin_manager.py
Expand Up @@ -37,15 +37,15 @@ def setUpClass(cls):

eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "eggs")
for egg_name in ["acme.bar", "acme.baz", "acme.foo"]:
for egg_name in ["acme-bar", "acme-baz", "acme-foo"]:
build_egg(
egg_dir=join(eggs_root_dir, egg_name),
dist_dir=cls.eggs_dir,
)

bad_eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "bad_eggs")
for egg_name in ["acme.bad"]:
for egg_name in ["acme-bad"]:
build_egg(
egg_dir=join(bad_eggs_root_dir, egg_name),
dist_dir=cls.bad_eggs_dir,
Expand Down Expand Up @@ -205,22 +205,22 @@ def on_broken_plugin(ep, exc):

def test_ignore_broken_distributions_raises_exceptions_by_default(self):
# Make sure that the distributions from eggs are already in the working
# set. This includes acme.foo, with version 0.1a1.
# set. This includes acme-foo, with version 0.1a1.
for dist in pkg_resources.find_distributions(self.eggs_dir):
pkg_resources.working_set.add(dist)

plugin_manager = EggBasketPluginManager(
plugin_path=[
# Attempt to add acme.foo, with conflicting version 0.1a11
self._create_broken_distribution_eggdir("acme.foo*.egg"),
# Attempt to add acme-foo, with conflicting version 0.1a11
self._create_broken_distribution_eggdir("acme_foo*.egg"),
],
)
with self.assertRaises(RuntimeError):
iter(plugin_manager)

def test_ignore_broken_distributions_loads_good_distributions(self):
# Make sure that the distributions from eggs are already in the working
# set. This includes acme.foo, with version 0.1a1.
# set. This includes acme-foo, with version 0.1a1.
for dist in pkg_resources.find_distributions(self.eggs_dir):
pkg_resources.working_set.add(dist)

Expand All @@ -234,7 +234,7 @@ def on_broken_distribution(dist, exc):
plugin_manager = EggBasketPluginManager(
plugin_path=[
self.eggs_dir,
self._create_broken_distribution_eggdir("acme.foo*.egg"),
self._create_broken_distribution_eggdir("acme_foo*.egg"),
],
on_broken_distribution=on_broken_distribution,
)
Expand All @@ -246,7 +246,7 @@ def on_broken_distribution(dist, exc):
self.assertIn("acme.baz", ids)

self.assertEqual(data["count"], 1)
self.assertEqual(data["distribution"].project_name, "acme.foo")
self.assertEqual(data["distribution"].project_name, "acme-foo")
exc = data["exc"]
self.assertTrue(isinstance(exc, pkg_resources.VersionConflict))

Expand Down
20 changes: 8 additions & 12 deletions pyproject.toml
Expand Up @@ -64,19 +64,15 @@ include = ['envisage*']
'envisage.examples' = ['demo/**']
'envisage.tests' = [
'bad_eggs/README.txt',
'bad_eggs/acme.bad/setup.py',
'bad_eggs/acme.bad/acme/*.py',
'bad_eggs/acme.bad/acme/bad/*.py',
'bad_eggs/acme-bad/setup.py',
'bad_eggs/acme-bad/acme_bad/*.py',
'eggs/README.txt',
'eggs/acme.bar/setup.py',
'eggs/acme.bar/acme/*.py',
'eggs/acme.bar/acme/bar/*.py',
'eggs/acme.baz/setup.py',
'eggs/acme.baz/acme/*.py',
'eggs/acme.baz/acme/baz/*.py',
'eggs/acme.foo/setup.py',
'eggs/acme.foo/acme/*.py',
'eggs/acme.foo/acme/foo/*.py',
'eggs/acme-bar/setup.py',
'eggs/acme-bar/acme_bar/*.py',
'eggs/acme-baz/setup.py',
'eggs/acme-baz/acme_baz/*.py',
'eggs/acme-foo/setup.py',
'eggs/acme-foo/acme_foo/*.py',
'plugins/pear/*.py',
'plugins/banana/*.py',
'plugins/orange/*.py',
Expand Down

0 comments on commit 518dadd

Please sign in to comment.