Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py: construct PKG_CONFIG_PATH even if there are broken packages #56

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 25 additions & 2 deletions src/pkgconf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
import importlib.util
import itertools
import logging
import operator
Expand Down Expand Up @@ -68,8 +69,30 @@


def _get_module_paths(name: str) -> Sequence[str]:
module = importlib.import_module(name)
return list(module.__path__)
# this gets the path of the module while trying to avoid loading new
# modules (which really is only true if it's a toplevel package)
try:
spec = importlib.util.find_spec(name)
except Exception as e:

Check warning on line 76 in src/pkgconf/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pkgconf/__init__.py#L76

Added line #L76 was not covered by tests
# Likely failed to load the parent module
_LOGGER.warning('Exception occurred when finding module "%s": %r', name, e)
return []

Check warning on line 79 in src/pkgconf/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pkgconf/__init__.py#L78-L79

Added lines #L78 - L79 were not covered by tests

if spec is None:
_LOGGER.warning('Could not find module "%s"', name)
return []

Check warning on line 83 in src/pkgconf/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pkgconf/__init__.py#L82-L83

Added lines #L82 - L83 were not covered by tests

if spec.has_location and spec.origin is not None:
# this is usually a directory but let's be defensive
if os.path.isdir(spec.origin):
return [spec.origin]

Check warning on line 88 in src/pkgconf/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pkgconf/__init__.py#L88

Added line #L88 was not covered by tests
return [os.path.dirname(spec.origin)]

if not spec.submodule_search_locations:
_LOGGER.warning('Module "%s" cannot be located', name)
return []

Check warning on line 93 in src/pkgconf/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/pkgconf/__init__.py#L92-L93

Added lines #L92 - L93 were not covered by tests

return spec.submodule_search_locations


def get_pkg_config_path() -> Sequence[str]:
Expand Down
Loading