From 776096522af8d8320b879571ded2b1c43242c0da Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Wed, 27 Jun 2018 21:32:11 +0300 Subject: always process module.__path__ for namespace packages, fixes #1321 --- pkg_resources/__init__.py | 11 ++++++----- setuptools/tests/test_namespaces.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 67015408..d642a405 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2135,12 +2135,13 @@ def _rebuild_mod_path(orig_path, package_name, module): parts = path_parts[:-module_parts] return safe_sys_path_index(_normalize_cached(os.sep.join(parts))) - if not isinstance(orig_path, list): - # Is this behavior useful when module.__path__ is not a list? - return + new_path = sorted(orig_path, key=position_in_sys_path) + new_path = [_normalize_cached(p) for p in new_path] - orig_path.sort(key=position_in_sys_path) - module.__path__[:] = [_normalize_cached(p) for p in orig_path] + if isinstance(module.__path__, list): + module.__path__[:] = new_path + else: + module.__path__ = new_path def declare_namespace(packageName): diff --git a/setuptools/tests/test_namespaces.py b/setuptools/tests/test_namespaces.py index 1ac1b35e..00ec75b4 100644 --- a/setuptools/tests/test_namespaces.py +++ b/setuptools/tests/test_namespaces.py @@ -109,3 +109,34 @@ class TestNamespaces: ] with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(pkg_resources_imp, cwd=str(pkg_A)) + + @pytest.mark.skipif(bool(os.environ.get("APPVEYOR")), + reason="https://github.com/pypa/setuptools/issues/851") + def test_packages_in_the_sampe_namespace_installed_and_cwd(self, tmpdir): + """ + Installing one namespace package and also have another in the same + namespace in the current working directory, both of them must be + importable. + """ + pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA') + pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB') + target = tmpdir / 'packages' + # use pip to install to the target directory + install_cmd = [ + sys.executable, + '-m', + 'pip.__main__', + 'install', + str(pkg_A), + '-t', str(target), + ] + subprocess.check_call(install_cmd) + namespaces.make_site_dir(target) + + # ensure that all packages import and pkg_resources imports + pkg_resources_imp = [ + sys.executable, + '-c', 'import pkg_resources; import myns.pkgA; import myns.pkgB', + ] + with test.test.paths_on_pythonpath([str(target)]): + subprocess.check_call(pkg_resources_imp, cwd=str(pkg_B)) -- cgit v1.2.3 From ecae51daeff22edcbbab38016d118778add14d33 Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Wed, 27 Jun 2018 21:44:13 +0300 Subject: added changelog.d entry --- changelog.d/1402.change.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/1402.change.rst diff --git a/changelog.d/1402.change.rst b/changelog.d/1402.change.rst new file mode 100644 index 00000000..5a68ac9d --- /dev/null +++ b/changelog.d/1402.change.rst @@ -0,0 +1,2 @@ +Fixed a bug with namespace packages under python-3.6 when one package in +current directory hides another which is installed. -- cgit v1.2.3 From d2346c91804333b29fe63b8e1414cd764eb1ef5f Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Fri, 17 Aug 2018 17:36:20 +0300 Subject: xfail namespace packages tests on appveyor instead of skipping them --- setuptools/tests/test_namespaces.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/setuptools/tests/test_namespaces.py b/setuptools/tests/test_namespaces.py index 00ec75b4..52ac6a68 100644 --- a/setuptools/tests/test_namespaces.py +++ b/setuptools/tests/test_namespaces.py @@ -14,8 +14,10 @@ class TestNamespaces: @pytest.mark.xfail(sys.version_info < (3, 5), reason="Requires importlib.util.module_from_spec") - @pytest.mark.skipif(bool(os.environ.get("APPVEYOR")), - reason="https://github.com/pypa/setuptools/issues/851") + @pytest.mark.xfail( + os.environ.get("APPVEYOR"), + reason="https://github.com/pypa/setuptools/issues/851", + ) def test_mixed_site_and_non_site(self, tmpdir): """ Installing two packages sharing the same namespace, one installed @@ -55,8 +57,10 @@ class TestNamespaces: with test.test.paths_on_pythonpath(map(str, targets)): subprocess.check_call(try_import) - @pytest.mark.skipif(bool(os.environ.get("APPVEYOR")), - reason="https://github.com/pypa/setuptools/issues/851") + @pytest.mark.xfail( + os.environ.get("APPVEYOR"), + reason="https://github.com/pypa/setuptools/issues/851", + ) def test_pkg_resources_import(self, tmpdir): """ Ensure that a namespace package doesn't break on import @@ -81,8 +85,10 @@ class TestNamespaces: with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(try_import) - @pytest.mark.skipif(bool(os.environ.get("APPVEYOR")), - reason="https://github.com/pypa/setuptools/issues/851") + @pytest.mark.xfail( + os.environ.get("APPVEYOR"), + reason="https://github.com/pypa/setuptools/issues/851", + ) def test_namespace_package_installed_and_cwd(self, tmpdir): """ Installing a namespace packages but also having it in the current @@ -110,8 +116,10 @@ class TestNamespaces: with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(pkg_resources_imp, cwd=str(pkg_A)) - @pytest.mark.skipif(bool(os.environ.get("APPVEYOR")), - reason="https://github.com/pypa/setuptools/issues/851") + @pytest.mark.xfail( + os.environ.get("APPVEYOR"), + reason="https://github.com/pypa/setuptools/issues/851", + ) def test_packages_in_the_sampe_namespace_installed_and_cwd(self, tmpdir): """ Installing one namespace package and also have another in the same -- cgit v1.2.3 From 1fc75056079f49d980dd664222bae47a713906ca Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Fri, 17 Aug 2018 17:38:22 +0300 Subject: change formatting to fix flake8 warning --- setuptools/tests/test_namespaces.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setuptools/tests/test_namespaces.py b/setuptools/tests/test_namespaces.py index 52ac6a68..839f5651 100644 --- a/setuptools/tests/test_namespaces.py +++ b/setuptools/tests/test_namespaces.py @@ -12,8 +12,10 @@ from setuptools.command import test class TestNamespaces: - @pytest.mark.xfail(sys.version_info < (3, 5), - reason="Requires importlib.util.module_from_spec") + @pytest.mark.xfail( + sys.version_info < (3, 5), + reason="Requires importlib.util.module_from_spec", + ) @pytest.mark.xfail( os.environ.get("APPVEYOR"), reason="https://github.com/pypa/setuptools/issues/851", -- cgit v1.2.3 From 0553c91f1c08d0426574bc996e377706a6df3e1a Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Tue, 21 Aug 2018 14:01:26 +0300 Subject: remove xfail for namespace tests that actually pass in AppVeyor --- setuptools/tests/test_namespaces.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/setuptools/tests/test_namespaces.py b/setuptools/tests/test_namespaces.py index 839f5651..f2acff84 100644 --- a/setuptools/tests/test_namespaces.py +++ b/setuptools/tests/test_namespaces.py @@ -59,10 +59,6 @@ class TestNamespaces: with test.test.paths_on_pythonpath(map(str, targets)): subprocess.check_call(try_import) - @pytest.mark.xfail( - os.environ.get("APPVEYOR"), - reason="https://github.com/pypa/setuptools/issues/851", - ) def test_pkg_resources_import(self, tmpdir): """ Ensure that a namespace package doesn't break on import @@ -87,10 +83,6 @@ class TestNamespaces: with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(try_import) - @pytest.mark.xfail( - os.environ.get("APPVEYOR"), - reason="https://github.com/pypa/setuptools/issues/851", - ) def test_namespace_package_installed_and_cwd(self, tmpdir): """ Installing a namespace packages but also having it in the current @@ -118,11 +110,7 @@ class TestNamespaces: with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(pkg_resources_imp, cwd=str(pkg_A)) - @pytest.mark.xfail( - os.environ.get("APPVEYOR"), - reason="https://github.com/pypa/setuptools/issues/851", - ) - def test_packages_in_the_sampe_namespace_installed_and_cwd(self, tmpdir): + def test_packages_in_the_same_namespace_installed_and_cwd(self, tmpdir): """ Installing one namespace package and also have another in the same namespace in the current working directory, both of them must be -- cgit v1.2.3 From ec1a8f60134fb409c9b747cb15e0b5efbd519874 Mon Sep 17 00:00:00 2001 From: Alexander Duryagin Date: Tue, 21 Aug 2018 19:48:22 +0300 Subject: remove xfail for AppVeyor from namespace tests entirely --- setuptools/tests/test_namespaces.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setuptools/tests/test_namespaces.py b/setuptools/tests/test_namespaces.py index f2acff84..da19bd79 100644 --- a/setuptools/tests/test_namespaces.py +++ b/setuptools/tests/test_namespaces.py @@ -16,10 +16,6 @@ class TestNamespaces: sys.version_info < (3, 5), reason="Requires importlib.util.module_from_spec", ) - @pytest.mark.xfail( - os.environ.get("APPVEYOR"), - reason="https://github.com/pypa/setuptools/issues/851", - ) def test_mixed_site_and_non_site(self, tmpdir): """ Installing two packages sharing the same namespace, one installed -- cgit v1.2.3