Vendor deps.
This commit is contained in:
1 parent
294527085e
commit
91e18fde3a
1714 files changed
+556667
-7
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
{"files":{".cargo_vcs_info.json":"696fe0b053bf3321d15410a79502e6b87134c77e51b00e6dc1fa75d7eaaf81a6","Cargo.lock":"383ac7c520f89d6f85b15d5adb66a5020c382c38a9ca9930b6641fe8d6ca2b68","Cargo.toml":"246dd2bad7ef1a5c56bf79c89ee9844115cc79fdbe659e647e38d30d7535ac10","Cargo.toml.orig":"d8c5002ae0de060115be9dc71af01f21affaab37db7cd84a96021369667583de","LICENSE-APACHE":"32c76dbe0e73d79100d5ece77c158399f2e2541bc5c78548a4ba45c1cb53c5c9","LICENSE-MIT":"afcbe3b2e6b37172b5a9ca869ee4c0b8cdc09316e5d4384864154482c33e5af6","src/lib.rs":"25d7af1ae4bf8cb5fbf13f92adcc4c0f1ffa4de64e9b731e5d7a58b0f2eb9278"},"package":"73225868fc1cd84eef2c3c230ddb91273bf1de46aeb8a4248da76d32a0924a1c"}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "a70d17f898df41b3d1632ee987f624f5222d8d39"
|
||||
},
|
||||
"path_in_vcs": "pyo3-macros"
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-macros"
|
||||
version = "0.29.2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"pyo3-macros-backend",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-macros-backend"
|
||||
version = "0.29.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "571575aa3749fa6216757dd47d2a3e7ef360f329a40f0666a9fbd14889024952"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
Vendored
+106
@@ -0,0 +1,106 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
rust-version = "1.83"
|
||||
name = "pyo3-macros"
|
||||
version = "0.29.2"
|
||||
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"]
|
||||
build = false
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = "Proc macros for PyO3 package"
|
||||
homepage = "https://github.com/pyo3/pyo3"
|
||||
readme = false
|
||||
keywords = [
|
||||
"pyo3",
|
||||
"python",
|
||||
"cpython",
|
||||
"ffi",
|
||||
]
|
||||
categories = [
|
||||
"api-bindings",
|
||||
"development-tools::ffi",
|
||||
]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/pyo3/pyo3"
|
||||
|
||||
[features]
|
||||
experimental-async = ["pyo3-macros-backend/experimental-async"]
|
||||
experimental-inspect = ["pyo3-macros-backend/experimental-inspect"]
|
||||
multiple-pymethods = []
|
||||
|
||||
[lib]
|
||||
name = "pyo3_macros"
|
||||
path = "src/lib.rs"
|
||||
proc-macro = true
|
||||
|
||||
[dependencies.proc-macro2]
|
||||
version = "1.0.60"
|
||||
default-features = false
|
||||
|
||||
[dependencies.pyo3-macros-backend]
|
||||
version = "=0.29.2"
|
||||
|
||||
[dependencies.quote]
|
||||
version = "1"
|
||||
|
||||
[dependencies.syn]
|
||||
version = "2"
|
||||
features = [
|
||||
"full",
|
||||
"extra-traits",
|
||||
]
|
||||
|
||||
[lints.clippy]
|
||||
checked_conversions = "warn"
|
||||
dbg_macro = "warn"
|
||||
explicit_into_iter_loop = "warn"
|
||||
explicit_iter_loop = "warn"
|
||||
filter_map_next = "warn"
|
||||
flat_map_option = "warn"
|
||||
let_unit_value = "warn"
|
||||
manual_assert = "warn"
|
||||
manual_ok_or = "warn"
|
||||
todo = "warn"
|
||||
undocumented_unsafe_blocks = "warn"
|
||||
unnecessary_wraps = "warn"
|
||||
used_underscore_binding = "warn"
|
||||
useless_transmute = "warn"
|
||||
|
||||
[lints.rust]
|
||||
elided_lifetimes_in_paths = "warn"
|
||||
invalid_doc_attributes = "warn"
|
||||
rust_2021_prelude_collisions = "warn"
|
||||
unsafe_op_in_unsafe_fn = "warn"
|
||||
unused_lifetimes = "warn"
|
||||
|
||||
[lints.rust.rust_2018_idioms]
|
||||
level = "warn"
|
||||
priority = -1
|
||||
|
||||
[lints.rust.unexpected_cfgs]
|
||||
level = "warn"
|
||||
priority = 0
|
||||
check-cfg = [
|
||||
"cfg(pyo3_disable_reference_pool)",
|
||||
"cfg(pyo3_leak_on_drop_without_reference_pool)",
|
||||
"cfg(pyo3_use_raw_dylib)",
|
||||
'cfg(pyo3_dll, values("python3", "python3_d", "python3t", "python3t_d", "python38", "python38_d", "python39", "python39_d", "python310", "python310_d", "python311", "python311_d", "python312", "python312_d", "python313", "python313_d", "python313t", "python313t_d", "python314", "python314_d", "python314t", "python314t_d", "python315", "python315_d", "python315t", "python315t_d", "python316", "python316_d", "python316t", "python316t_d", "libpypy3.11-c"))',
|
||||
]
|
||||
|
||||
[lints.rustdoc]
|
||||
bare_urls = "warn"
|
||||
broken_intra_doc_links = "warn"
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "pyo3-macros"
|
||||
version = "0.29.2"
|
||||
description = "Proc macros for PyO3 package"
|
||||
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"]
|
||||
keywords = ["pyo3", "python", "cpython", "ffi"]
|
||||
homepage = "https://github.com/pyo3/pyo3"
|
||||
repository = "https://github.com/pyo3/pyo3"
|
||||
categories = ["api-bindings", "development-tools::ffi"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
rust-version.workspace = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
multiple-pymethods = []
|
||||
experimental-async = ["pyo3-macros-backend/experimental-async"]
|
||||
experimental-inspect = ["pyo3-macros-backend/experimental-inspect"]
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = { version = "1.0.60", default-features = false }
|
||||
quote = "1"
|
||||
syn = { version = "2", features = ["full", "extra-traits"] }
|
||||
pyo3-macros-backend = { path = "../pyo3-macros-backend", version = "=0.29.2" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
Vendored
+178
@@ -0,0 +1,178 @@
|
||||
Copyright (c) 2017-present PyO3 Project and Contributors. https://github.com/PyO3
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2023-present PyO3 Project and Contributors. https://github.com/PyO3
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+257
@@ -0,0 +1,257 @@
|
||||
//! This crate declares only the proc macro attributes, as a crate defining proc macro attributes
|
||||
//! must not contain any other public items.
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use pyo3_macros_backend::{
|
||||
build_derive_from_pyobject, build_derive_into_pyobject, build_py_class, build_py_enum,
|
||||
build_py_function, build_py_methods, pymodule_function_impl, pymodule_module_impl, PyClassArgs,
|
||||
PyClassMethodsType, PyFunctionOptions, PyModuleOptions,
|
||||
};
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, Item};
|
||||
|
||||
/// A proc macro used to implement Python modules.
|
||||
///
|
||||
/// The name of the module will be taken from the module name, unless `#[pyo3(name = "my_name")]`
|
||||
/// is also annotated on the module to override the name. **Important**: the module name should
|
||||
/// match the `lib.name` setting in `Cargo.toml`, so that Python is able to import the module
|
||||
/// without needing a custom import loader.
|
||||
///
|
||||
/// Modules annotated with `#[pymodule]` can also be annotated with the following:
|
||||
///
|
||||
/// | Annotation | Description |
|
||||
/// | :- | :- |
|
||||
/// | `#[pyo3(name = "...")]` | Defines the name of the module in Python. |
|
||||
/// | `#[pyo3(submodule)]` | Skips adding a `PyInit_` FFI symbol to the compiled binary. |
|
||||
/// | `#[pyo3(module = "...")]` | Defines the Python `dotted.path` to the parent module for use in introspection. |
|
||||
/// | `#[pyo3(crate = "pyo3")]` | Defines the path to PyO3 to use code generated by the macro. |
|
||||
/// | `#[pyo3(gil_used = true)]` | Declares the GIL is needed to run this module safely under free-threaded Python. |
|
||||
///
|
||||
/// For more on creating Python modules see the [module section of the guide][1].
|
||||
///
|
||||
/// It is also possible to use this macro on functions but this is a deprecated usage. In this case,
|
||||
/// due to technical limitations on how `#[pymodule]` is implemented, a function marked
|
||||
/// `#[pymodule]` cannot have a module with the same name in the same scope. (The
|
||||
/// `#[pymodule]` implementation generates a hidden module with the same name containing
|
||||
/// metadata about the module, which is used by `wrap_pymodule!`).
|
||||
///
|
||||
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/module.html")]
|
||||
#[proc_macro_attribute]
|
||||
pub fn pymodule(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let options = parse_macro_input!(args as PyModuleOptions);
|
||||
|
||||
let mut ast = parse_macro_input!(input as Item);
|
||||
let expanded = match &mut ast {
|
||||
Item::Mod(module) => {
|
||||
match pymodule_module_impl(module, options) {
|
||||
// #[pymodule] on a module will rebuild the original ast, so we don't emit it here
|
||||
Ok(expanded) => return expanded.into(),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
Item::Fn(function) => pymodule_function_impl(function, options),
|
||||
unsupported => Err(syn::Error::new_spanned(
|
||||
unsupported,
|
||||
"#[pymodule] only supports modules and functions.",
|
||||
)),
|
||||
}
|
||||
.unwrap_or_compile_error();
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn pyclass(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let item = parse_macro_input!(input as Item);
|
||||
match item {
|
||||
Item::Struct(struct_) => pyclass_impl(attr, struct_, methods_type()),
|
||||
Item::Enum(enum_) => pyclass_enum_impl(attr, enum_, methods_type()),
|
||||
unsupported => {
|
||||
syn::Error::new_spanned(unsupported, "#[pyclass] only supports structs and enums.")
|
||||
.into_compile_error()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A proc macro used to expose methods to Python.
|
||||
///
|
||||
/// Methods within a `#[pymethods]` block can be annotated with as well as the following:
|
||||
///
|
||||
/// | Annotation | Description |
|
||||
/// | :- | :- |
|
||||
/// | [`#[new]`][4] | Defines the class constructor, like Python's `__new__` method. |
|
||||
/// | [`#[getter]`][5] and [`#[setter]`][5] | These define getters and setters, similar to Python's `@property` decorator. This is useful for getters/setters that require computation or side effects; if that is not the case consider using [`#[pyo3(get, set)]`][12] on the struct's field(s).|
|
||||
/// | [`#[staticmethod]`][6]| Defines the method as a staticmethod, like Python's `@staticmethod` decorator.|
|
||||
/// | [`#[classmethod]`][7] | Defines the method as a classmethod, like Python's `@classmethod` decorator.|
|
||||
/// | [`#[classattr]`][9] | Defines a class variable. |
|
||||
/// | [`#[args]`][10] | Deprecated way to define a method's default arguments and allows the function to receive `*args` and `**kwargs`. Use `#[pyo3(signature = (...))]` instead. |
|
||||
/// | <nobr>[`#[pyo3(<option> = <value>)`][11]</nobr> | Any of the `#[pyo3]` options supported on [`macro@pyfunction`]. |
|
||||
///
|
||||
/// For more on creating class methods,
|
||||
/// see the [class section of the guide][1].
|
||||
///
|
||||
/// If the [`multiple-pymethods`][2] feature is enabled, it is possible to implement
|
||||
/// multiple `#[pymethods]` blocks for a single `#[pyclass]`.
|
||||
/// This will add a transitive dependency on the [`inventory`][3] crate.
|
||||
///
|
||||
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#instance-methods")]
|
||||
#[doc = concat!("[2]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/features.html#multiple-pymethods")]
|
||||
/// [3]: https://docs.rs/inventory/
|
||||
#[doc = concat!("[4]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#constructor")]
|
||||
#[doc = concat!("[5]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#object-properties-using-getter-and-setter")]
|
||||
#[doc = concat!("[6]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#static-methods")]
|
||||
#[doc = concat!("[7]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#class-methods")]
|
||||
#[doc = concat!("[8]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#callable-objects")]
|
||||
#[doc = concat!("[9]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#class-attributes")]
|
||||
#[doc = concat!("[10]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#method-arguments")]
|
||||
#[doc = concat!("[11]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/function.html#function-options")]
|
||||
#[doc = concat!("[12]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#object-properties-using-pyo3get-set")]
|
||||
#[proc_macro_attribute]
|
||||
pub fn pymethods(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let methods_type = if cfg!(feature = "multiple-pymethods") {
|
||||
PyClassMethodsType::Inventory
|
||||
} else {
|
||||
PyClassMethodsType::Specialization
|
||||
};
|
||||
pymethods_impl(attr, input, methods_type)
|
||||
}
|
||||
|
||||
/// A proc macro used to expose Rust functions to Python.
|
||||
///
|
||||
/// Functions annotated with `#[pyfunction]` can also be annotated with the following `#[pyo3]`
|
||||
/// options:
|
||||
///
|
||||
/// | Annotation | Description |
|
||||
/// | :- | :- |
|
||||
/// | `#[pyo3(name = "...")]` | Defines the name of the function in Python. |
|
||||
/// | `#[pyo3(text_signature = "...")]` | Defines the `__text_signature__` attribute of the function in Python. |
|
||||
/// | `#[pyo3(pass_module)]` | Passes the module containing the function as a `&PyModule` first argument to the function. |
|
||||
/// | `#[pyo3(warn(message = "...", category = ...))]` | Generate warning given a message and a category |
|
||||
///
|
||||
/// For more on exposing functions see the [function section of the guide][1].
|
||||
///
|
||||
/// Due to technical limitations on how `#[pyfunction]` is implemented, a function marked
|
||||
/// `#[pyfunction]` cannot have a module with the same name in the same scope. (The
|
||||
/// `#[pyfunction]` implementation generates a hidden module with the same name containing
|
||||
/// metadata about the function, which is used by `wrap_pyfunction!`).
|
||||
///
|
||||
#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/function.html")]
|
||||
#[proc_macro_attribute]
|
||||
pub fn pyfunction(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as syn::ItemFn);
|
||||
let options = parse_macro_input!(attr as PyFunctionOptions);
|
||||
|
||||
let expanded = build_py_function(&mut ast, options).unwrap_or_compile_error();
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(IntoPyObject, attributes(pyo3))]
|
||||
pub fn derive_into_py_object(item: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(item as syn::DeriveInput);
|
||||
let expanded = build_derive_into_pyobject::<false>(&ast).unwrap_or_compile_error();
|
||||
quote!(
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(IntoPyObjectRef, attributes(pyo3))]
|
||||
pub fn derive_into_py_object_ref(item: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(item as syn::DeriveInput);
|
||||
let expanded =
|
||||
pyo3_macros_backend::build_derive_into_pyobject::<true>(&ast).unwrap_or_compile_error();
|
||||
quote!(
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(FromPyObject, attributes(pyo3))]
|
||||
pub fn derive_from_py_object(item: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(item as syn::DeriveInput);
|
||||
let expanded = build_derive_from_pyobject(&ast).unwrap_or_compile_error();
|
||||
quote!(
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn pyclass_impl(
|
||||
attrs: TokenStream,
|
||||
mut ast: syn::ItemStruct,
|
||||
methods_type: PyClassMethodsType,
|
||||
) -> TokenStream {
|
||||
let args = parse_macro_input!(attrs with PyClassArgs::parse_struct_args);
|
||||
let expanded = build_py_class(&mut ast, args, methods_type).unwrap_or_compile_error();
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn pyclass_enum_impl(
|
||||
attrs: TokenStream,
|
||||
mut ast: syn::ItemEnum,
|
||||
methods_type: PyClassMethodsType,
|
||||
) -> TokenStream {
|
||||
let args = parse_macro_input!(attrs with PyClassArgs::parse_enum_args);
|
||||
let expanded = build_py_enum(&mut ast, args, methods_type).unwrap_or_compile_error();
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn pymethods_impl(
|
||||
attr: TokenStream,
|
||||
input: TokenStream,
|
||||
methods_type: PyClassMethodsType,
|
||||
) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as syn::ItemImpl);
|
||||
// Apply all options as a #[pyo3] attribute on the ItemImpl
|
||||
// e.g. #[pymethods(crate = "crate")] impl Foo { }
|
||||
// -> #[pyo3(crate = "crate")] impl Foo { }
|
||||
let attr: TokenStream2 = attr.into();
|
||||
ast.attrs.push(syn::parse_quote!( #[pyo3(#attr)] ));
|
||||
let expanded = build_py_methods(&mut ast, methods_type).unwrap_or_compile_error();
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn methods_type() -> PyClassMethodsType {
|
||||
if cfg!(feature = "multiple-pymethods") {
|
||||
PyClassMethodsType::Inventory
|
||||
} else {
|
||||
PyClassMethodsType::Specialization
|
||||
}
|
||||
}
|
||||
|
||||
trait UnwrapOrCompileError {
|
||||
fn unwrap_or_compile_error(self) -> TokenStream2;
|
||||
}
|
||||
|
||||
impl UnwrapOrCompileError for syn::Result<TokenStream2> {
|
||||
fn unwrap_or_compile_error(self) -> TokenStream2 {
|
||||
self.unwrap_or_else(|e| e.into_compile_error())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user