Skip to content

Commit 26eff9f

Browse files
authored
Merge pull request #121 from PyO3/readthedocs
docs: add sphinx / readthedocs configuration
2 parents 14703b8 + b4dd6d7 commit 26eff9f

File tree

14 files changed

+274
-197
lines changed

14 files changed

+274
-197
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ target
1010
*.egg-info
1111
setuptools_rust/version.py
1212
pyo3
13+
docs/_build

.readthedocs.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
3+
python:
4+
install:
5+
- requirements: docs/requirements.txt
6+
- method: pip
7+
path: .

README.md

Lines changed: 8 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Setuptools plugin for Rust extensions
22

3-
[![Build Status](https://travis-ci.org/PyO3/setuptools-rust.svg?branch=master)](https://travis-ci.org/PyO3/setuptools-rust)
3+
![example workflow](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml/badge.svg)
44
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://badge.fury.io/py/setuptools-rust)
5+
[![readthedocs](https://readthedocs.org/projects/pip/badge/)](https://setuptools-rust.readthedocs.io/en/latest/)
56
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
67

7-
Setuptools helpers for rust Python extensions implemented with [PyO3](https://github.com/PyO3/pyo3) and [rust-cpython](https://github.com/dgrunwald/rust-cpython).
8+
Setuptools helpers for Rust Python extensions implemented with [PyO3](https://github.com/PyO3/pyo3) and [rust-cpython](https://github.com/dgrunwald/rust-cpython).
89

9-
Compile and distribute Python extensions written in rust as easily as if
10+
Compile and distribute Python extensions written in Rust as easily as if
1011
they were written in C.
1112

1213
## Setup
@@ -32,6 +33,9 @@ setup(
3233
)
3334
```
3435

36+
For a complete reference of the options supported by the `RustExtension` class, see the
37+
[API reference](https://setuptools-rust.readthedocs.io/en/latest/reference.html).
38+
3539
### MANIFEST.in
3640

3741
This file is required for building source distributions
@@ -129,107 +133,6 @@ You can then upload the `manylinux2014` wheels to pypi using [twine](https://git
129133

130134
It is possible to use any of the `manylinux` docker images: `manylinux1`, `manylinux2010` or `manylinux2014`. (Just replace `manylinux2014` in the above instructions with the alternative version you wish to use.)
131135

132-
## RustExtension
133-
134-
You can define rust extension with RustExtension class:
135-
136-
```python
137-
RustExtension(
138-
name,
139-
path="Cargo.toml",
140-
args=None,
141-
features=None,
142-
rustc_flags=None,
143-
rust_version=None,
144-
quiet=False,
145-
debug=None,
146-
binding=Binding.PyO3,
147-
strip=Strip.No,
148-
script=False,
149-
native=False,
150-
optional=False,
151-
py_limited_api=False,
152-
)
153-
```
154-
155-
The class for creating rust extensions.
156-
157-
- param str `name`
158-
159-
the full name of the extension, including any packages -- ie.
160-
*not* a filename or pathname, but Python dotted name. It is
161-
possible to specify multiple binaries, if extension uses
162-
Binsing.Exec binding mode. In that case first argument has to be
163-
dictionary. Keys of the dictionary corresponds to compiled rust
164-
binaries and values are full name of the executable inside python
165-
package.
166-
167-
- param str `path`
168-
169-
path to the Cargo.toml manifest file
170-
171-
- param \[str\] `args`
172-
173-
a list of extra argumenents to be passed to cargo.
174-
175-
- param \[str\] `features`
176-
177-
a list of features to also build
178-
179-
- param \[str\] `rustc_flags`
180-
181-
A list of arguments to pass to rustc, e.g. cargo rustc --features
182-
\<features\> \<args\> -- \<rustc\_flags\>
183-
184-
- param str `rust_version`
185-
186-
sematic version of rust compiler version -- for example
187-
*\>1.14,\<1.16*, default is None
188-
189-
- param bool `quiet`
190-
191-
Does not echo cargo's output. default is `False`
192-
193-
- param bool `debug`
194-
195-
Controls whether `--debug` or `--release` is passed to cargo. If set
196-
to None then build type is auto-detect. Inplace build is debug
197-
build otherwise release. Default: `None`
198-
199-
- param int `binding`
200-
201-
Controls which python binding is in use.
202-
* `Binding.PyO3` uses PyO3
203-
* `Binding.RustCPython` uses rust-cpython
204-
* `Binding.NoBinding` uses no binding.
205-
* `Binding.Exec` build executable.
206-
207-
- param int `strip`
208-
209-
Strip symbols from final file. Does nothing for debug build.
210-
* `Strip.No` - do not strip symbols (default)
211-
* `Strip.Debug` - strip debug symbols
212-
* `Strip.All` - strip all symbols
213-
214-
- param bool `script`
215-
216-
Generate console script for executable if `Binding.Exec` is used.
217-
218-
- param bool `native`
219-
220-
Build extension or executable with "-C target-cpu=native"
221-
222-
- param bool `optional`
223-
224-
if it is true, a build failure in the extension will not abort the
225-
build process, but instead simply not install the failing
226-
extension.
227-
- param bool `py_limited_api`
228-
229-
Same as `py_limited_api` on `setuptools.Extension`. Note that if you
230-
set this to True, your extension must pass the appropriate feature
231-
flags to pyo3 (ensuring that `abi3` feature is enabled).
232-
233136
## Commands
234137

235138
- build - Standard build command builds all rust extensions.
@@ -240,5 +143,5 @@ The class for creating rust extensions.
240143
extensions.
241144
- tomlgen\_rust - Automatically generate a Cargo.toml manifest based
242145
on Python package metadata. See the [example
243-
project](https://github.com/PyO3/setuptools-rust/tree/master/example_tomlgen)
146+
project](https://github.com/PyO3/setuptools-rust/tree/master/examples/tomlgen)
244147
on GitHub for more information about this command.

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/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. mdinclude:: ../README.md

docs/conf.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
13+
# -- Project information -----------------------------------------------------
14+
15+
project = 'setuptools-rust'
16+
copyright = '2021, The PyO3 Contributors'
17+
author = 'The PyO3 Contributors'
18+
19+
20+
# -- General configuration ---------------------------------------------------
21+
22+
# Add any Sphinx extension module names here, as strings. They can be
23+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
24+
# ones.
25+
extensions = [
26+
"sphinx.ext.autodoc",
27+
"sphinx.ext.napoleon",
28+
"sphinx_autodoc_typehints",
29+
"sphinx_rtd_theme",
30+
"m2r2",
31+
]
32+
33+
# Add any paths that contain templates here, relative to this directory.
34+
templates_path = ['_templates']
35+
36+
# List of patterns, relative to source directory, that match files and
37+
# directories to ignore when looking for source files.
38+
# This pattern also affects html_static_path and html_extra_path.
39+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
40+
41+
42+
# -- Options for HTML output -------------------------------------------------
43+
44+
# The theme to use for HTML and HTML Help pages. See the documentation for
45+
# a list of builtin themes.
46+
#
47+
html_theme = 'sphinx_rtd_theme'
48+
49+
# Add any paths that contain custom static files (such as style sheets) here,
50+
# relative to this directory. They are copied after the builtin static files,
51+
# so a file named "default.css" will overwrite the builtin "default.css".
52+
html_static_path = ['_static']
53+
54+
html_theme_options = {
55+
'prev_next_buttons_location': None,
56+
}
57+
58+
# -- Custom HTML link transformation to make documentation links relative --
59+
60+
# This is necessary because the README.md (for example) has links to the latest
61+
# documentation, but we want them to be relative to the specific docs version.
62+
63+
from sphinx.transforms import SphinxTransform
64+
65+
DOCS_URL = 'https://setuptools-rust.readthedocs.io/en/latest/'
66+
67+
class RelativeDocLinks(SphinxTransform):
68+
69+
default_priority = 750
70+
71+
def apply(self):
72+
from docutils.nodes import reference, Text
73+
baseref = lambda o: (
74+
isinstance(o, reference) and
75+
o.get('refuri', '').startswith(DOCS_URL))
76+
basetext = lambda o: (
77+
isinstance(o, Text) and o.startswith(DOCS_URL))
78+
for node in self.document.traverse(baseref):
79+
target = node['refuri'].replace(DOCS_URL, "", 1)
80+
node.replace_attr('refuri', target)
81+
for t in node.traverse(basetext):
82+
t1 = Text(t.replace(DOCS_URL, "", 1), t.rawsource)
83+
t.parent.replace(t, t1)
84+
return
85+
86+
# end of class
87+
88+
def setup(app):
89+
app.add_transform(RelativeDocLinks)
90+
return

docs/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. toctree::
2+
:maxdepth: 2
3+
:hidden:
4+
5+
README
6+
reference
7+
8+
.. include:: README.rst

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+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
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/reference.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
API Reference
2+
=============
3+
4+
.. py:module:: setuptools_rust
5+
6+
.. autoclass:: RustExtension
7+
.. autoclass:: Binding
8+
.. autoclass:: Strip

docs/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
m2r2==0.2.7
2+
Sphinx==3.5.2
3+
sphinx-autodoc-typehints==1.11.1
4+
sphinx-rtd-theme==0.5.1

0 commit comments

Comments
 (0)