Skip to content

Commit 0c499ec

Browse files
Restore class inheritance hierararchy for build_py command class
Custom build_py written to enable support for multi-versioned DPCLSyclInterface on Linux need to inherit from versioneer's version of build_py, rather than from setuptools' one to incorporate the step where dpctl/_version.py is overwritten with rendered result based on source tree.
1 parent a44770e commit 0c499ec

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VCS = git
33
versionfile_source = dpctl/_version.py
44
versionfile_build = dpctl/_version.py
55
tag_prefix =
6-
parentdir_prefix = DPCTL-
6+
parentdir_prefix = dpctl-
77

88
[bdist_wheel]
99
universal=1

setup.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import numpy as np
2424
import setuptools.command.build_ext as orig_build_ext
25-
import setuptools.command.build_py as orig_build_py
2625
import setuptools.command.develop as orig_develop
2726
import setuptools.command.install as orig_install
2827
from Cython.Build import cythonize
@@ -254,32 +253,35 @@ def run(self):
254253
return super().run()
255254

256255

257-
class build_py(orig_build_py.build_py):
258-
def run(self):
259-
dpctl_src_dir = self.get_package_dir("dpctl")
260-
dpctl_build_dir = os.path.join(self.build_lib, "dpctl")
261-
os.makedirs(dpctl_build_dir, exist_ok=True)
262-
if IS_LIN:
263-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")):
264-
# Check if the file already exists before copying. The check is
265-
# needed when dealing with symlinks.
266-
if not os.path.exists(
267-
os.path.join(dpctl_build_dir, os.path.basename(fn))
268-
):
269-
shutil.copy(
270-
src=fn,
271-
dst=dpctl_build_dir,
272-
follow_symlinks=False,
273-
)
274-
elif IS_WIN:
275-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")):
276-
shutil.copy(src=fn, dst=dpctl_build_dir)
277-
278-
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")):
279-
shutil.copy(src=fn, dst=dpctl_build_dir)
280-
else:
281-
raise NotImplementedError("Unsupported platform")
282-
return super().run()
256+
def get_build_py(orig_build_py):
257+
class build_py(orig_build_py):
258+
def run(self):
259+
dpctl_src_dir = self.get_package_dir("dpctl")
260+
dpctl_build_dir = os.path.join(self.build_lib, "dpctl")
261+
os.makedirs(dpctl_build_dir, exist_ok=True)
262+
if IS_LIN:
263+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")):
264+
# Check if the file already exists before copying.
265+
# The check is needed when dealing with symlinks.
266+
if not os.path.exists(
267+
os.path.join(dpctl_build_dir, os.path.basename(fn))
268+
):
269+
shutil.copy(
270+
src=fn,
271+
dst=dpctl_build_dir,
272+
follow_symlinks=False,
273+
)
274+
elif IS_WIN:
275+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")):
276+
shutil.copy(src=fn, dst=dpctl_build_dir)
277+
278+
for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")):
279+
shutil.copy(src=fn, dst=dpctl_build_dir)
280+
else:
281+
raise NotImplementedError("Unsupported platform")
282+
return super().run()
283+
284+
return build_py
283285

284286

285287
class install(orig_install.install):
@@ -436,10 +438,10 @@ def run(self):
436438

437439
def _get_cmdclass():
438440
cmdclass = versioneer.get_cmdclass()
441+
cmdclass["build_py"] = get_build_py(cmdclass["build_py"])
439442
cmdclass["install"] = install
440443
cmdclass["develop"] = develop
441444
cmdclass["build_ext"] = build_ext
442-
cmdclass["build_py"] = build_py
443445
return cmdclass
444446

445447

0 commit comments

Comments
 (0)