@@ -269,6 +269,54 @@ def test_namespace_created_via_package_dir(self, venv, tmp_path, editable_opts):
269269 venv .run (["python" , "-m" , "pip" , "install" , "-e" , str (pkg_C ), * opts ])
270270 venv .run (["python" , "-c" , "from myns.n import pkgA, pkgB, pkgC" ])
271271
272+ def test_namespace_accidental_config_in_lenient_mode (self , venv , tmp_path ):
273+ """Sometimes users might specify an ``include`` pattern that ignores parent
274+ packages. In a normal installation this would ignore all modules inside the
275+ parent packages, and make them namespaces (reported in issue #3504),
276+ so the editable mode should preserve this behaviour.
277+ """
278+ files = {
279+ "pkgA" : {
280+ "pyproject.toml" : dedent ("""\
281+ [build-system]
282+ requires = ["setuptools", "wheel"]
283+ build-backend = "setuptools.build_meta"
284+
285+ [project]
286+ name = "pkgA"
287+ version = "3.14159"
288+
289+ [tool.setuptools]
290+ packages.find.include = ["mypkg.*"]
291+ """ ),
292+ "mypkg" : {
293+ "__init__.py" : "" ,
294+ "other.py" : "b = 1" ,
295+ "n" : {
296+ "__init__.py" : "" ,
297+ "pkgA.py" : "a = 1" ,
298+ },
299+ },
300+ "MANIFEST.in" : EXAMPLE ["MANIFEST.in" ],
301+ },
302+ }
303+ jaraco .path .build (files , prefix = tmp_path )
304+ pkg_A = tmp_path / "pkgA"
305+
306+ # use pip to install to the target directory
307+ opts = ["--no-build-isolation" ] # force current version of setuptools
308+ venv .run (["python" , "-m" , "pip" , "-v" , "install" , "-e" , str (pkg_A ), * opts ])
309+ out = venv .run (["python" , "-c" , "from mypkg.n import pkgA; print(pkgA.a)" ])
310+ assert str (out , "utf-8" ).strip () == "1"
311+ cmd = """\
312+ try:
313+ import mypkg.other
314+ except ImportError:
315+ print("mypkg.other not defined")
316+ """
317+ out = venv .run (["python" , "-c" , dedent (cmd )])
318+ assert "mypkg.other not defined" in str (out , "utf-8" )
319+
272320
273321# Moved here from test_develop:
274322@pytest .mark .xfail (
@@ -490,7 +538,7 @@ def test_pkg_roots(tmp_path):
490538 assert ns == {"f" , "f.g" }
491539
492540 ns = set (_find_virtual_namespaces (roots ))
493- assert ns == {"a.b.c.x" , "a.b.c.x.y" , "m" , "m.n" , "m.n.o" , "m.n.o.p" }
541+ assert ns == {"a.b" , "a.b .c.x" , "a.b.c.x.y" , "m" , "m.n" , "m.n.o" , "m.n.o.p" }
494542
495543
496544class TestOverallBehaviour :
0 commit comments