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

Recover from TypeError raised by inspect.getfile #74

Merged
merged 1 commit into from
Nov 27, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix: Recover from `TypeError` when getting plugin path (when using pytest-xdist)

## [0.3.1] - 2023-08-08

- Feature: Add `exc_info` and `stack_info` parameters to message bar logger for capturing exception.
Expand Down
14 changes: 12 additions & 2 deletions tools/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from qgis.PyQt.QtWidgets import QDialog, QWidget

__copyright__ = (
"Copyright 2019, 3Liz, 2020-2021 Gispo Ltd, 2022 National Land Survey of Finland"
"Copyright 2019, 3Liz, 2020-2021 Gispo Ltd, "
"2022-2023 National Land Survey of Finland"
)
__license__ = "GPL version 3"
__email__ = "[email protected]"
Expand Down Expand Up @@ -56,7 +57,16 @@ def _plugin_path_dependency() -> str:
top_level_name, *_ = module_name.split(".", maxsplit=1)
top_level_module = sys.modules.get(top_level_name)
if top_level_module is not None:
top_level_directory = Path(inspect.getfile(top_level_module)).parent
try:
top_level_directory = Path(inspect.getfile(top_level_module)).parent
except TypeError:
# TypeError gets thrown if
LKajan marked this conversation as resolved.
Show resolved Hide resolved
# pytest-xdist is used in tests since it
# adds <module '__main__' (built-in)> into stack
LKajan marked this conversation as resolved.
Show resolved Hide resolved
# The 'getfile' function throws a TypeError for built-in modules.
# We are only interested in custom modules, so it is safe to ignore
# the error.
continue
if (top_level_directory / "metadata.txt").exists():
return str(top_level_directory)

Expand Down