Skip to content

Commit 613a70b

Browse files
committed
docs: use versioned links from docs to guide (#4331)
* use versioned links from docs to guide * use standard python version in `guide-build` ci job
1 parent b50f1c3 commit 613a70b

File tree

12 files changed

+51
-37
lines changed

12 files changed

+51
-37
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
tag_name: ${{ steps.prepare_tag.outputs.tag_name }}
2323
steps:
2424
- uses: actions/checkout@v4
25-
25+
- uses: actions/setup-python@v5
2626
- uses: dtolnay/rust-toolchain@nightly
2727

2828
- name: Setup mdBook

guide/src/building-and-distribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn main() {
163163

164164
For more discussion on and workarounds for MacOS linking problems [see this issue](https://github.com/PyO3/pyo3/issues/1800#issuecomment-906786649).
165165

166-
Finally, don't forget that on MacOS the `extension-module` feature will cause `cargo test` to fail without the `--no-default-features` flag (see [the FAQ](https://pyo3.rs/main/faq.html#i-cant-run-cargo-test-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror)).
166+
Finally, don't forget that on MacOS the `extension-module` feature will cause `cargo test` to fail without the `--no-default-features` flag (see [the FAQ](https://pyo3.rs/main/faq.html#i-cant-run-cargo-test-or-i-cant-build-in-a-cargo-workspace-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror)).
167167

168168
### The `extension-module` feature
169169

noxfile.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,17 @@ def check_guide(session: nox.Session):
394394
docs(session)
395395
session.posargs.extend(posargs)
396396

397+
if toml is None:
398+
session.error("requires Python 3.11 or `toml` to be installed")
399+
pyo3_version = toml.loads((PYO3_DIR / "Cargo.toml").read_text())["package"][
400+
"version"
401+
]
402+
397403
remaps = {
398404
f"file://{PYO3_GUIDE_SRC}/([^/]*/)*?%7B%7B#PYO3_DOCS_URL}}}}": f"file://{PYO3_DOCS_TARGET}",
405+
f"https://pyo3.rs/v{pyo3_version}": f"file://{PYO3_GUIDE_TARGET}",
406+
"https://pyo3.rs/main/": f"file://{PYO3_GUIDE_TARGET}/",
407+
"https://pyo3.rs/latest/": f"file://{PYO3_GUIDE_TARGET}/",
399408
"%7B%7B#PYO3_DOCS_VERSION}}": "latest",
400409
}
401410
remap_args = []
@@ -416,8 +425,7 @@ def check_guide(session: nox.Session):
416425
session,
417426
"lychee",
418427
str(PYO3_DOCS_TARGET),
419-
f"--remap=https://pyo3.rs/main/ file://{PYO3_GUIDE_TARGET}/",
420-
f"--remap=https://pyo3.rs/latest/ file://{PYO3_GUIDE_TARGET}/",
428+
*remap_args,
421429
f"--exclude=file://{PYO3_DOCS_TARGET}",
422430
"--exclude=http://www.adobe.com/",
423431
*session.posargs,

pyo3-build-config/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use target_lexicon::OperatingSystem;
3939
/// | `#[cfg(PyPy)]` | This marks code which is run when compiling for PyPy. |
4040
/// | `#[cfg(GraalPy)]` | This marks code which is run when compiling for GraalPy. |
4141
///
42-
/// For examples of how to use these attributes, [see PyO3's guide](https://pyo3.rs/latest/building-and-distribution/multiple_python_versions.html).
42+
/// For examples of how to use these attributes,
43+
#[doc = concat!("[see PyO3's guide](https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/building-and-distribution/multiple_python_versions.html)")]
44+
/// .
4345
#[cfg(feature = "resolve-config")]
4446
pub fn use_pyo3_cfgs() {
4547
print_expected_cfgs();

pyo3-ffi/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@
221221
//! [`maturin`]: https://github.com/PyO3/maturin "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
222222
//! [`pyo3-build-config`]: https://docs.rs/pyo3-build-config
223223
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/features.html "Features - The Cargo Book"
224-
//! [manual_builds]: https://pyo3.rs/latest/building-and-distribution.html#manual-builds "Manual builds - Building and Distribution - PyO3 user guide"
224+
#![doc = concat!("[manual_builds]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/building-and-distribution.html#manual-builds \"Manual builds - Building and Distribution - PyO3 user guide\"")]
225225
//! [setuptools-rust]: https://github.com/PyO3/setuptools-rust "Setuptools plugin for Rust extensions"
226226
//! [PEP 384]: https://www.python.org/dev/peps/pep-0384 "PEP 384 -- Defining a Stable ABI"
227-
//! [Features chapter of the guide]: https://pyo3.rs/latest/features.html#features-reference "Features Reference - PyO3 user guide"
228-
227+
#![doc = concat!("[Features chapter of the guide]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/features.html#features-reference \"Features Reference - PyO3 user guide\"")]
229228
#![allow(
230229
missing_docs,
231230
non_camel_case_types,

pyo3-macros-backend/src/pyclass.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,19 @@ pub fn build_py_class(
232232

233233
if let Some(lt) = class.generics.lifetimes().next() {
234234
bail_spanned!(
235-
lt.span() =>
236-
"#[pyclass] cannot have lifetime parameters. \
237-
For an explanation, see https://pyo3.rs/latest/class.html#no-lifetime-parameters"
235+
lt.span() => concat!(
236+
"#[pyclass] cannot have lifetime parameters. For an explanation, see \
237+
https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#no-lifetime-parameters"
238+
)
238239
);
239240
}
240241

241242
ensure_spanned!(
242243
class.generics.params.is_empty(),
243-
class.generics.span() =>
244-
"#[pyclass] cannot have generic parameters. \
245-
For an explanation, see https://pyo3.rs/latest/class.html#no-generic-parameters"
244+
class.generics.span() => concat!(
245+
"#[pyclass] cannot have generic parameters. For an explanation, see \
246+
https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#no-generic-parameters"
247+
)
246248
);
247249

248250
let mut field_options: Vec<(&syn::Field, FieldPyO3Options)> = match &mut class.fields {

pyo3-macros/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syn::{parse::Nothing, parse_macro_input, Item};
3232
/// `#[pymodule]` implementation generates a hidden module with the same name containing
3333
/// metadata about the module, which is used by `wrap_pymodule!`).
3434
///
35-
/// [1]: https://pyo3.rs/latest/module.html
35+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/module.html")]
3636
#[proc_macro_attribute]
3737
pub fn pymodule(args: TokenStream, input: TokenStream) -> TokenStream {
3838
match parse_macro_input!(input as Item) {
@@ -99,17 +99,17 @@ pub fn pyclass(attr: TokenStream, input: TokenStream) -> TokenStream {
9999
/// multiple `#[pymethods]` blocks for a single `#[pyclass]`.
100100
/// This will add a transitive dependency on the [`inventory`][3] crate.
101101
///
102-
/// [1]: https://pyo3.rs/latest/class.html#instance-methods
103-
/// [2]: https://pyo3.rs/latest/features.html#multiple-pymethods
102+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#instance-methods")]
103+
#[doc = concat!("[2]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/features.html#multiple-pymethods")]
104104
/// [3]: https://docs.rs/inventory/
105-
/// [4]: https://pyo3.rs/latest/class.html#constructor
106-
/// [5]: https://pyo3.rs/latest/class.html#object-properties-using-getter-and-setter
107-
/// [6]: https://pyo3.rs/latest/class.html#static-methods
108-
/// [7]: https://pyo3.rs/latest/class.html#class-methods
109-
/// [8]: https://pyo3.rs/latest/class.html#callable-objects
110-
/// [9]: https://pyo3.rs/latest/class.html#class-attributes
111-
/// [10]: https://pyo3.rs/latest/class.html#method-arguments
112-
/// [11]: https://pyo3.rs/latest/class.html#object-properties-using-pyo3get-set
105+
#[doc = concat!("[4]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#constructor")]
106+
#[doc = concat!("[5]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#object-properties-using-getter-and-setter")]
107+
#[doc = concat!("[6]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#static-methods")]
108+
#[doc = concat!("[7]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#class-methods")]
109+
#[doc = concat!("[8]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#callable-objects")]
110+
#[doc = concat!("[9]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#class-attributes")]
111+
#[doc = concat!("[10]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#method-arguments")]
112+
#[doc = concat!("[11]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#object-properties-using-pyo3get-set")]
113113
#[proc_macro_attribute]
114114
pub fn pymethods(attr: TokenStream, input: TokenStream) -> TokenStream {
115115
let methods_type = if cfg!(feature = "multiple-pymethods") {
@@ -138,7 +138,7 @@ pub fn pymethods(attr: TokenStream, input: TokenStream) -> TokenStream {
138138
/// `#[pyfunction]` implementation generates a hidden module with the same name containing
139139
/// metadata about the function, which is used by `wrap_pyfunction!`).
140140
///
141-
/// [1]: https://pyo3.rs/latest/function.html
141+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/function.html")]
142142
#[proc_macro_attribute]
143143
pub fn pyfunction(attr: TokenStream, input: TokenStream) -> TokenStream {
144144
let mut ast = parse_macro_input!(input as syn::ItemFn);

src/instance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ impl<T> IntoPy<PyObject> for Borrowed<'_, '_, T> {
744744
/// - [`Py::borrow`], [`Py::try_borrow`], [`Py::borrow_mut`], or [`Py::try_borrow_mut`],
745745
///
746746
/// to get a (mutable) reference to a contained pyclass, using a scheme similar to std's [`RefCell`].
747-
/// See the [guide entry](https://pyo3.rs/latest/class.html#bound-and-interior-mutability)
747+
/// See the
748+
#[doc = concat!("[guide entry](https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#bound-and-interior-mutability)")]
748749
/// for more information.
749750
/// - You can call methods directly on `Py` with [`Py::call_bound`], [`Py::call_method_bound`] and friends.
750751
///

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,25 @@
295295
//! [`rust_decimal`]: ./rust_decimal/index.html "Documenation about the `rust_decimal` feature."
296296
//! [`Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
297297
//! [`serde`]: <./serde/index.html> "Documentation about the `serde` feature."
298-
//! [calling_rust]: https://pyo3.rs/latest/python-from-rust.html "Calling Python from Rust - PyO3 user guide"
298+
#![doc = concat!("[calling_rust]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/python-from-rust.html \"Calling Python from Rust - PyO3 user guide\"")]
299299
//! [examples subdirectory]: https://github.com/PyO3/pyo3/tree/main/examples
300300
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/features.html "Features - The Cargo Book"
301301
//! [global interpreter lock]: https://docs.python.org/3/glossary.html#term-global-interpreter-lock
302302
//! [hashbrown]: https://docs.rs/hashbrown
303303
//! [smallvec]: https://docs.rs/smallvec
304304
//! [indexmap]: https://docs.rs/indexmap
305-
//! [manual_builds]: https://pyo3.rs/latest/building-and-distribution.html#manual-builds "Manual builds - Building and Distribution - PyO3 user guide"
305+
#![doc = concat!("[manual_builds]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/building-and-distribution.html#manual-builds \"Manual builds - Building and Distribution - PyO3 user guide\"")]
306306
//! [num-bigint]: https://docs.rs/num-bigint
307307
//! [num-complex]: https://docs.rs/num-complex
308308
//! [num-rational]: https://docs.rs/num-rational
309309
//! [serde]: https://docs.rs/serde
310310
//! [setuptools-rust]: https://github.com/PyO3/setuptools-rust "Setuptools plugin for Rust extensions"
311311
//! [the guide]: https://pyo3.rs "PyO3 user guide"
312-
//! [types]: https://pyo3.rs/latest/types.html "GIL lifetimes, mutability and Python object types"
312+
#![doc = concat!("[types]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/types.html \"GIL lifetimes, mutability and Python object types\"")]
313313
//! [PEP 384]: https://www.python.org/dev/peps/pep-0384 "PEP 384 -- Defining a Stable ABI"
314314
//! [Python from Rust]: https://github.com/PyO3/pyo3#using-python-from-rust
315315
//! [Rust from Python]: https://github.com/PyO3/pyo3#using-rust-from-python
316-
//! [Features chapter of the guide]: https://pyo3.rs/latest/features.html#features-reference "Features Reference - PyO3 user guide"
316+
#![doc = concat!("[Features chapter of the guide]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/features.html#features-reference \"Features Reference - PyO3 user guide\"")]
317317
//! [`Ungil`]: crate::marker::Ungil
318318
pub use crate::class::*;
319319
pub use crate::conversion::{AsPyPointer, FromPyObject, IntoPy, ToPyObject};
@@ -483,7 +483,7 @@ pub use pyo3_macros::{pyfunction, pymethods, pymodule, FromPyObject};
483483
/// For more on creating Python classes,
484484
/// see the [class section of the guide][1].
485485
///
486-
/// [1]: https://pyo3.rs/latest/class.html
486+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html")]
487487
#[cfg(feature = "macros")]
488488
pub use pyo3_macros::pyclass;
489489

src/sync.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ unsafe impl<T> Sync for GILProtected<T> where T: Send {}
5959
/// Unlike `once_cell::sync` which blocks threads to achieve thread safety, this implementation
6060
/// uses the Python GIL to mediate concurrent access. This helps in cases where `once_cell` or
6161
/// `lazy_static`'s synchronization strategy can lead to deadlocks when interacting with the Python
62-
/// GIL. For an example, see [the FAQ section](https://pyo3.rs/latest/faq.html) of the guide.
62+
/// GIL. For an example, see
63+
#[doc = concat!("[the FAQ section](https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/faq.html)")]
64+
/// of the guide.
6365
///
6466
/// Note that:
6567
/// 1) `get_or_init` and `get_or_try_init` do not protect against infinite recursion

src/types/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl PyModule {
304304
/// make an *instance* of `Foo` (or *get* one for that matter, as we haven't exported
305305
/// anything that can return instances of `Foo`).
306306
///
307-
/// [1]: https://pyo3.rs/latest/class.html#constructor
307+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#constructor")]
308308
pub fn add_class<T>(&self) -> PyResult<()>
309309
where
310310
T: PyClass,
@@ -509,7 +509,7 @@ pub trait PyModuleMethods<'py>: crate::sealed::Sealed {
509509
/// make an *instance* of `Foo` (or *get* one for that matter, as we haven't exported
510510
/// anything that can return instances of `Foo`).
511511
///
512-
/// [1]: https://pyo3.rs/latest/class.html#constructor
512+
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#constructor")]
513513
fn add_class<T>(&self) -> PyResult<()>
514514
where
515515
T: PyClass;

tests/ui/reject_generics.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/latest/class.html#no-generic-parameters
1+
error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.23.0-dev/class.html#no-generic-parameters
22
--> tests/ui/reject_generics.rs:4:25
33
|
44
4 | struct ClassWithGenerics<A> {
55
| ^
66

7-
error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/latest/class.html#no-lifetime-parameters
7+
error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.23.0-dev/class.html#no-lifetime-parameters
88
--> tests/ui/reject_generics.rs:9:27
99
|
1010
9 | struct ClassWithLifetimes<'a> {

0 commit comments

Comments
 (0)