Skip to content

Commit dbb731a

Browse files
committed
Clean up setup.py
1 parent c9b30cd commit dbb731a

File tree

2 files changed

+6
-112
lines changed

2 files changed

+6
-112
lines changed

conda-recipe/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ ${PYTHON} -m pip install dist/dpctl*.whl \
3131
--prefix "${PREFIX}" \
3232
-vv
3333

34+
# Recover symbolic links
35+
# libDPCTLSyclInterface.so.0 -> libDPCTLSyclInterface.so.0.17
36+
# libDPCTLSyclInterface.so -> libDPCTLSyclInterface.so.0
37+
find $PREFIX | grep libDPCTLSyclInterface | sort -r | \
38+
awk '{if ($0=="") ln=""; else if (ln=="") ln = $0; else system("rm " $0 ";\tln -s " ln " " $0); ln = $0 }'
39+
3440
# Copy wheel package
3541
if [[ -v WHEELS_OUTPUT_FOLDER ]]; then
3642
cp dist/dpctl*.whl "${WHEELS_OUTPUT_FOLDER[@]}"

setup.py

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -14,124 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import glob
18-
import os.path
19-
import pathlib
20-
import shutil
21-
import sys
22-
2317
import skbuild
2418
import skbuild.setuptools_wrap
2519
import skbuild.utils
2620
import versioneer
27-
from skbuild.command.build_py import build_py as _skbuild_build_py
28-
from skbuild.command.install import install as _skbuild_install
29-
30-
"""
31-
Get the project version
32-
"""
33-
thefile_path = os.path.abspath(os.path.dirname(__file__))
34-
35-
36-
def cleanup_destination(cmake_manifest):
37-
"""Delete library files from dpctl/ folder before
38-
letting skbuild copy them over to avoid errors.
39-
"""
40-
_to_unlink = []
41-
for fn in cmake_manifest:
42-
bn = os.path.basename(fn)
43-
# delete
44-
if "DPCTLSyclInterface" in bn:
45-
lib_fn = os.path.join("dpctl", bn)
46-
if os.path.exists(lib_fn):
47-
_to_unlink.append(lib_fn)
48-
for fn in _to_unlink:
49-
pathlib.Path(fn).unlink()
50-
return cmake_manifest
51-
52-
53-
def _patched_copy_file(
54-
src_file, dest_file, hide_listing=True, preserve_mode=True
55-
):
56-
"""Copy ``src_file`` to ``dest_file`` ensuring parent directory exists.
57-
58-
By default, message like `creating directory /path/to/package` and
59-
`copying directory /src/path/to/package -> path/to/package` are displayed
60-
on standard output. Setting ``hide_listing`` to False avoids message from
61-
being displayed.
62-
63-
NB: Patched here to not follows symbolic links
64-
"""
65-
# Create directory if needed
66-
dest_dir = os.path.dirname(dest_file)
67-
if dest_dir != "" and not os.path.exists(dest_dir):
68-
if not hide_listing:
69-
print("creating directory {}".format(dest_dir))
70-
skbuild.utils.mkdir_p(dest_dir)
71-
72-
# Copy file
73-
if not hide_listing:
74-
print("copying {} -> {}".format(src_file, dest_file))
75-
shutil.copyfile(src_file, dest_file, follow_symlinks=False)
76-
shutil.copymode(src_file, dest_file, follow_symlinks=False)
77-
78-
79-
skbuild.setuptools_wrap._copy_file = _patched_copy_file
80-
81-
82-
class BuildPyCmd(_skbuild_build_py):
83-
def copy_file(self, src, dst, preserve_mode=True):
84-
_patched_copy_file(src, dst, preserve_mode=preserve_mode)
85-
return (dst, 1)
86-
87-
def build_package_data(self):
88-
"""Copy data files into build directory"""
89-
for package, src_dir, build_dir, filenames in self.data_files:
90-
for filename in filenames:
91-
target = os.path.join(build_dir, filename)
92-
self.mkpath(os.path.dirname(target))
93-
srcfile = os.path.join(src_dir, filename)
94-
outf, copied = self.copy_file(srcfile, target)
95-
srcfile = os.path.abspath(srcfile)
96-
97-
98-
class InstallCmd(_skbuild_install):
99-
def run(self):
100-
ret = super().run()
101-
if "linux" in sys.platform:
102-
this_dir = os.path.dirname(os.path.abspath(__file__))
103-
dpctl_build_dir = os.path.join(this_dir, self.build_lib, "dpctl")
104-
dpctl_install_dir = os.path.join(self.install_libbase, "dpctl")
105-
sofiles = glob.glob(
106-
os.path.join(dpctl_build_dir, "*DPCTLSyclInterface.so*")
107-
)
108-
# insert actual file at the beginning of the list
109-
pos = [i for i, fn in enumerate(sofiles) if not os.path.islink(fn)]
110-
if pos:
111-
hard_file = sofiles.pop(pos[0])
112-
sofiles.insert(0, hard_file)
113-
for fn in sofiles:
114-
base_fn = os.path.basename(fn)
115-
src_file = os.path.join(dpctl_build_dir, base_fn)
116-
dst_file = os.path.join(dpctl_install_dir, base_fn)
117-
os.remove(dst_file)
118-
_patched_copy_file(src_file, dst_file)
119-
return ret
120-
121-
122-
def _get_cmdclass():
123-
cmdclass = versioneer.get_cmdclass(
124-
cmdclass={
125-
"build_py": BuildPyCmd,
126-
"install": InstallCmd,
127-
}
128-
)
129-
return cmdclass
130-
13121

13222
skbuild.setup(
13323
version=versioneer.get_version(),
134-
cmdclass=_get_cmdclass(),
13524
url="https://github.com/IntelPython/dpctl",
13625
packages=[
13726
"dpctl",
@@ -169,5 +58,4 @@ def _get_cmdclass():
16958
]
17059
},
17160
include_package_data=False,
172-
cmake_process_manifest_hook=cleanup_destination,
17361
)

0 commit comments

Comments
 (0)