is run, or the interactive interpreter is reset.
Can be disabled by uncommenting
"#VMARGS=-Dpyghidra.sys.modules.restore.disable=true" in
launch.properties if its found to cause problems.
pyghidra_launcher.py can now use an existing pyghidra
installation in an externally managed environment. Upgrading is disabled
in this scenario.
Fixed an issue with getting the package version from an arbitrary
environment
Verifying the type annotations used by PyGhidra with Mypy static type
checker leads to the following error:
core.py:171: error: Argument 1 to "contextmanager" has incompatible
type "Callable[[str | Path, str | Path, str, Any, str, str, str |
JClass, str, Any], AbstractContextManager[Any, bool | None]]";
expected "Callable[[str | Path, str | Path, str, Any, str, str, str
| JClass, str, Any], Iterator[Never]]" [arg-type]
Indeed, in Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py,
function open_program was declared to return a
ContextManager["FlatProgramAPI"]. While this function indeed returns
such a type, the implementation uses decorator @contextlib.contextmanager
which expects the wrapped function to return an generator (with yield).
Use Generator["FlatProgramAPI", None, None] to fix this.
While at it, fix other locations where the type annotation of the
function wrapped with contextmanager was incorrect.
Refactors the `get_package_version` helper function to use the standard
`importlib.metadata` library instead of a subprocess call to `pip show`.
This change provides several benefits:
- Robustness: Avoids brittle parsing of command-line tool output.
- Performance: Eliminates the overhead of spawning a new process.
- Correctness: The return type hint is corrected to `Optional[str]` to
accurately reflect that the function can return `None`.
- Simplicity: The unused `python_cmd` parameter has been removed,
simplifying the function's signature.