Skip to content

Commit dfee347

Browse files
authored
Merge pull request #1590 from mejrs/docsrs
docsrs feature
2 parents 350e7b2 + 136b7d4 commit dfee347

File tree

17 files changed

+50
-10
lines changed

17 files changed

+50
-10
lines changed

.github/workflows/guide.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
78
release:
89
types: [published]
910

@@ -18,6 +19,11 @@ jobs:
1819
steps:
1920
- uses: actions/checkout@v2
2021

22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: nightly
25+
profile: minimal
26+
2127
- name: Setup mdBook
2228
uses: peaceiris/actions-mdbook@v1
2329
with:
@@ -38,11 +44,12 @@ jobs:
3844
# This adds the docs to gh-pages-build/doc
3945
- name: Build the doc
4046
run: |
41-
cargo doc --features="default num-bigint num-complex" --no-deps
47+
cargo +nightly rustdoc --lib --no-default-features --features="macros num-bigint num-complex hashbrown serde multiple-pymethods" -- --cfg docsrs
4248
cp -r target/doc gh-pages-build/doc
4349
echo "<meta http-equiv=refresh content=0;url=pyo3/index.html>" > gh-pages-build/doc/index.html
4450
4551
- name: Deploy
52+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
4653
uses: peaceiris/[email protected]
4754
with:
4855
github_token: ${{ secrets.GITHUB_TOKEN }}

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ members = [
7979
"examples/setuptools-rust-starter",
8080
"examples/word-count"
8181
]
82+
83+
[package.metadata.docs.rs]
84+
no-default-features = true
85+
features = ["macros", "num-bigint", "num-complex", "hashbrown", "serde", "multiple-pymethods"]
86+
rustdoc-args = ["--cfg", "docsrs"]

pyo3-macros-backend/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2017-present PyO3 Project and Contributors
22
//! This crate contains the implementation of the proc macro attributes
33
4+
#![cfg_attr(docsrs, feature(doc_cfg))]
45
#![recursion_limit = "1024"]
56

67
// Listed first so that macros in this module are available in the rest of the crate.

pyo3-macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! This crate declares only the proc macro attributes, as a crate defining proc macro attributes
33
//! must not contain any other public items.
44
5+
#![cfg_attr(docsrs, feature(doc_cfg))]
56
extern crate proc_macro;
67

78
use proc_macro::TokenStream;

src/class/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod macros;
77

88
pub mod basic;
99
#[cfg(not(Py_LIMITED_API))]
10+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
1011
pub mod buffer;
1112
pub mod context;
1213
pub mod descr;
@@ -23,6 +24,7 @@ pub mod sequence;
2324

2425
pub use self::basic::PyObjectProtocol;
2526
#[cfg(not(Py_LIMITED_API))]
27+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
2628
pub use self::buffer::PyBufferProtocol;
2729
pub use self::context::PyContextProtocol;
2830
pub use self::descr::PyDescrProtocol;

src/conversion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ where
108108
T: ToPyObject,
109109
{
110110
#[cfg(feature = "nightly")]
111+
#[cfg_attr(docsrs, doc(cfg(feature = "nightly")))]
111112
default fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
112113
where
113114
F: FnOnce(*mut ffi::PyObject) -> R,
@@ -122,6 +123,7 @@ where
122123
}
123124

