Skip to content

Commit fa9ef6a

Browse files
committed
add pyo3 support
1 parent 4272c1c commit fa9ef6a

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGES
22
=======
33

4+
0.6.0 (2017-05-14)
5+
------------------
6+
7+
- Add support for PyO3 project https://github.com/PyO3/PyO3
8+
9+
410
0.5.1 (2017-05-03)
511
------------------
612

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
version = '0.5.1'
3+
version = '0.6.0'
44

55

66
setup(

setuptools_rust/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def build_extension(self, ext):
5252
# disables rust's pkg-config seeking for specified packages,
5353
# which causes pythonXX-sys to fall back to detecting the
5454
# interpreter from the path.
55-
"PYTHON_2.7_NO_PKG_CONFIG": "1",
5655
"PATH": bindir + os.pathsep + os.environ.get("PATH", "")
5756
})
5857

@@ -61,7 +60,7 @@ def build_extension(self, ext):
6160
"Can not file rust extension project file: %s" % ext.path)
6261

6362
features = set(ext.features)
64-
features.update(cpython_feature())
63+
features.update(cpython_feature(pyo3=ext.pyo3))
6564

6665
if ext.debug is None:
6766
debug_build = self.inplace
@@ -107,7 +106,8 @@ def build_extension(self, ext):
107106
if not quiet:
108107
if isinstance(output, bytes):
109108
output = output.decode('latin-1')
110-
print(output, file=sys.stderr)
109+
if output:
110+
print(output, file=sys.stderr)
111111

112112
# Find the shared library that cargo hopefully produced and copy
113113
# it into the build directory as if it were produced by build_ext.

setuptools_rust/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run(self):
5555
"Can not file rust extension project file: %s" % ext.path)
5656

5757
features = set(ext.features)
58-
features.update(cpython_feature())
58+
features.update(cpython_feature(pyo3=ext.pyo3))
5959

6060
# build cargo command
6161
args = (["cargo", "check", "--lib", "--manifest-path", ext.path,

setuptools_rust/extension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ class RustExtension:
2828
Controls whether --debug or --release is passed to cargo. If set to
2929
None then build type is auto-detect. Inplace build is debug build
3030
otherwise release. Default: None
31+
pyo3 : bool
32+
Controls wich python binding is in use. `pyo3=True` uses PyO3 binding,
33+
`pyo3=False` uses rust-cpython binding,
3134
"""
3235

3336
def __init__(self, name, path,
3437
args=None, features=None, rust_version=None,
35-
quiet=False, debug=None):
38+
quiet=False, debug=None, pyo3=False):
3639
self.name = name
3740
self.args = args
41+
self.pyo3 = pyo3
3842
self.rust_version = rust_version
3943
self.quiet = quiet
4044
self.debug = debug

setuptools_rust/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def run(self):
5757
"Can not file rust extension project file: %s" % ext.path)
5858

5959
features = set(ext.features)
60-
features.update(cpython_feature(ext=False))
60+
features.update(cpython_feature(ext=False, pyo3=ext.pyo3))
6161

6262
# build cargo command
63-
args = (["cargo", "test", "--manifest-path", ext.path,
64-
"--features", " ".join(features)]
63+
args = (["cargo", "test", '--color', 'always', "--manifest-path",
64+
ext.path, "--features", " ".join(features)]
6565
+ list(ext.args or []))
6666

6767
# Execute cargo command

setuptools_rust/utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,28 @@
66
import semantic_version
77

88

9-
def cpython_feature(ext=True):
9+
def cpython_feature(ext=True, pyo3=False):
1010
version = sys.version_info
11-
if (2, 7) < version < (2, 8):
12-
if ext:
13-
return ("cpython/python27-sys", "cpython/extension-module-2-7")
14-
else:
15-
return ("cpython/python27-sys",)
16-
elif (3, 3) < version:
11+
12+
if pyo3:
1713
if ext:
18-
return ("cpython/python3-sys", "cpython/extension-module")
14+
return ("pyo3/extension-module",)
1915
else:
20-
return ("cpython/python3-sys",)
16+
return ()
2117
else:
22-
raise DistutilsPlatformError(
23-
"Unsupported python version: %s" % sys.version)
18+
if (2, 7) < version < (2, 8):
19+
if ext:
20+
return ("cpython/python27-sys", "cpython/extension-module-2-7")
21+
else:
22+
return ("cpython/python27-sys",)
23+
elif (3, 3) < version:
24+
if ext:
25+
return ("cpython/python3-sys", "cpython/extension-module")
26+
else:
27+
return ("cpython/python3-sys",)
28+
29+
raise DistutilsPlatformError(
30+
"Unsupported python version: %s" % sys.version)
2431

2532

2633
def get_rust_version():

0 commit comments

Comments
 (0)