Skip to content

Commit 5c82908

Browse files
committed
Build docs with sphinx
1 parent e13ac14 commit 5c82908

File tree

11 files changed

+218
-23
lines changed

11 files changed

+218
-23
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,13 @@ jobs:
114114
with:
115115
python-version: '3.11'
116116
- run: |
117-
pip install pdoc
118-
pip install -e .
119-
- run: pdoc -o docs pypcode
120-
- uses: actions/upload-pages-artifact@v1
121-
with:
122-
path: docs/
123-
124-
deploy_docs:
125-
name: Deploy docs to GitHub pages
126-
needs: [build_docs, build_wheels, test_wheels]
127-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
128-
runs-on: ubuntu-latest
129-
permissions:
130-
pages: write
131-
id-token: write
132-
environment:
133-
name: github-pages
134-
url: ${{ steps.deployment.outputs.page_url }}
135-
steps:
136-
- id: deployment
137-
uses: actions/deploy-pages@v1
117+
pip install -e .[docs]
118+
cd docs && make html coverage
119+
if [ -s _build/coverage/python.txt ]; then
120+
echo "Doc coverage is missing for:"
121+
cat _build/coverage/python.txt
122+
exit 1
123+
fi
138124
139125
upload_pypi:
140126
name: Upload wheels to PyPI

.readthedocs.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
version: 2
5+
build:
6+
os: ubuntu-22.04
7+
tools:
8+
python: "3.8"
9+
10+
python:
11+
install:
12+
- method: pip
13+
path: .
14+
extra_requirements:
15+
- docs

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_build

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:mod:`pypcode`
2+
=========================================
3+
4+
.. automodule:: pypcode

docs/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
import datetime
7+
8+
# -- Project information -----------------------------------------------------
9+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
10+
11+
project = "pypcode"
12+
project_copyright = f"{datetime.datetime.now().year}, The angr Project contributors"
13+
author = "The angr Project"
14+
15+
# -- General configuration ---------------------------------------------------
16+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
17+
18+
extensions = [
19+
"sphinx.ext.autodoc",
20+
"sphinx.ext.autosummary",
21+
"sphinx.ext.coverage",
22+
"sphinx.ext.napoleon",
23+
"sphinx.ext.todo",
24+
"sphinx.ext.viewcode",
25+
"sphinx_autodoc_typehints",
26+
"myst_parser",
27+
]
28+
29+
templates_path = ["_templates"]
30+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
31+
32+
# -- Options for autodoc -----------------------------------------------------
33+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration
34+
autoclass_content = "class"
35+
autodoc_default_options = {
36+
"members": True,
37+
"member-order": "bysource",
38+
"inherited-members": True,
39+
"show-inheritance": True,
40+
"undoc-members": True,
41+
}
42+
autodoc_inherit_docstrings = True
43+
autodoc_typehints = "both"
44+
45+
# -- Options for coverage ----------------------------------------------------
46+
# https://www.sphinx-doc.org/en/master/usage/extensions/coverage.html
47+
coverage_write_headline = False
48+
49+
# -- Options for HTML output -------------------------------------------------
50+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
51+
52+
html_theme = "furo"
53+
html_static_path = ["_static"]

docs/index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pypcode documentation
2+
=====================
3+
pypcode is a machine code disassembly and IR translation library for Python using the
4+
excellent `SLEIGH <https://ghidra.re/courses/languages/html/sleigh.html>`__ library from the `Ghidra <https://ghidra-sre.org/>`__ framework (version 10.2.2).
5+
6+
This library was created primarily for use with `angr <http://angr.io>`__, which provides analyses and symbolic
7+
execution of p-code.
8+
9+
Table of Contents
10+
-----------------
11+
12+
.. toctree::
13+
:maxdepth: 2
14+
15+
Quick Start <quickstart>
16+
API <api>
17+
18+
Indices and Tables
19+
------------------
20+
21+
* :ref:`genindex`
22+
* :ref:`modindex`
23+
* :ref:`search`

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/quickstart.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Quick Start
2+
===========
3+
4+
Installation
5+
------------
6+
This package can be installed on Linux, macOS, and Windows platforms for recent (3.8+) versions of both CPython and
7+
PyPy. Wheels are provided for several configurations. You can install the latest release from PyPI using ``pip``:
8+
9+
.. code:: bash
10+
11+
pip install pypcode
12+
13+
You can also install the very latest development version from this repository using ``pip``:
14+
15+
.. code:: bash
16+
17+
pip install --user https://github.com/angr/pypcode/archive/refs/heads/master.zip
18+
19+
You can now invoke the ``pypcode`` module from command line to translate supported machine code to P-code from command
20+
line. Run ``python -m pypcode --help`` for usage information. See module source(``__main__.py``) for examples of using
21+
pypcode as a library.
22+
23+
Command Line Usage Example
24+
--------------------------
25+
::
26+
27+
$ python -m pypcode -b x86:LE:64:default test-x64.bin
28+
--------------------------------------------------------------------------------
29+
00000000/2: XOR EAX,EAX
30+
--------------------------------------------------------------------------------
31+
0: CF = 0x0
32+
1: OF = 0x0
33+
2: EAX = EAX ^ EAX
34+
3: RAX = zext(EAX)
35+
4: SF = EAX s< 0x0
36+
5: ZF = EAX == 0x0
37+
6: unique[0x2580:4] = EAX & 0xff
38+
7: unique[0x2590:1] = popcount(unique[0x2580:4])
39+
8: unique[0x25a0:1] = unique[0x2590:1] & 0x1
40+
9: PF = unique[0x25a0:1] == 0x0
41+
42+
--------------------------------------------------------------------------------
43+
00000002/2: CMP ESI,EAX
44+
--------------------------------------------------------------------------------
45+
0: CF = ESI < EAX
46+
1: OF = sborrow(ESI, EAX)
47+
2: unique[0x5180:4] = ESI - EAX
48+
3: SF = unique[0x5180:4] s< 0x0
49+
4: ZF = unique[0x5180:4] == 0x0
50+
5: unique[0x2580:4] = unique[0x5180:4] & 0xff
51+
6: unique[0x2590:1] = popcount(unique[0x2580:4])
52+
7: unique[0x25a0:1] = unique[0x2590:1] & 0x1
53+
8: PF = unique[0x25a0:1] == 0x0
54+
55+
--------------------------------------------------------------------------------
56+
00000004/2: JBE 0x17
57+
--------------------------------------------------------------------------------
58+
0: unique[0x18f0:1] = CF || ZF
59+
1: if (unique[0x18f0:1]) goto ram[0x17:8]

pypcode/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22
"""
33
Pythonic interface to SLEIGH by way of the csleigh C API wrapper and CFFI.
4-
5-
.. include:: ../README.md
64
"""
75

86
import os.path

0 commit comments

Comments
 (0)