124125
#[cfg(feature = "nightly")]
126+
#[cfg_attr(docsrs, doc(cfg(feature = "nightly")))]
125127
impl<T> ToBorrowedObject for T
126128
where
127129
T: ToPyObject + AsPyPointer,
@@ -201,6 +203,7 @@ where
201203
/// }
202204
/// ```
203205
/// Python code will see this as any of the `int`, `string` or `None` objects.
206+
#[cfg_attr(docsrs, doc(alias = "IntoPyCallbackOutput"))]
204207
pub trait IntoPy<T>: Sized {
205208
/// Performs the conversion.
206209
fn into_py(self, py: Python) -> T;

src/gil.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ pub(crate) fn gil_is_acquired() -> bool {
4545
/// If both the Python interpreter and Python threading are already initialized,
4646
/// this function has no effect.
4747
///
48-
/// # Availability
49-
/// This function is not available on PyPy.
50-
///
5148
/// # Panics
5249
/// - If the Python interpreter is initialized but Python threading is not,
5350
/// a panic occurs.
@@ -68,6 +65,7 @@ pub(crate) fn gil_is_acquired() -> bool {
6865
/// }
6966
/// ```
7067
#[cfg(not(PyPy))]
68+
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
7169
#[allow(clippy::clippy::collapsible_if)] // for if cfg!
7270
pub fn prepare_freethreaded_python() {
7371
// Protect against race conditions when Python is not yet initialized and multiple threads
@@ -106,9 +104,6 @@ pub fn prepare_freethreaded_python() {
106104
/// single process, it is not safe to call this function more than once. (Many such modules will not
107105
/// initialize correctly on the second run.)
108106
///
109-
/// # Availability
110-
/// This function is not available on PyPy.
111-
///
112107
/// # Panics
113108
/// - If the Python interpreter is already initalized before calling this function.
114109
///
@@ -132,6 +127,7 @@ pub fn prepare_freethreaded_python() {
132127
/// }
133128
/// ```
134129
#[cfg(not(PyPy))]
130+
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
135131
#[allow(clippy::clippy::collapsible_if)] // for if cfg!
136132
pub unsafe fn with_embedded_python_interpreter<F, R>(f: F) -> R
137133
where

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg_attr(feature = "nightly", feature(specialization))]
2+
#![cfg_attr(docsrs, feature(doc_cfg))]
23
#![allow(clippy::missing_safety_doc)] // FIXME (#698)
34

45
//! Rust bindings to the Python interpreter.
@@ -132,6 +133,7 @@ pub use crate::conversion::{
132133
};
133134
pub use crate::err::{PyDowncastError, PyErr, PyErrArguments, PyResult};
134135
#[cfg(not(PyPy))]
136+
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
135137
pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter};
136138
pub use crate::gil::{GILGuard, GILPool};
137139
pub use crate::instance::{Py, PyNativeType, PyObject};
@@ -159,7 +161,9 @@ mod internal_tricks;
159161

160162
// The CPython stable ABI does not include PyBuffer.
161163
#[cfg(not(Py_LIMITED_API))]
164+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
162165
pub mod buffer;
166+
163167
#[doc(hidden)]
164168
pub mod callback;
165169
pub mod class;
@@ -174,8 +178,11 @@ pub mod ffi;
174178
pub mod freelist;
175179
mod gil;
176180
mod instance;
181+
177182
#[cfg(not(Py_LIMITED_API))]
183+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
178184
pub mod marshal;
185+
179186
pub mod once_cell;
180187
pub mod panic;
181188
pub mod prelude;

src/types/complex.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl PyComplex {
3434
}
3535
/// Returns `|self|`.
3636
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
37+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
3738
pub fn abs(&self) -> c_double {
3839
unsafe {
3940
let val = (*(self.as_ptr() as *mut ffi::PyComplexObject)).cval;
@@ -42,6 +43,7 @@ impl PyComplex {
4243
}
4344
/// Returns `self ** other`
4445
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
46+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
4547
pub fn pow(&self, other: &PyComplex) -> &PyComplex {
4648
unsafe {
4749
self.py()
@@ -63,6 +65,7 @@ unsafe fn complex_operation(
6365
}
6466

6567
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
68+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
6669
impl<'py> Add for &'py PyComplex {
6770
type Output = &'py PyComplex;
6871
fn add(self, other: &'py PyComplex) -> &'py PyComplex {
@@ -74,6 +77,7 @@ impl<'py> Add for &'py PyComplex {
7477
}
7578

7679
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
80+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
7781
impl<'py> Sub for &'py PyComplex {
7882
type Output = &'py PyComplex;
7983
fn sub(self, other: &'py PyComplex) -> &'py PyComplex {
@@ -85,6 +89,7 @@ impl<'py> Sub for &'py PyComplex {
8589
}
8690

8791
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
92+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
8893
impl<'py> Mul for &'py PyComplex {
8994
type Output = &'py PyComplex;
9095
fn mul(self, other: &'py PyComplex) -> &'py PyComplex {
@@ -96,6 +101,7 @@ impl<'py> Mul for &'py PyComplex {
96101
}
97102

98103
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
104+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
99105
impl<'py> Div for &'py PyComplex {
100106
type Output = &'py PyComplex;
101107
fn div(self, other: &'py PyComplex) -> &'py PyComplex {
@@ -107,6 +113,7 @@ impl<'py> Div for &'py PyComplex {
107113
}
108114

109115
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
116+
#[cfg_attr(docsrs, doc(cfg(not(any(Py_LIMITED_API, PyPy)))))]
110117
impl<'py> Neg for &'py PyComplex {
111118
type Output = &'py PyComplex;
112119
fn neg(self) -> &'py PyComplex {
@@ -119,13 +126,14 @@ impl<'py> Neg for &'py PyComplex {
119126
}
120127

121128
#[cfg(feature = "num-complex")]
129+
#[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))]
122130
mod complex_conversion {
123131
use super::*;
124132
use crate::{FromPyObject, PyErr, PyNativeType, PyObject, PyResult, ToPyObject};
125133
use num_complex::Complex;
126134

127135
impl PyComplex {
128-
/// Creates a new Python `PyComplex` object from num_complex::Complex.
136+
/// Creates a new Python `PyComplex` object from `num_complex`'s [`Complex`].
129137
pub fn from_complex<F: Into<c_double>>(py: Python, complex: Complex<F>) -> &PyComplex {
130138
unsafe {
131139
let ptr = ffi::PyComplex_FromDoubles(complex.re.into(), complex.im.into());

src/types/dict.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl PyDict {
3737
/// Returns an error on invalid input. In the case of key collisions,
3838
/// this keeps the last entry seen.
3939
#[cfg(not(PyPy))]
40+
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
4041
pub fn from_sequence(py: Python, seq: PyObject) -> PyResult<&PyDict> {
4142
unsafe {
4243
let dict = py.from_owned_ptr::<PyDict>(ffi::PyDict_New());

src/types/iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<'p> Iterator for &'p PyIterator {
6969

7070
// PyIter_Check does not exist in the limited API until 3.8
7171
#[cfg(any(not(Py_LIMITED_API), Py_3_8))]
72+
#[cfg_attr(docsrs, doc(cfg(any(not(Py_LIMITED_API), Py_3_8))))]
7273
impl<'v> PyTryFrom<'v> for PyIterator {
7374
fn try_from<V: Into<&'v PyAny>>(value: V) -> Result<&'v PyIterator, PyDowncastError<'v>> {
7475
let value = value.into();

src/types/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use self::bytearray::PyByteArray;
88
pub use self::bytes::PyBytes;
99
pub use self::complex::PyComplex;
1010
#[cfg(not(Py_LIMITED_API))]
11+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
1112
pub use self::datetime::{
1213
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTzInfo,
1314
};
@@ -225,6 +226,7 @@ mod bytearray;
225226
mod bytes;
226227
mod complex;
227228
#[cfg(not(Py_LIMITED_API))]
229+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
228230
mod datetime;
229231
mod dict;
230232
mod floatob;

src/types/module.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl PyModule {
112112
///
113113
/// May fail if the module does not have a `__file__` attribute.
114114
#[cfg(not(all(windows, PyPy)))]
115+
#[cfg_attr(docsrs, doc(cfg(not(all(windows, PyPy)))))]
115116
pub fn filename(&self) -> PyResult<&str> {
116117
use crate::types::PyString;
117118
unsafe {

src/types/num.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ mod test_128bit_intergers {
357357
}
358358

359359
#[cfg(all(feature = "num-bigint", not(any(Py_LIMITED_API, PyPy))))]
360+
#[cfg_attr(
361+
docsrs,
362+
doc(cfg(all(feature = "num-bigint", not(any(Py_LIMITED_API, PyPy)))))
363+
)]
360364
mod bigint_conversion {
361365
use super::*;
362366
use crate::{err, Py};

src/types/sequence.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl PySequence {
187187
/// number of keys for which `self[key] == value`.
188188
#[inline]
189189
#[cfg(not(PyPy))]
190+
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
190191
pub fn count<V>(&self, value: V) -> PyResult<usize>
191192
where
192193
V: ToBorrowedObject,

src/types/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<'a> std::iter::IntoIterator for &'a PyFrozenSet {
324324
}
325325

326326
#[cfg(feature = "hashbrown")]
327+
#[cfg_attr(docsrs, doc(cfg(feature = "hashbrown")))]
327328
mod hashbrown_hashset_conversion {
328329
use super::*;
329330
use crate::{FromPyObject, PyObject, PyResult, ToPyObject};

src/types/tuple.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ impl PyTuple {
7878
}
7979

8080
/// Returns `self` as a slice of objects.
81-
///
82-
/// Not available when compiled with Py_LIMITED_API.
8381
#[cfg(not(Py_LIMITED_API))]
82+
#[cfg_attr(docsrs, doc(cfg(not(Py_LIMITED_API))))]
8483
pub fn as_slice(&self) -> &[&PyAny] {
8584
// This is safe because &PyAny has the same memory layout as *mut ffi::PyObject,
8685
// and because tuples are immutable.

0 commit comments

Comments
 (0)