55import warnings
66
77from setuptools import Extension , setup
8- from setuptools . command . build_ext import build_ext
8+ import numpy as np
99
1010debug = os .getenv ("DEBUG_CPPRB" )
1111
1818 or os .getenv ("GITLAB_CI" )
1919)
2020
21- arm_mac = (sysconfig .get_platform ().split ("-" )[0 ] == "macosx" ) and (platform .machine () == "arm64" )
22-
23- requires = ["numpy" ]
24- setup_requires = ["wheel" ]
25-
26- if sys .version_info >= (3 , 9 ):
27- # NumPy 2.0 breaks ABI compatibility.
28- # To support both NumPy 1.x and 2.x, build with NumPy 2.x
29- # cf. https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-abi-handling
30- setup_requires .append ("numpy>=2.0.0" )
31- elif (sys .version_info < (3 , 9 )) and not arm_mac :
32- # NumPy 1.20 breaks ABI compatibility.
33- # To support both NumPy 1.19.x and 1.20+, build with NumPy 1.19
34- # This is necessary to work with old library which requires old NumPy.
35-
36- # NumPy 1.19.5 doesn't support Python 3.10+
37- # NumPy 1.19.5 doesn't distribute wheel for macOS aarch64,
38- setup_requires .append ("numpy<1.20" )
39- else :
40- setup_requires .append ("numpy" )
41-
42- rb_source = "src/cpprb/PyReplayBuffer"
43- cpp_ext = ".cpp"
44- pyx_ext = ".pyx"
45-
4621
4722# Set compiler flags depending on platform
4823if platform .system () == "Windows" :
6136 if debug :
6237 extra_compile_args .append ("-DCYTHON_TRACE_NOGIL=1" )
6338
64- # Check cythonize or not
65- pyx_file = rb_source + pyx_ext
66- use_cython = os .path .exists (pyx_file )
6739
68- if use_cython :
69- suffix = pyx_ext
70- setup_requires .extend (["cython>=3.0.11" ])
71- compiler_directives = {"language_level" : "3" }
7240
73- if debug :
74- compiler_directives [ "linetrace" ] = True
75- else :
76- suffix = cpp_ext
41+ compiler_directives = { "language_level" : "3" }
42+ if debug :
43+ compiler_directives [ "linetrace" ] = True
44+
7745
7846# Set ext_module
7947ext = [["cpprb" , "PyReplayBuffer" ], ["cpprb" , "VectorWrapper" ]]
8048
8149ext_modules = [
8250 Extension (
8351 "." .join (e ),
84- sources = ["src/" + "/" .join (e ) + suffix ],
85- extra_compile_args = extra_compile_args ,
86- extra_link_args = extra_link_args ,
87- language = "c++" ,
52+ sources = ["src/" + "/" .join (e ) + ".pyx" ],
53+ include_dirs = [np .get_include ()],
54+ extra_compile_args = extra_compile_args ,
55+ extra_link_args = extra_link_args ,
56+ language = "c++" ,
57+ compiler_directives = compiler_directives ,
58+ cython_include_dirs = ["." ],
8859 )
8960 for e in ext
9061]
9162
9263
93- class LazyImportBuildExtCommand (build_ext ):
94- """
95- build_ext command class for lazy numpy and cython import
96- """
97-
98- def run (self ):
99- import numpy as np
100-
101- self .include_dirs .append (np .get_include ())
102- build_ext .run (self )
103-
104- def finalize_options (self ):
105- if use_cython :
106- from Cython .Build import cythonize
107-
108- self .distribution .ext_modules = cythonize (
109- self .distribution .ext_modules ,
110- compiler_directives = compiler_directives ,
111- include_path = ["." ],
112- annotate = True ,
113- )
114- super ().finalize_options ()
115-
116-
11764description = "ReplayBuffer for Reinforcement Learning written by C++ and Cython"
11865README = os .path .join (os .path .abspath (os .path .dirname (__file__ )), "README.md" )
11966if os .path .exists (README ):
@@ -126,36 +73,8 @@ def finalize_options(self):
12673 long_description_content_type = "text/plain"
12774
12875setup (
129- name = "cpprb" ,
130- author = "Yamada Hiroyuki" ,
13176 description = description ,
132- version = "11.0.0" ,
133- install_requires = requires ,
134- setup_requires = setup_requires ,
135- cmdclass = {"build_ext" : LazyImportBuildExtCommand },
136- url = "https://ymd_h.gitlab.io/cpprb/" ,
137- project_urls = {
138- "Source Code" : "https://gitlab.com/ymd_h/cpprb" ,
139- "Mirror" : "https://github.com/ymd-h/cpprb" ,
140- "Change Log" : "https://ymd_h.gitlab.io/cpprb/changelog/" ,
141- "Bug Report & QA" : "https://github.com/ymd-h/cpprb/discussions" ,
142- },
143- package_dir = {"" : "src" },
14477 ext_modules = ext_modules ,
145- include_dirs = ["cpprb" ],
146- packages = ["cpprb" ],
147- classifiers = [
148- "Programming Language :: Python" ,
149- "Programming Language :: Python :: 3" ,
150- "License :: OSI Approved :: MIT License" ,
151- "Operating System :: OS Independent" ,
152- "Development Status :: 4 - Beta" ,
153- "Intended Audience :: Developers" ,
154- "Intended Audience :: Science/Research" ,
155- "Topic :: Scientific/Engineering" ,
156- "Topic :: Scientific/Engineering :: Artificial Intelligence" ,
157- "Topic :: Software Development :: Libraries" ,
158- ],
15978 long_description = long_description ,
16079 long_description_content_type = long_description_content_type ,
16180)
0 commit comments