1- import os
2- import subprocess
31import sys
42from setuptools import find_packages , setup
5- from setuptools .command .test import test as TestCommand
63from setuptools_rust import RustExtension
74
8- class PyTest (TestCommand ):
9- user_options = []
10- def run (self ):
11- self .run_command ("test_rust" )
12- import subprocess
13- errno = subprocess .call (['pytest' , 'tests' ])
14- raise SystemExit (errno )
155
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- def get_features ():
25- version = sys .version_info [0 :2 ]
26- if version [0 ] == 2 :
27- return ['numpy/python2' ]
28- else :
29- return ['numpy/python3' ]
6+ PYTHON_MAJOR_VERSION = sys .version_info [0 ]
307
318setup_requires = ['setuptools-rust>=0.6.0' ]
329install_requires = ['numpy' ]
@@ -39,13 +16,12 @@ def get_features():
3916 rust_extensions = [RustExtension (
4017 'rust_ext.rust_ext' ,
4118 './Cargo.toml' ,
42- rustc_flags = get_cfg_flags () ,
43- features = get_features () ,
19+ rustc_flags = [ '--cfg=Py_{}' . format ( PYTHON_MAJOR_VERSION )] ,
20+ features = [ 'numpy/python{}' . format ( PYTHON_MAJOR_VERSION )] ,
4421 )],
4522 install_requires = install_requires ,
4623 setup_requires = setup_requires ,
4724 test_requires = test_requires ,
4825 packages = find_packages (),
4926 zip_safe = False ,
50- cmdclass = dict (test = PyTest )
5127)
0 commit comments