GP-7053: Adding Python typing_extensions module and using it in PyGhidra

for deprecation
This commit is contained in:
Ryan Kurtz
2026-07-10 05:13:30 -04:00
parent 5aa3853207
commit 7008a9ce0f
6 changed files with 14 additions and 11 deletions

View File

@@ -23,3 +23,4 @@ MODULE FILE LICENSE: pypkg/dist/jpype1-1.5.2.tar.gz Apache License 2.0
MODULE FILE LICENSE: pypkg/dist/packaging-25.0-py3-none-any.whl Apache License 2.0 MODULE FILE LICENSE: pypkg/dist/packaging-25.0-py3-none-any.whl Apache License 2.0
MODULE FILE LICENSE: pypkg/dist/setuptools-80.9.0-py3-none-any.whl MIT MODULE FILE LICENSE: pypkg/dist/setuptools-80.9.0-py3-none-any.whl MIT
MODULE FILE LICENSE: pypkg/dist/wheel-0.45.1-py3-none-any.whl MIT MODULE FILE LICENSE: pypkg/dist/wheel-0.45.1-py3-none-any.whl MIT
MODULE FILE LICENSE: pypkg/dist/typing_extensions-4.16.0-py3-none-any.whl Python Software Foundation License

View File

@@ -58,6 +58,7 @@ distributePyDep("jpype1-1.5.2.tar.gz")
distributePyDep("packaging-25.0-py3-none-any.whl") distributePyDep("packaging-25.0-py3-none-any.whl")
distributePyDep("setuptools-80.9.0-py3-none-any.whl") distributePyDep("setuptools-80.9.0-py3-none-any.whl")
distributePyDep("wheel-0.45.1-py3-none-any.whl") distributePyDep("wheel-0.45.1-py3-none-any.whl")
distributePyDep("typing_extensions-4.16.0-py3-none-any.whl")
// Install JPype into the development virtual environment // Install JPype into the development virtual environment
task installJPype(type: Exec) { task installJPype(type: Exec) {

View File

@@ -573,6 +573,8 @@ __3.2.0__
* When an uncaught `JException` occurs, PyGhidra will now output the full Java stack trace. * When an uncaught `JException` occurs, PyGhidra will now output the full Java stack trace.
* PyGhidra no longer swallows the original exception object generated by GhidraScripts. * PyGhidra no longer swallows the original exception object generated by GhidraScripts.
* PyGhidra now depends on `JPype >=1.5.2, != 1.6.0, != 1.7.0`. * PyGhidra now depends on `JPype >=1.5.2, != 1.6.0, != 1.7.0`.
* Using `typing_extensions` to properly deprecate [`pyghidra.open_program()`](#pyghidraopen_program)
and [`pyghidra.run_script()`](#pyghidrarun_script).
__3.1.0__ __3.1.0__
* PyGhidra will now, by default, restore `sys.modules` to its prior state after a PyGhidra script is * PyGhidra will now, by default, restore `sys.modules` to its prior state after a PyGhidra script is

View File

@@ -31,6 +31,7 @@ classifiers = [
] ]
dependencies = [ dependencies = [
"Jpype1 >=1.5.2, !=1.6.0, !=1.7.0", "Jpype1 >=1.5.2, !=1.6.0, !=1.7.0",
"typing_extensions ~=4.16",
"packaging" "packaging"
] ]

View File

@@ -14,7 +14,7 @@
# limitations under the License. # limitations under the License.
## ##
import contextlib import contextlib
import warnings from typing_extensions import deprecated
from typing import Union, TYPE_CHECKING, Tuple, Generator, List, Optional from typing import Union, TYPE_CHECKING, Tuple, Generator, List, Optional
from pyghidra.converters import * # pylint: disable=wildcard-import, unused-wildcard-import from pyghidra.converters import * # pylint: disable=wildcard-import, unused-wildcard-import
@@ -169,6 +169,7 @@ def _analyze_program(flat_api, program):
@contextlib.contextmanager @contextlib.contextmanager
@deprecated("open_program() is deprecated, use open_project() and program_context() or program_loader() instead.", stacklevel=3)
def open_program( def open_program(
binary_path: Union[str, Path], binary_path: Union[str, Path],
project_location: Union[str, Path] = None, project_location: Union[str, Path] = None,
@@ -206,11 +207,6 @@ def open_program(
:raises ValueError: If the provided language, compiler or loader is invalid. :raises ValueError: If the provided language, compiler or loader is invalid.
:raises TypeError: If the provided loader does not implement `ghidra.app.util.opinion.Loader`. :raises TypeError: If the provided loader does not implement `ghidra.app.util.opinion.Loader`.
""" """
warnings.warn(
"open_program() is deprecated, use open_project() and program_context() or program_loader() instead.",
DeprecationWarning,
stacklevel=3
)
from pyghidra.launcher import PyGhidraLauncher, HeadlessPyGhidraLauncher from pyghidra.launcher import PyGhidraLauncher, HeadlessPyGhidraLauncher
@@ -320,6 +316,7 @@ def _flat_api(
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
@deprecated("run_script() is deprecated, use open_project() and ghidra_script() instead.", stacklevel=3)
def run_script( def run_script(
binary_path: Optional[Union[str, Path]], binary_path: Optional[Union[str, Path]],
script_path: Union[str, Path], script_path: Union[str, Path],
@@ -367,11 +364,6 @@ def run_script(
:raises ValueError: If the provided language, compiler or loader is invalid. :raises ValueError: If the provided language, compiler or loader is invalid.
:raises TypeError: If the provided loader does not implement `ghidra.app.util.opinion.Loader`. :raises TypeError: If the provided loader does not implement `ghidra.app.util.opinion.Loader`.
""" """
warnings.warn(
"run_script() is deprecated, use open_project() and ghidra_script() instead.",
DeprecationWarning,
stacklevel=3
)
script_path = str(script_path) script_path = str(script_path)
args = binary_path, project_location, project_name, verbose, analyze, lang, compiler, loader, program_name, nested_project_location args = binary_path, project_location, project_name, verbose, analyze, lang, compiler, loader, program_name, nested_project_location

View File

@@ -345,6 +345,12 @@ ext.deps = [
url: "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl", url: "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl",
sha256: "29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", sha256: "29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484",
destination: file("${DEPS_DIR}/PyGhidra/") destination: file("${DEPS_DIR}/PyGhidra/")
],
[
name: "typing_extensions-4.16.0-py3-none-any.whl",
url: "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl",
sha256: "481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8",
destination: file("${DEPS_DIR}/PyGhidra/")
], ],
[ [
name: "jpype1-1.5.2-cp313-cp313-macosx_10_13_universal2.whl", name: "jpype1-1.5.2-cp313-cp313-macosx_10_13_universal2.whl",