maturin 0.12.19__py3-none-win_amd64.whl → 1.11.4__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- maturin/__init__.py +108 -46
- maturin/__main__.py +50 -0
- maturin/bootstrap.py +31 -0
- {maturin-0.12.19.data → maturin-1.11.4.data}/scripts/maturin.exe +0 -0
- maturin-1.11.4.dist-info/METADATA +303 -0
- maturin-1.11.4.dist-info/RECORD +9 -0
- {maturin-0.12.19.dist-info → maturin-1.11.4.dist-info}/WHEEL +1 -1
- maturin-1.11.4.dist-info/licenses/license-apache +201 -0
- maturin-1.11.4.dist-info/licenses/license-mit +25 -0
- maturin/import_hook.py +0 -152
- maturin-0.12.19.dist-info/METADATA +0 -284
- maturin-0.12.19.dist-info/RECORD +0 -6
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) 2018 konstin
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any
|
|
4
|
+
person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the
|
|
6
|
+
Software without restriction, including without
|
|
7
|
+
limitation the rights to use, copy, modify, merge,
|
|
8
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software
|
|
10
|
+
is furnished to do so, subject to the following
|
|
11
|
+
conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice
|
|
14
|
+
shall be included in all copies or substantial portions
|
|
15
|
+
of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
18
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
20
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
21
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
24
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
maturin/import_hook.py
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import contextlib
|
|
2
|
-
import importlib
|
|
3
|
-
import importlib.util
|
|
4
|
-
from importlib import abc
|
|
5
|
-
from importlib.machinery import ModuleSpec
|
|
6
|
-
import os
|
|
7
|
-
import pathlib
|
|
8
|
-
import shutil
|
|
9
|
-
import sys
|
|
10
|
-
import subprocess
|
|
11
|
-
from typing import Optional
|
|
12
|
-
|
|
13
|
-
try:
|
|
14
|
-
import tomllib
|
|
15
|
-
except ModuleNotFoundError:
|
|
16
|
-
import tomli as tomllib
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class Importer(abc.MetaPathFinder):
|
|
20
|
-
"""A meta-path importer for the maturin based packages"""
|
|
21
|
-
|
|
22
|
-
def __init__(self, bindings: Optional[str] = None, release: bool = False):
|
|
23
|
-
self.bindings = bindings
|
|
24
|
-
self.release = release
|
|
25
|
-
|
|
26
|
-
def find_spec(self, fullname, path, target=None):
|
|
27
|
-
if fullname in sys.modules:
|
|
28
|
-
return
|
|
29
|
-
mod_parts = fullname.split(".")
|
|
30
|
-
module_name = mod_parts[-1]
|
|
31
|
-
|
|
32
|
-
cwd = pathlib.Path(os.getcwd())
|
|
33
|
-
# Full Cargo project in cwd
|
|
34
|
-
cargo_toml = cwd / "Cargo.toml"
|
|
35
|
-
if _is_cargo_project(cargo_toml, module_name):
|
|
36
|
-
return self._build_and_load(fullname, cargo_toml)
|
|
37
|
-
|
|
38
|
-
# Full Cargo project in subdirectory of cwd
|
|
39
|
-
cargo_toml = cwd / module_name / "Cargo.toml"
|
|
40
|
-
if _is_cargo_project(cargo_toml, module_name):
|
|
41
|
-
return self._build_and_load(fullname, cargo_toml)
|
|
42
|
-
# module name with '-' instead of '_'
|
|
43
|
-
cargo_toml = cwd / module_name.replace("_", "-") / "Cargo.toml"
|
|
44
|
-
if _is_cargo_project(cargo_toml, module_name):
|
|
45
|
-
return self._build_and_load(fullname, cargo_toml)
|
|
46
|
-
|
|
47
|
-
# Single .rs file
|
|
48
|
-
rust_file = cwd / (module_name + ".rs")
|
|
49
|
-
if rust_file.exists():
|
|
50
|
-
project_dir = generate_project(rust_file, bindings=self.bindings or "pyo3")
|
|
51
|
-
cargo_toml = project_dir / "Cargo.toml"
|
|
52
|
-
return self._build_and_load(fullname, cargo_toml)
|
|
53
|
-
|
|
54
|
-
def _build_and_load(self, fullname: str, cargo_toml: pathlib.Path) -> ModuleSpec:
|
|
55
|
-
build_module(cargo_toml, bindings=self.bindings)
|
|
56
|
-
loader = Loader(fullname)
|
|
57
|
-
return importlib.util.spec_from_loader(fullname, loader)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class Loader(abc.Loader):
|
|
61
|
-
def __init__(self, fullname):
|
|
62
|
-
self.fullname = fullname
|
|
63
|
-
|
|
64
|
-
def load_module(self, fullname):
|
|
65
|
-
return importlib.import_module(self.fullname)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _is_cargo_project(cargo_toml: pathlib.Path, module_name: str) -> bool:
|
|
69
|
-
with contextlib.suppress(FileNotFoundError):
|
|
70
|
-
with open(cargo_toml, "rb") as f:
|
|
71
|
-
cargo = tomllib.load(f)
|
|
72
|
-
package_name = cargo.get("package", {}).get("name")
|
|
73
|
-
if (
|
|
74
|
-
package_name == module_name
|
|
75
|
-
or package_name.replace("-", "_") == module_name
|
|
76
|
-
):
|
|
77
|
-
return True
|
|
78
|
-
return False
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def generate_project(rust_file: pathlib.Path, bindings: str = "pyo3") -> pathlib.Path:
|
|
82
|
-
build_dir = pathlib.Path(os.getcwd()) / "build"
|
|
83
|
-
project_dir = build_dir / rust_file.stem
|
|
84
|
-
if project_dir.exists():
|
|
85
|
-
shutil.rmtree(project_dir)
|
|
86
|
-
|
|
87
|
-
command = ["maturin", "new", "-b", bindings, project_dir]
|
|
88
|
-
result = subprocess.run(command, stdout=subprocess.PIPE)
|
|
89
|
-
if result.returncode != 0:
|
|
90
|
-
sys.stderr.write(
|
|
91
|
-
f"Error: command {command} returned non-zero exit status {result.returncode}\n"
|
|
92
|
-
)
|
|
93
|
-
raise ImportError("Failed to generate cargo project")
|
|
94
|
-
|
|
95
|
-
with open(rust_file) as f:
|
|
96
|
-
lib_rs_content = f.read()
|
|
97
|
-
lib_rs = project_dir / "src" / "lib.rs"
|
|
98
|
-
with open(lib_rs, "w") as f:
|
|
99
|
-
f.write(lib_rs_content)
|
|
100
|
-
return project_dir
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def build_module(
|
|
104
|
-
manifest_path: pathlib.Path, bindings: Optional[str] = None, release: bool = False
|
|
105
|
-
):
|
|
106
|
-
command = ["maturin", "develop", "-m", manifest_path]
|
|
107
|
-
if bindings:
|
|
108
|
-
command.append("-b")
|
|
109
|
-
command.append(bindings)
|
|
110
|
-
if release:
|
|
111
|
-
command.append("--release")
|
|
112
|
-
result = subprocess.run(command, stdout=subprocess.PIPE)
|
|
113
|
-
sys.stdout.buffer.write(result.stdout)
|
|
114
|
-
sys.stdout.flush()
|
|
115
|
-
if result.returncode != 0:
|
|
116
|
-
sys.stderr.write(
|
|
117
|
-
f"Error: command {command} returned non-zero exit status {result.returncode}\n"
|
|
118
|
-
)
|
|
119
|
-
raise ImportError("Failed to build module with maturin")
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
def _have_importer() -> bool:
|
|
123
|
-
for importer in sys.meta_path:
|
|
124
|
-
if isinstance(importer, Importer):
|
|
125
|
-
return True
|
|
126
|
-
return False
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def install(bindings: Optional[str] = None, release: bool = False):
|
|
130
|
-
"""
|
|
131
|
-
Install the import hook.
|
|
132
|
-
|
|
133
|
-
:param bindings: Which kind of bindings to use.
|
|
134
|
-
Possible values are pyo3, rust-cpython and cffi
|
|
135
|
-
|
|
136
|
-
:param release: Build in release mode, otherwise debug mode by default
|
|
137
|
-
"""
|
|
138
|
-
if _have_importer():
|
|
139
|
-
return
|
|
140
|
-
importer = Importer(bindings=bindings, release=release)
|
|
141
|
-
sys.meta_path.append(importer)
|
|
142
|
-
return importer
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def uninstall(importer: Importer):
|
|
146
|
-
"""
|
|
147
|
-
Uninstall the import hook.
|
|
148
|
-
"""
|
|
149
|
-
try:
|
|
150
|
-
sys.meta_path.remove(importer)
|
|
151
|
-
except ValueError:
|
|
152
|
-
pass
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: maturin
|
|
3
|
-
Version: 0.12.19
|
|
4
|
-
Classifier: Topic :: Software Development :: Build Tools
|
|
5
|
-
Classifier: Programming Language :: Rust
|
|
6
|
-
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
7
|
-
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
8
|
-
Requires-Dist: tomli>=1.1.0 ; python_version<'3.11'
|
|
9
|
-
Requires-Dist: ziglang~=0.9.0; extra == 'zig'
|
|
10
|
-
Requires-Dist: patchelf; extra == 'patchelf'
|
|
11
|
-
Provides-Extra: zig
|
|
12
|
-
Provides-Extra: patchelf
|
|
13
|
-
Summary: Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages
|
|
14
|
-
Keywords: python,cffi,packaging,pypi,pyo3
|
|
15
|
-
Home-Page: https://github.com/pyo3/maturin
|
|
16
|
-
Author: konstin <konstin@mailbox.org>, messense <messense@icloud.com>
|
|
17
|
-
Author-email: konstin <konstin@mailbox.org>, messense <messense@icloud.com>
|
|
18
|
-
License: MIT OR Apache-2.0
|
|
19
|
-
Requires-Python: >=3.6
|
|
20
|
-
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
21
|
-
Project-URL: Issues, https://github.com/PyO3/maturin/issues
|
|
22
|
-
Project-URL: Changelog, https://maturin.rs/changelog.html
|
|
23
|
-
Project-URL: Source Code, https://github.com/PyO3/maturin
|
|
24
|
-
Project-URL: Documentation, https://maturin.rs
|
|
25
|
-
|
|
26
|
-
# Maturin
|
|
27
|
-
|
|
28
|
-
_formerly pyo3-pack_
|
|
29
|
-
|
|
30
|
-
[](https://github.com/PyO3/maturin/actions)
|
|
31
|
-
[](https://cirrus-ci.com/github/PyO3/maturin)
|
|
32
|
-
[](https://crates.io/crates/maturin)
|
|
33
|
-
[](https://pypi.org/project/maturin/)
|
|
34
|
-
[](https://maturin.rs/)
|
|
35
|
-
[](https://gitter.im/PyO3/Lobby)
|
|
36
|
-
|
|
37
|
-
Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages.
|
|
38
|
-
|
|
39
|
-
This project is meant as a zero configuration replacement for [setuptools-rust](https://github.com/PyO3/setuptools-rust) and [milksnake](https://github.com/getsentry/milksnake).
|
|
40
|
-
It supports building wheels for python 3.5+ on windows, linux, mac and freebsd, can upload them to [pypi](https://pypi.org/) and has basic pypy support.
|
|
41
|
-
|
|
42
|
-
Check out the [User Guide](https://maturin.rs/)!
|
|
43
|
-
|
|
44
|
-
## Usage
|
|
45
|
-
|
|
46
|
-
You can either download binaries from the [latest release](https://github.com/PyO3/maturin/releases/latest) or install it with pip:
|
|
47
|
-
|
|
48
|
-
```shell
|
|
49
|
-
pip install maturin
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
There are four main commands:
|
|
53
|
-
|
|
54
|
-
* `maturin new` creates a new cargo project with maturin configured.
|
|
55
|
-
* `maturin publish` builds the crate into python packages and publishes them to pypi.
|
|
56
|
-
* `maturin build` builds the wheels and stores them in a folder (`target/wheels` by default), but doesn't upload them. It's possible to upload those with [twine](https://github.com/pypa/twine) or `maturin upload`.
|
|
57
|
-
* `maturin develop` builds the crate and installs it as a python module directly in the current virtualenv. Note that while `maturin develop` is faster, it doesn't support all the feature that running `pip install` after `maturin build` supports.
|
|
58
|
-
|
|
59
|
-
`pyo3` and `rust-cpython` bindings are automatically detected, for cffi or binaries you need to pass `-b cffi` or `-b bin`.
|
|
60
|
-
maturin doesn't need extra configuration files and doesn't clash with an existing setuptools-rust or milksnake configuration.
|
|
61
|
-
You can even integrate it with testing tools such as [tox](https://tox.readthedocs.io/en/latest/).
|
|
62
|
-
There are examples for the different bindings in the `test-crates` folder.
|
|
63
|
-
|
|
64
|
-
The name of the package will be the name of the cargo project, i.e. the name field in the `[package]` section of `Cargo.toml`.
|
|
65
|
-
The name of the module, which you are using when importing, will be the `name` value in the `[lib]` section (which defaults to the name of the package). For binaries, it's simply the name of the binary generated by cargo.
|
|
66
|
-
|
|
67
|
-
## Python packaging basics
|
|
68
|
-
|
|
69
|
-
Python packages come in two formats:
|
|
70
|
-
A built form called wheel and source distributions (sdist), both of which are archives.
|
|
71
|
-
A wheel can be compatible with any python version, interpreter (cpython and pypy, mainly), operating system and hardware architecture (for pure python wheels),
|
|
72
|
-
can be limited to a specific platform and architecture (e.g. when using ctypes or cffi) or to a specific python interpreter and version on a specific architecture and operating system (e.g. with pyo3 and rust-cpython).
|
|
73
|
-
|
|
74
|
-
When using `pip install` on a package, pip tries to find a matching wheel and install that. If it doesn't find one, it downloads the source distribution and builds a wheel for the current platform,
|
|
75
|
-
which requires the right compilers to be installed. Installing a wheel is much faster than installing a source distribution as building wheels is generally slow.
|
|
76
|
-
|
|
77
|
-
When you publish a package to be installable with `pip install`, you upload it to [pypi](https://pypi.org/), the official package repository.
|
|
78
|
-
For testing, you can use [test pypi](https://test.pypi.org/) instead, which you can use with `pip install --index-url https://test.pypi.org/simple/`.
|
|
79
|
-
Note that for publishing for linux, [you need to use the manylinux docker container](#manylinux-and-auditwheel), while for publishing from your repository you can use the [messense/maturin-action github action](https://github.com/messense/maturin-action).
|
|
80
|
-
|
|
81
|
-
## pyo3 and rust-cpython
|
|
82
|
-
|
|
83
|
-
For pyo3 and rust-cpython, maturin can only build packages for installed python versions. On linux and mac, all python versions in `PATH` are used.
|
|
84
|
-
If you don't set your own interpreters with `-i`, a heuristic is used to search for python installations.
|
|
85
|
-
On windows all versions from the python launcher (which is installed by default by the python.org installer) and all conda environments except base are used. You can check which versions are picked up with the `list-python` subcommand.
|
|
86
|
-
|
|
87
|
-
pyo3 will set the used python interpreter in the environment variable `PYTHON_SYS_EXECUTABLE`, which can be used from custom build scripts. Maturin can build and upload wheels for pypy with pyo3, even though only pypy3.7-7.3 on linux is tested.
|
|
88
|
-
|
|
89
|
-
## Cffi
|
|
90
|
-
|
|
91
|
-
Cffi wheels are compatible with all python versions including pypy. If `cffi` isn't installed and python is running inside a virtualenv, maturin will install it, otherwise you have to install it yourself (`pip install cffi`).
|
|
92
|
-
|
|
93
|
-
maturin uses cbindgen to generate a header file, which can be customized by configuring cbindgen through a `cbindgen.toml` file inside your project root. Alternatively you can use a build script that writes a header file to `$PROJECT_ROOT/target/header.h`.
|
|
94
|
-
|
|
95
|
-
Based on the header file maturin generates a module which exports an `ffi` and a `lib` object.
|
|
96
|
-
|
|
97
|
-
<details>
|
|
98
|
-
<summary>Example of a custom build script</summary>
|
|
99
|
-
|
|
100
|
-
```rust
|
|
101
|
-
use cbindgen;
|
|
102
|
-
use std::env;
|
|
103
|
-
use std::path::Path;
|
|
104
|
-
|
|
105
|
-
fn main() {
|
|
106
|
-
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
107
|
-
|
|
108
|
-
let bindings = cbindgen::Builder::new()
|
|
109
|
-
.with_no_includes()
|
|
110
|
-
.with_language(cbindgen::Language::C)
|
|
111
|
-
.with_crate(crate_dir)
|
|
112
|
-
.generate()
|
|
113
|
-
.unwrap();
|
|
114
|
-
bindings.write_to_file(Path::new("target").join("header.h"));
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
</details>
|
|
119
|
-
|
|
120
|
-
## Mixed rust/python projects
|
|
121
|
-
|
|
122
|
-
To create a mixed rust/python project, create a folder with your module name (i.e. `lib.name` in Cargo.toml) next to your Cargo.toml and add your python sources there:
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
my-project
|
|
126
|
-
├── Cargo.toml
|
|
127
|
-
├── my_project
|
|
128
|
-
│ ├── __init__.py
|
|
129
|
-
│ └── bar.py
|
|
130
|
-
├── pyproject.toml
|
|
131
|
-
├── Readme.md
|
|
132
|
-
└── src
|
|
133
|
-
└── lib.rs
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
You can specify a different python source directory in `Cargo.toml` by setting `package.metadata.maturin.python-source`, for example
|
|
137
|
-
|
|
138
|
-
```toml
|
|
139
|
-
[package.metadata.maturin]
|
|
140
|
-
python-source = "python"
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
then the project structure would look like this:
|
|
144
|
-
|
|
145
|
-
```
|
|
146
|
-
my-project
|
|
147
|
-
├── Cargo.toml
|
|
148
|
-
├── python
|
|
149
|
-
│ └── my_project
|
|
150
|
-
│ ├── __init__.py
|
|
151
|
-
│ └── bar.py
|
|
152
|
-
├── pyproject.toml
|
|
153
|
-
├── Readme.md
|
|
154
|
-
└── src
|
|
155
|
-
└── lib.rs
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
maturin will add the native extension as a module in your python folder. When using develop, maturin will copy the native library and for cffi also the glue code to your python folder. You should add those files to your gitignore.
|
|
159
|
-
|
|
160
|
-
With cffi you can do `from .my_project import lib` and then use `lib.my_native_function`, with pyo3/rust-cpython you can directly `from .my_project import my_native_function`.
|
|
161
|
-
|
|
162
|
-
Example layout with pyo3 after `maturin develop`:
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
my-project
|
|
166
|
-
├── Cargo.toml
|
|
167
|
-
├── my_project
|
|
168
|
-
│ ├── __init__.py
|
|
169
|
-
│ ├── bar.py
|
|
170
|
-
│ └── my_project.cpython-36m-x86_64-linux-gnu.so
|
|
171
|
-
├── Readme.md
|
|
172
|
-
└── src
|
|
173
|
-
└── lib.rs
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Python metadata
|
|
177
|
-
|
|
178
|
-
maturin supports [PEP 621](https://www.python.org/dev/peps/pep-0621/), you can specify python package metadata in `pyproject.toml`.
|
|
179
|
-
maturin merges metadata from `Cargo.toml` and `pyproject.toml`, `pyproject.toml` take precedence over `Cargo.toml`.
|
|
180
|
-
|
|
181
|
-
To specify python dependencies, add a list `dependencies` in a `[project]` section in the `pyproject.toml`. This list is equivalent to `install_requires` in setuptools:
|
|
182
|
-
|
|
183
|
-
```toml
|
|
184
|
-
[project]
|
|
185
|
-
name = "my-project"
|
|
186
|
-
dependencies = ["flask~=1.1.0", "toml==0.10.0"]
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Pip allows adding so called console scripts, which are shell commands that execute some function in you program. You can add console scripts in a section `[project.scripts]`.
|
|
190
|
-
The keys are the script names while the values are the path to the function in the format `some.module.path:class.function`, where the `class` part is optional. The function is called with no arguments. Example:
|
|
191
|
-
|
|
192
|
-
```toml
|
|
193
|
-
[project.scripts]
|
|
194
|
-
get_42 = "my_project:DummyClass.get_42"
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
You can also specify [trove classifiers](https://pypi.org/classifiers/) in your Cargo.toml under `project.classifiers`:
|
|
198
|
-
|
|
199
|
-
```toml
|
|
200
|
-
[project]
|
|
201
|
-
name = "my-project"
|
|
202
|
-
classifiers = ["Programming Language :: Python"]
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Source distribution
|
|
206
|
-
|
|
207
|
-
maturin supports building through `pyproject.toml`. To use it, create a `pyproject.toml` next to your `Cargo.toml` with the following content:
|
|
208
|
-
|
|
209
|
-
```toml
|
|
210
|
-
[build-system]
|
|
211
|
-
requires = ["maturin>=0.12,<0.13"]
|
|
212
|
-
build-backend = "maturin"
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
If a `pyproject.toml` with a `[build-system]` entry is present, maturin will build a source distribution of your package, unless `--no-sdist` is specified.
|
|
216
|
-
The source distribution will contain the same files as `cargo package`. To only build a source distribution, pass `--interpreter` without any values.
|
|
217
|
-
|
|
218
|
-
You can then e.g. install your package with `pip install .`. With `pip install . -v` you can see the output of cargo and maturin.
|
|
219
|
-
|
|
220
|
-
You can use the options `compatibility`, `skip-auditwheel`, `bindings`, `strip`, `cargo-extra-args` and `rustc-extra-args` under `[tool.maturin]` the same way you would when running maturin directly.
|
|
221
|
-
The `bindings` key is required for cffi and bin projects as those can't be automatically detected. Currently, all builds are in release mode (see [this thread](https://discuss.python.org/t/pep-517-debug-vs-release-builds/1924) for details).
|
|
222
|
-
|
|
223
|
-
For a non-manylinux build with cffi bindings you could use the following:
|
|
224
|
-
|
|
225
|
-
```toml
|
|
226
|
-
[build-system]
|
|
227
|
-
requires = ["maturin>=0.12,<0.13"]
|
|
228
|
-
build-backend = "maturin"
|
|
229
|
-
|
|
230
|
-
[tool.maturin]
|
|
231
|
-
bindings = "cffi"
|
|
232
|
-
compatibility = "linux"
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
`manylinux` option is also accepted as an alias of `compatibility` for backward compatibility with old version of maturin.
|
|
236
|
-
|
|
237
|
-
To include arbitrary files in the sdist for use during compilation specify `sdist-include` as an array of globs:
|
|
238
|
-
|
|
239
|
-
```toml
|
|
240
|
-
[tool.maturin]
|
|
241
|
-
sdist-include = ["path/**/*"]
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
There's a `maturin sdist` command for only building a source distribution as workaround for [pypa/pip#6041](https://github.com/pypa/pip/issues/6041).
|
|
245
|
-
|
|
246
|
-
## Manylinux and auditwheel
|
|
247
|
-
|
|
248
|
-
For portability reasons, native python modules on linux must only dynamically link a set of very few libraries which are installed basically everywhere, hence the name manylinux.
|
|
249
|
-
The pypa offers special docker images and a tool called [auditwheel](https://github.com/pypa/auditwheel/) to ensure compliance with the [manylinux rules](https://www.python.org/dev/peps/pep-0571/#the-manylinux2010-policy).
|
|
250
|
-
If you want to publish widely usable wheels for linux pypi, **you need to use a manylinux docker image**.
|
|
251
|
-
|
|
252
|
-
The Rust compiler since version 1.47 [requires at least glibc 2.11](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1470-2020-10-08), so you need to use at least manylinux2010.
|
|
253
|
-
For publishing, we recommend enforcing the same manylinux version as the image with the manylinux flag, e.g. use `--manylinux 2014` if you are building in `quay.io/pypa/manylinux2014_x86_64`.
|
|
254
|
-
The [messense/maturin-action](https://github.com/messense/maturin-action) github action already takes care of this if you set e.g. `manylinux: 2014`.
|
|
255
|
-
|
|
256
|
-
maturin contains a reimplementation of auditwheel automatically checks the generated library and gives the wheel the proper.
|
|
257
|
-
If your system's glibc is too new or you link other shared libraries, it will assign the `linux` tag.
|
|
258
|
-
You can also manually disable those checks and directly use native linux target with `--manylinux off`.
|
|
259
|
-
|
|
260
|
-
For full manylinux compliance you need to compile in a CentOS docker container. The [pyo3/maturin](https://ghcr.io/pyo3/maturin) image is based on the manylinux2010 image,
|
|
261
|
-
and passes arguments to the `maturin` binary. You can use it like this:
|
|
262
|
-
|
|
263
|
-
```
|
|
264
|
-
docker run --rm -v $(pwd):/io ghcr.io/pyo3/maturin build --release # or other maturin arguments
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
Note that this image is very basic and only contains python, maturin and stable rust. If you need additional tools, you can run commands inside the manylinux container.
|
|
268
|
-
See [konstin/complex-manylinux-maturin-docker](https://github.com/konstin/complex-manylinux-maturin-docker) for a small educational example or [nanoporetech/fast-ctc-decode](https://github.com/nanoporetech/fast-ctc-decode/blob/b226ea0f2b2f4f474eff47349703d57d2ea4801b/.github/workflows/publish.yml) for a real world setup.
|
|
269
|
-
|
|
270
|
-
maturin itself is manylinux compliant when compiled for the musl target.
|
|
271
|
-
|
|
272
|
-
## Code
|
|
273
|
-
|
|
274
|
-
The main part is the maturin library, which is completely documented and should be well integrable. The accompanying `main.rs` takes care username and password for the pypi upload and otherwise calls into the library.
|
|
275
|
-
|
|
276
|
-
The `sysconfig` folder contains the output of `python -m sysconfig` for different python versions and platform, which is helpful during development.
|
|
277
|
-
|
|
278
|
-
You need to install `cffi` and `virtualenv` (`pip install cffi virtualenv`) to run the tests.
|
|
279
|
-
|
|
280
|
-
There are some optional hacks that can speed up the tests (over 80s to 17s on my machine).
|
|
281
|
-
1. By running `cargo build --release --manifest-path test-crates/cargo-mock/Cargo.toml` you can activate a cargo cache avoiding to rebuild the pyo3 test crates with every python version.
|
|
282
|
-
2. Delete `target/test-cache` to clear the cache (e.g. after changing a test crate) or remove `test-crates/cargo-mock/target/release/cargo` to deactivate it.
|
|
283
|
-
3. By running the tests with the `faster-tests` feature, binaries are stripped and wheels are only stored and not compressed.
|
|
284
|
-
|
maturin-0.12.19.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
maturin-0.12.19.dist-info/METADATA,sha256=cms-zhifDbMbgx3PfmmC7kC50hhl_zJhGoe_uXQaL_A,15476
|
|
2
|
-
maturin-0.12.19.dist-info/WHEEL,sha256=6OXUSsNrEQivqqFRVKBxqPQsdGI0KIVrJ1bSNlw7PXY,95
|
|
3
|
-
maturin/import_hook.py,sha256=gFTAmQZBhoWvweXK5-ontQfqnVE-DTRJmnjIbn0bDUI,4987
|
|
4
|
-
maturin/__init__.py,sha256=V4ISM-b_o3LnveoWtNCsCorRXtjPXo94tBuN1prAcEc,5467
|
|
5
|
-
maturin-0.12.19.data/scripts/maturin.exe,sha256=LY5SKozDHN8s51Sz9D7VdjanCO_bKnnphx0ggGYdgAU,16143872
|
|
6
|
-
maturin-0.12.19.dist-info/RECORD,,
|