mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 01:39:21 +02:00
GP-5345: New ghidra-stubs with README.md
This commit is contained in:
parent
115353d34c
commit
b965e693a0
3 changed files with 69 additions and 0 deletions
50
GhidraBuild/BuildFiles/Doclets/support/GhidraStubs_README.md
Normal file
50
GhidraBuild/BuildFiles/Doclets/support/GhidraStubs_README.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Ghidra Type Stubs
|
||||
|
||||
The Ghidra Type Stubs library is a [PEP 561 stubs package][pep-0561] for the
|
||||
[Ghidra API](https://github.com/NationalSecurityAgency/ghidra). The stub files can be used to
|
||||
improve your development experience in supported editors like PyCharm and Visual Studio Code.
|
||||
|
||||
## Installation
|
||||
|
||||
The stubs can be installed with `pip install ghidra-stubs*.whl` into the environment in which the
|
||||
real Ghidra module (i.e., `pyghidra`) is available. Any conformant tool will then use the stubs
|
||||
package for type analysis purposes.
|
||||
|
||||
## Usage
|
||||
|
||||
Once installed, all you need to do is import the Ghidra modules as usual, and your supported editor
|
||||
will do the rest.
|
||||
|
||||
```python
|
||||
import pyghidra
|
||||
```
|
||||
|
||||
To get support for the Ghidra builtins, you need to import them as well. The type hints for those
|
||||
exist in the generated `ghidra_builtins` stub. Since it is not a real Python module, importing it at
|
||||
runtime will fail.
|
||||
|
||||
```python
|
||||
try:
|
||||
from ghidra.ghidra_builtins import *
|
||||
except:
|
||||
pass
|
||||
```
|
||||
|
||||
If you are using [PyGhidra](https://pypi.org/project/pyghidra/) from a Python 3 environment where no
|
||||
real `ghidra` module exists you can use a snippet like the following:
|
||||
|
||||
```python
|
||||
import typing
|
||||
if typing.TYPE_CHECKING:
|
||||
from ghidra.ghidra_builtins import *
|
||||
|
||||
# actual code follows here
|
||||
```
|
||||
|
||||
`typing.TYPE_CHECKING` is a special value that is always `False` at runtime but `True` during any
|
||||
kind of type checking or completion.
|
||||
|
||||
Once done, just code & enjoy.
|
||||
|
||||
[pep-0484]: https://www.python.org/dev/peps/pep-0484/
|
||||
[pep-0561]: https://www.python.org/dev/peps/pep-0561/#stub-only-packages
|
|
@ -1,4 +1,5 @@
|
|||
##VERSION: 2.0
|
||||
Doclets/Module.manifest||GHIDRA||||END|
|
||||
Doclets/support/GhidraStubs_README.md||GHIDRA||||END|
|
||||
sleighDevBuild.template||GHIDRA||||END|
|
||||
sleighDistBuild.template||GHIDRA||||END|
|
||||
|
|
|
@ -246,6 +246,12 @@ task createGhidraStubsWheel {
|
|||
from(file("${ROOT_PROJECT_DIR}/LICENSE"))
|
||||
into typestubsDir
|
||||
}
|
||||
|
||||
copy {
|
||||
from("${ROOT_PROJECT_DIR}/GhidraBuild/BuildFiles/Doclets/support/GhidraStubs_README.md")
|
||||
into typestubsDir
|
||||
rename "GhidraStubs_README.md", "README.md"
|
||||
}
|
||||
|
||||
def manifest = file("${typestubsDir}/MANIFEST.in")
|
||||
manifest.write("graft src\n")
|
||||
|
@ -259,10 +265,22 @@ task createGhidraStubsWheel {
|
|||
[project]
|
||||
name = "ghidra-stubs"
|
||||
version = "${project.version}"
|
||||
dynamic = ["readme"]
|
||||
description = "Ghidra Type Stubs"
|
||||
license = {text = "Apache-2.0"}
|
||||
maintainers = [
|
||||
{name = "Ghidra Development Team"},
|
||||
]
|
||||
keywords = [
|
||||
"ghidra",
|
||||
]
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: Apache Software License",
|
||||
"Typing :: Stubs Only",
|
||||
]
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
readme = {file = ["README.md"], content-type = "text/markdown"}
|
||||
""".stripIndent()
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue