11import sys
22from setuptools import find_packages , setup
3- from setuptools .command .test import test as TestCommand
43from setuptools_rust import RustExtension
54
65
7- class PyTest (TestCommand ):
8- user_options = []
9-
10- def run (self ):
11- self .run_command ("test_rust" )
12- import subprocess
13- errno = subprocess .call (['pytest' , 'tests' ])
14- raise SystemExit (errno )
15-
16-
17- def get_cfg_flags ():
18- version = sys .version_info [0 :2 ]
19- if version [0 ] == 2 :
20- return ['--cfg=Py_2' ]
21- else :
22- return ['--cfg=Py_3' ]
23-
24-
25- def get_features ():
26- version = sys .version_info [0 :2 ]
27- if version [0 ] == 2 :
28- return ['numpy/python2' ]
29- else :
30- return ['numpy/python3' ]
31-
6+ PYTHON_MAJOR_VERSION = sys .version_info [0 ]
327
338setup_requires = ['setuptools-rust>=0.6.0' ]
349install_requires = ['numpy' ]
@@ -41,13 +16,12 @@ def get_features():
4116 rust_extensions = [RustExtension (
4217 'rust_ext.rust_ext' ,
4318 './Cargo.toml' ,
44- rustc_flags = get_cfg_flags () ,
45- features = get_features () ,
19+ rustc_flags = [ '--cfg=Py_{}' . format ( PYTHON_MAJOR_VERSION )] ,
20+ features = [ 'numpy/python{}' . format ( PYTHON_MAJOR_VERSION )] ,
4621 )],
4722 install_requires = install_requires ,
4823 setup_requires = setup_requires ,
4924 test_requires = test_requires ,
5025 packages = find_packages (),
5126 zip_safe = False ,
52- cmdclass = dict (test = PyTest )
5327)
0 commit comments