Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/pkgconf/_path_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def module_path(name: str) -> str:
module = import_module_no_exec(name)
# Check if submodule_search_locations is set on the spec.
if module.__spec__.submodule_search_locations:
# If it contains a single path, use it.
if len(module.__spec__.submodule_search_locations) == 1:
return module.__spec__.submodule_search_locations[0]
# Namespace packages may span multiple locations. Return the first one,
# which matches the import system search order.
return next(iter(module.__spec__.submodule_search_locations))
# Traversables often implement __fspath__, attempt to use it.
traversable = importlib.resources.files(module)
if isinstance(traversable, os.PathLike):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix=${pcfiledir}
13 changes: 13 additions & 0 deletions tests/packages/namespace-pkgconfig-primary/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
build-backend = 'hatchling.build'
requires = ['hatchling']

[project]
name = 'namespace-pkgconfig-primary'
version = '1.0.0'

[project.entry-points.pkg_config]
namespace-pkgconfig-primary = 'namespace.pkgconf'

[tool.hatch.build.targets.wheel]
packages = ['namespace']
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prefix=${pcfiledir}
10 changes: 10 additions & 0 deletions tests/packages/namespace-pkgconfig-secondary/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
build-backend = 'hatchling.build'
requires = ['hatchling']

[project]
name = 'namespace-pkgconfig-secondary'
version = '1.0.0'

[tool.hatch.build.targets.wheel]
packages = ['namespace']
31 changes: 31 additions & 0 deletions tests/test_python_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@ def test_pkg_config_path_namespace(env, packages):
assert path == [pathlib.Path(env.scheme['purelib'], 'namespace')]


def test_pkg_config_path_namespace_multiple_locations(env, packages, tmp_path):
dst = tmp_path / 'namespace-pkgconfig-primary'
shutil.copytree(packages / 'namespace-pkgconfig-primary', dst)

env.install(['-e', dst])
env.install_from_path(packages / 'namespace-pkgconfig-secondary', from_sdist=False)

script = """
import os
import warnings
import pkgconf
import pkgconf._path_entrypoints

warnings.simplefilter('error', pkgconf._path_entrypoints.PathWarning)
paths = [
path for path in pkgconf.get_pkg_config_path()
if path.endswith(os.path.join('namespace', 'pkgconf'))
]
assert len(paths) == 1, paths
"""
process = subprocess.run(
[os.fspath(env.interpreter), '-c', script],
env=env.env,
capture_output=True,
text=True,
check=False,
)

assert process.returncode == 0, process.stderr


def test_pkg_config_path_error_on_import(env, packages):
path = list(env.introspectable.call('pkgconf.get_pkg_config_path'))
assert len(path) == 0
Expand Down
Loading