Imported Upstream version 38.2.2 upstream/38.2.2
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 14 Jan 2019 01:40:29 +0000 (10:40 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 14 Jan 2019 01:40:29 +0000 (10:40 +0900)
CHANGES.rst
setup.cfg
setup.py
setuptools/tests/test_wheel.py
setuptools/wheel.py

index d5fd66a..3886854 100644 (file)
@@ -1,3 +1,9 @@
+v38.2.2
+-------
+
+* #1214: fix handling of namespace packages when installing
+  from a wheel.
+
 v38.2.1
 -------
 
index fd93d44..19b073e 100755 (executable)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 38.2.1
+current_version = 38.2.2
 commit = True
 tag = True
 
index 8662816..778fc50 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -89,7 +89,7 @@ def pypi_link(pkg_filename):
 
 setup_params = dict(
     name="setuptools",
-    version="38.2.1",
+    version="38.2.2",
     description="Easily download, build, install, upgrade, and uninstall "
         "Python packages",
     author="Python Packaging Authority",
index 2e85725..408c357 100644 (file)
@@ -412,6 +412,38 @@ WHEEL_INSTALL_TESTS = (
         ),
     ),
 
+    dict(
+        id='namespace_package',
+        file_defs={
+            'foo': {
+                'bar': {
+                    '__init__.py': ''
+                },
+            },
+        },
+        setup_kwargs=dict(
+            namespace_packages=['foo'],
+            packages=['foo.bar'],
+        ),
+        install_tree=DALS(
+            '''
+            foo-1.0-py{py_version}.egg/
+            |-- foo-1.0-py{py_version}-nspkg.pth
+            |-- EGG-INFO/
+            |  |-- DESCRIPTION.rst
+            |  |-- PKG-INFO
+            |  |-- RECORD
+            |  |-- WHEEL
+            |  |-- metadata.json
+            |  |-- namespace_packages.txt
+            |  |-- top_level.txt
+            |-- foo/
+            |  |-- __init__.py
+            |  |-- bar/
+            |  |  |-- __init__.py
+            '''),
+    ),
+
 )
 
 @pytest.mark.parametrize(
index f711f38..c232721 100644 (file)
@@ -20,6 +20,13 @@ WHEEL_NAME = re.compile(
     )\.whl$""",
 re.VERBOSE).match
 
+NAMESPACE_PACKAGE_INIT = '''\
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    __path__ = __import__('pkgutil').extend_path(__path__, __name__)
+'''
+
 
 class Wheel(object):
 
@@ -124,3 +131,14 @@ class Wheel(object):
                 os.rmdir(subdir)
             if os.path.exists(dist_data):
                 os.rmdir(dist_data)
+            # Fix namespace packages.
+            namespace_packages = os.path.join(egg_info, 'namespace_packages.txt')
+            if os.path.exists(namespace_packages):
+                with open(namespace_packages) as fp:
+                    namespace_packages = fp.read().split()
+                for mod in namespace_packages:
+                    mod_dir = os.path.join(destination_eggdir, *mod.split('.'))
+                    mod_init = os.path.join(mod_dir, '__init__.py')
+                    if os.path.exists(mod_dir) and not os.path.exists(mod_init):
+                        with open(mod_init, 'w') as fp:
+                            fp.write(NAMESPACE_PACKAGE_INIT)