Skip to content

Commit 24bdfa1

Browse files
committed
Migrate config from setup.py to pyproject.toml
1 parent 3c80f4c commit 24bdfa1

File tree

2 files changed

+50
-94
lines changed

2 files changed

+50
-94
lines changed

pyproject.toml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
[build-system]
2-
requires = ["setuptools", "wheel"]
2+
requires = ["setuptools", "wheel", "numpy>=2.0.0", "cython>=3.0.11"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "cpprb"
7+
version = "11.0.0"
8+
license = { file = "LICENSE" }
9+
authors = [{ name = "Yamada Hiroyuki" }]
10+
classifiers=[
11+
"Programming Language :: Python",
12+
"Programming Language :: Python :: 3",
13+
"License :: OSI Approved :: MIT License",
14+
"Operating System :: OS Independent",
15+
"Development Status :: 4 - Beta",
16+
"Intended Audience :: Developers",
17+
"Intended Audience :: Science/Research",
18+
"Topic :: Scientific/Engineering",
19+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
20+
"Topic :: Software Development :: Libraries",
21+
]
22+
dependencies = ["numpy"]
23+
dynamic = [
24+
"description",
25+
"readme",
26+
]
27+
28+
[project.urls]
29+
"Home Page" = "https://ymd_h.gitlab.io/cpprb/"
30+
"Source Code" = "https://gitlab.com/ymd_h/cpprb"
31+
"Mirror" = "https://github.com/ymd-h/cpprb"
32+
"Change Log" = "https://ymd_h.gitlab.io/cpprb/changelog/"
33+
"Bug Report & QA" = "https://github.com/ymd-h/cpprb/discussions"
34+
35+
36+
[tool.setuptools]
37+
packages = ["cpprb"]
38+
package-dir = { "" = "src" }
39+
include-package-data = false
40+
41+
542
[tool.cibuildwheel]
643
build = ["cp3{9,10,11,12,13}-{macosx_*,{win,????linux}_*64}"]
744
build-frontend = "build[uv]"

setup.py

Lines changed: 12 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import warnings
66

77
from setuptools import Extension, setup
8-
from setuptools.command.build_ext import build_ext
8+
import numpy as np
99

1010
debug = os.getenv("DEBUG_CPPRB")
1111

@@ -18,31 +18,6 @@
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
4823
if platform.system() == "Windows":
@@ -61,59 +36,31 @@
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
7947
ext = [["cpprb", "PyReplayBuffer"], ["cpprb", "VectorWrapper"]]
8048

8149
ext_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-
11764
description = "ReplayBuffer for Reinforcement Learning written by C++ and Cython"
11865
README = os.path.join(os.path.abspath(os.path.dirname(__file__)), "README.md")
11966
if os.path.exists(README):
@@ -126,36 +73,8 @@ def finalize_options(self):
12673
long_description_content_type = "text/plain"
12774

12875
setup(
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

Comments
 (0)