Skip to content

Commit 5c299f2

Browse files
thijsmieeboasson
authored andcommitted
Remove scikit-build
1 parent 6c54bbc commit 5c299f2

File tree

12 files changed

+305
-92
lines changed

12 files changed

+305
-92
lines changed

.azure/publish-release.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ variables:
3838
CONFIGURE: >-
3939
mkdir -p build &&
4040
cd build &&
41-
cmake ../main -DCMAKE_INSTALL_PREFIX="$CYCLONEDDS_HOME" -DBUILD_SCHEMA=off -DENABLE_SHM=off -DENABLE_SSL=off -DENABLE_SECURITY=off -DENABLE_TOPIC_DISCOVERY=on -DENABLE_TYPE_DISCOVERY=on
41+
cmake ../main -DCMAKE_INSTALL_PREFIX="$CYCLONEDDS_HOME" -DBUILD_SCHEMA=off -DENABLE_SHM=off -DENABLE_SSL=on -DENABLE_SECURITY=on -DENABLE_TOPIC_DISCOVERY=on -DENABLE_TYPE_DISCOVERY=on
4242
BUILD: >-
4343
cmake --build . --target install
4444
CIBW_BEFORE_ALL: >-
@@ -48,16 +48,16 @@ variables:
4848
auditwheel repair -w {dest_dir} {wheel}
4949
CIBW_ENVIRONMENT_LINUX: >-
5050
CYCLONEDDS_HOME=/project/install
51-
CMAKE_PREFIX_PATH=/project/install
5251
LD_LIBRARY_PATH=/project/install/lib:/project/install/lib64
52+
STANDALONE_WHEELS=1
5353
# ---- MACOS ----
5454
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >-
5555
DYLD_LIBRARY_PATH=$(Build.Repository.LocalPath)/install/lib delocate-listdeps {wheel} &&
5656
DYLD_LIBRARY_PATH=$(Build.Repository.LocalPath)/install/lib delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
5757
CIBW_ENVIRONMENT_MACOS: >-
5858
CYCLONEDDS_HOME=$(Build.Repository.LocalPath)/install
59-
CMAKE_PREFIX_PATH=$(Build.Repository.LocalPath)/install
6059
DYLD_LIBRARY_PATH=$(Build.Repository.LocalPath)/install/lib
60+
STANDALONE_WHEELS=1
6161
# ---- WINDOWS ----
6262
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >-
6363
pip install delvewheel==0.0.14 &&
@@ -93,9 +93,9 @@ jobs:
9393
$(CLONE) && $(CONFIGURE) -A Win32 && $(BUILD)
9494
steps:
9595
- pwsh: |
96+
Write-Host "###vso[task.setvariable variable=STANDALONE_WHEELS;]1"
9697
Write-Host "###vso[task.setvariable variable=PATH;]$(Build.Repository.LocalPath)\\install\\bin;${env:PATH}"
9798
Write-Host "###vso[task.setvariable variable=CYCLONEDDS_HOME;]$(Build.Repository.LocalPath)\install"
98-
Write-Host "###vso[task.setvariable variable=CMAKE_PREFIX_PATH;]$(Build.Repository.LocalPath)\install"
9999
$a = "${env:CIBW_BEFORE_ALL_WINDOWS_PRE}" -replace "\`$CYCLONEDDS_HOME","$(Build.Repository.LocalPath)\install"
100100
Write-Host "###vso[task.setvariable variable=CIBW_BEFORE_ALL_WINDOWS;]$a"
101101
condition: eq(variables['Agent.OS'], 'Windows_NT')
@@ -128,4 +128,3 @@ jobs:
128128
find artifacts/ -name "*.whl" -exec mv {} wheelhouse \;
129129
displayName: Collect wheels for publication
130130
- template: /.azure/templates/publish-package.yml
131-

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Custom
2+
cyclonedds/__library__.py
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $ pip3 install --user .[dev]
4141
$ pip3 install --user .[docs]
4242
```
4343

44-
While the quickest way to get going is the `--user` flag it is not the recommended, we recommend using [a virtual environment][2], [poetry][3], [pipenv][4] or [pyenv][5]. After the installation is complete `import cyclonedds` should now work. The `CYCLONEDDS_HOME` variable is essential for the Python backend to locate the CycloneDDS binaries so this always needs to be set when running Python code with Cyclone DDS. Have a look at the [examples](examples/) to learn about how to use the Python API.
44+
While the quickest way to get going is the `--user` flag it is not the recommended, we recommend using [a virtual environment][2], [poetry][3], [pipenv][4] or [pyenv][5]. After the installation is complete `import cyclonedds` should now work. Have a look at the [examples](examples/) to learn about how to use the Python API.
4545

4646
You can also run the idl compiler in Python mode if it the Python package is installed. Simply run `idlc -l py file.idl` and a Python module with your types will be generated in the current working directory. If you wish to nest the resulting Python module inside an existing package you can specify the path from the intended root. So if you have a package 'wubble' with a submodule 'fruzzy' and want the generated modules and types under there you can do `idlc -l py -p py-root-prefix=wubble.fruzzy file.idl`.
4747

buildhelp/bdist_wheel.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
2+
from cyclone_search import find_cyclonedds
3+
from pathlib import Path
4+
import shutil
5+
import os
6+
7+
8+
class bdist_wheel(_bdist_wheel):
9+
def initialize_options(self):
10+
self.standalone = os.environ.get("STANDALONE_WHEELS") == "1"
11+
super().initialize_options()
12+
13+
def finalize_options(self):
14+
if self.standalone:
15+
self.distribution.entry_points["console_scripts"].append("idlc=cyclonedds.tools.wheel_idlc:command")
16+
super().finalize_options()
17+
18+
def run(self):
19+
if self.standalone:
20+
cyclone = find_cyclonedds()
21+
22+
newlibdir = Path(self.bdist_dir) / 'cyclonedds' / '.libs'
23+
24+
os.makedirs(newlibdir, exist_ok=True)
25+
with open(Path(self.bdist_dir) / 'cyclonedds' / '__library__.py', "w", encoding='utf-8') as f:
26+
f.write("from pathlib import Path\n\n")
27+
f.write("in_wheel = True\n")
28+
f.write(f"library_path = Path(__file__).parent / '.libs' / '{cyclone.ddsc_library.name}'")
29+
30+
shutil.copy(cyclone.ddsc_library, newlibdir / cyclone.ddsc_library.name)
31+
32+
if cyclone.idlc_executable and cyclone.idlc_library:
33+
shutil.copy(cyclone.idlc_executable, newlibdir / cyclone.idlc_executable.name)
34+
shutil.copy(cyclone.idlc_library, newlibdir / cyclone.idlc_library.name)
35+
36+
for lib in cyclone.security_libs:
37+
shutil.copy(lib, newlibdir / lib.name)
38+
39+
super().run()

buildhelp/build_ext.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from setuptools.command.build_ext import build_ext as _build_ext
2+
from setuptools import Extension
3+
4+
5+
class Library(Extension):
6+
pass
7+
8+
9+
class build_ext(_build_ext):
10+
def get_libraries(self, ext):
11+
if isinstance(ext, Library):
12+
return ext.libraries
13+
return super().get_libraries(ext)
14+
15+
def get_export_symbols(self, ext):
16+
if isinstance(ext, Library):
17+
return ext.export_symbols
18+
return super().get_export_symbols(ext)
19+

buildhelp/cyclone_search.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""
2+
* Copyright(c) 2022 ZettaScale Technology and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
7+
* v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
"""
12+
import os
13+
import platform
14+
from pathlib import Path
15+
from typing import List, Optional
16+
from dataclasses import dataclass
17+
18+
19+
@dataclass
20+
class FoundCycloneResult:
21+
home: Path
22+
library_path: Path
23+
include_path: Path
24+
binary_path: Path
25+
ddsc_library: Path
26+
idlc_executable: Optional[Path]
27+
idlc_library: Optional[Path]
28+
security_libs: List[Path]
29+
30+
31+
def first_or_none(alist):
32+
alist = list(alist)
33+
if alist:
34+
return alist[0]
35+
36+
37+
def good_directory(directory: Path):
38+
dir = directory.resolve()
39+
if not dir.exists():
40+
return
41+
42+
include_path = dir / 'include'
43+
bindir = dir / 'bin'
44+
45+
if not include_path.exists() or not bindir.exists():
46+
return
47+
48+
libdir = dir / 'lib'
49+
if not libdir.exists():
50+
libdir = dir / 'lib64'
51+
if not libdir.exists():
52+
return None
53+
54+
if platform.system() == 'Windows':
55+
ddsc_library = bindir / "ddsc.dll"
56+
elif platform.system() == 'Darwin':
57+
ddsc_library = libdir / "libddsc.dylib"
58+
else:
59+
ddsc_library = libdir / "libddsc.so"
60+
61+
if not ddsc_library.exists():
62+
return None
63+
64+
idlc_executable = first_or_none(bindir.glob("idlc*"))
65+
idlc_library = first_or_none(libdir.glob('libcycloneddsidl*')) or first_or_none(bindir.glob("cycloneddsidl*"))
66+
security_libs = list(libdir.glob("*dds_security_*")) + list(bindir.glob("*dds_security_*"))
67+
68+
return FoundCycloneResult(
69+
home=dir,
70+
include_path=include_path,
71+
library_path=libdir,
72+
binary_path=bindir,
73+
ddsc_library=ddsc_library,
74+
idlc_executable=idlc_executable,
75+
idlc_library=idlc_library,
76+
security_libs=security_libs
77+
)
78+
79+
80+
def search_cyclone_pathlike(pathlike, upone=False):
81+
for path in pathlike.split(os.pathsep):
82+
if upone:
83+
return good_directory(Path(path) / '..')
84+
else:
85+
return good_directory(Path(path))
86+
87+
88+
def find_cyclonedds() -> Optional[FoundCycloneResult]:
89+
if "CYCLONEDDS_HOME" in os.environ:
90+
dir = good_directory(Path(os.environ["CYCLONEDDS_HOME"]))
91+
if dir:
92+
return dir
93+
if "CycloneDDS_ROOT" in os.environ:
94+
dir = good_directory(Path(os.environ["CMAKE_CycloneDDS_ROOT"]))
95+
if dir:
96+
return dir
97+
if "CycloneDDS_ROOT" in os.environ:
98+
dir = good_directory(Path(os.environ["CycloneDDS_ROOT"]))
99+
if dir:
100+
return dir
101+
if "CMAKE_PREFIX_PATH" in os.environ:
102+
dir = search_cyclone_pathlike(os.environ["CMAKE_PREFIX_PATH"])
103+
if dir:
104+
return dir
105+
if "CMAKE_LIBRARY_PATH" in os.environ:
106+
dir = search_cyclone_pathlike(os.environ["CMAKE_LIBRARY_PATH"])
107+
if dir:
108+
return dir
109+
if platform.system() != "Windows" and "LIBRARY_PATH" in os.environ:
110+
dir = search_cyclone_pathlike(os.environ["LIBRARY_PATH"], upone=True)
111+
if dir:
112+
return dir
113+
if platform.system() != "Windows" and "LD_LIBRARY_PATH" in os.environ:
114+
dir = search_cyclone_pathlike(os.environ["LD_LIBRARY_PATH"], upone=True)
115+
if dir:
116+
return dir
117+
if platform.system() == "Windows" and "PATH" in os.environ:
118+
dir = search_cyclone_pathlike(os.environ["PATH"], upone=True)
119+
if dir:
120+
return dir
121+

cyclonedds/__idlc__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,13 @@
1010
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111
"""
1212

13-
from os import path, listdir
1413
from sys import exit
14+
from pathlib import Path
1515

1616

17-
dir = path.abspath(path.join(path.dirname(__file__), ".libs"))
18-
libs = [f for f in listdir(dir) if "idl" in f]
19-
20-
if not libs:
21-
idlpy_lib = None
22-
else:
23-
idlpy_lib = path.join(dir, libs[0])
17+
idlpy_path = list(Path(__file__).resolve().parent.glob("_idlpy*"))[0]
2418

2519

2620
if __name__ == "__main__":
27-
if not idlpy_lib:
28-
exit(1)
29-
print(idlpy_lib, end="", flush=True)
21+
print(idlpy_path, end="", flush=True)
3022
exit(0)

cyclonedds/internal.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ctypes.util import find_library
1919
from functools import wraps
2020
from dataclasses import dataclass
21+
from .__library__ import library_path, in_wheel
2122

2223

2324
class CycloneDDSLoaderException(Exception):
@@ -26,24 +27,19 @@ class CycloneDDSLoaderException(Exception):
2627

2728
def _load(path):
2829
"""Most basic loader, return the loaded DLL on path"""
29-
library = ct.CDLL(path)
30+
try:
31+
library = ct.CDLL(path)
32+
except OSError:
33+
raise CycloneDDSLoaderException(f"Failed to load CycloneDDS library from {path}")
3034
if not library:
31-
raise CycloneDDSLoaderException("Failed to load CycloneDDS library from {path}")
35+
raise CycloneDDSLoaderException(f"Failed to load CycloneDDS library from {path}")
3236
return library
3337

3438

3539
def _loader_wheel_gen(rel_path, ext):
36-
"""
37-
The tools 'auditwheel', 'delvewheel' and 'delocate' include libddsc into the Python environment in
38-
a predictable location. This location differs slightly per tool. Generate a loader given the relative
39-
path and platform-dependend extension.
40-
"""
4140
def _loader_wheel():
42-
origin = os.path.join(os.path.dirname(__file__), *rel_path)
43-
if os.path.exists(origin):
44-
for file in os.listdir(origin):
45-
if "ddsc" in file and ext in file and file.index(ext) > file.index("ddsc"):
46-
return _load(os.path.join(origin, file))
41+
if in_wheel:
42+
return _load(str(library_path))
4743
return None
4844
return _loader_wheel
4945

@@ -82,21 +78,32 @@ def _loader_on_path():
8278
return _loader_on_path
8379

8480

81+
82+
def _loader_install_path():
83+
try:
84+
return _load(str(library_path))
85+
except CycloneDDSLoaderException:
86+
pass
87+
return None
88+
8589
_loaders_per_system = {
8690
"Linux": [
8791
_loader_wheel_gen(["..", "cyclonedds.libs"], ".so"),
88-
_loader_cyclonedds_home_gen("lib/libddsc.so"),
92+
_loader_cyclonedds_home_gen(f"lib{os.sep}libddsc.so"),
8993
_loader_on_path_gen("libddsc.so"),
94+
_loader_install_path
9095
],
9196
"Windows": [
9297
_loader_wheel_gen(["..", "cyclonedds.libs"], ".dll"),
93-
_loader_cyclonedds_home_gen("bin\\ddsc.dll"),
94-
_loader_on_path_gen("ddsc.dll")
98+
_loader_cyclonedds_home_gen(f"bin{os.sep}ddsc.dll"),
99+
_loader_on_path_gen("ddsc.dll"),
100+
_loader_install_path
95101
],
96102
"Darwin": [
97103
_loader_wheel_gen([".dylibs"], ".dylib"),
98-
_loader_cyclonedds_home_gen("lib/libddsc.dylib"),
104+
_loader_cyclonedds_home_gen(f"lib{os.sep}libddsc.dylib"),
99105
_loader_on_path_gen("libddsc.dylib"),
106+
_loader_install_path
100107
]
101108
}
102109

@@ -125,7 +132,6 @@ def load_cyclonedds() -> ct.CDLL:
125132
"Try setting the CYCLONEDDS_HOME variable to what you used as CMAKE_INSTALL_PREFIX."
126133
)
127134

128-
129135
def c_call(cname):
130136
"""
131137
Decorator. Convert a function into call into the class associated dll.

cyclonedds/tools/wheel_idlc/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,33 @@
1111
1212
1313
This tool is used in wheels to perform the idlc command.
14-
The idlc binary is under cyclonedds/.bin/idlc, libs are under
14+
The idlc binary is under cyclonedds/.libs/idlc, libs are under
1515
cyclonedds/.libs.
1616
"""
1717

1818
import os
1919
import sys
2020
import platform
21-
import subprocess
2221
import cyclonedds
22+
from pathlib import Path
2323

24-
basedir = os.path.abspath(os.path.dirname(cyclonedds.__file__))
25-
idlc = os.path.join(basedir, ".bin", "idlc")
26-
if platform.system() == "Windows":
27-
idlc += ".exe"
2824

29-
libdir = os.path.join(basedir, ".libs")
25+
libdir = Path(__file__).resolve().parent / '.libs'
26+
idlc = (libdir / 'idlc.exe') if platform.system() == "Windows" else (libdir / 'idlc')
3027

3128

3229
def command():
33-
if not os.path.exists(idlc):
30+
if not idlc.exists():
3431
print("Python idlc entrypoint active but cyclonedds-python installation does not include idlc executable!")
3532
sys.exit(1)
3633

3734
environ = os.environ.copy()
3835

3936
if platform.system() == "Windows":
40-
environ["PATH"] = ";".join([libdir] + environ.get("PATH", "").split(";"))
37+
environ["PATH"] = ";".join([str(libdir)] + environ.get("PATH", "").split(";"))
4138
elif platform.system() == "Darwin":
42-
environ["DYLD_LIBRARY_PATH"] = ":".join([libdir] + environ.get("DYLD_LIBRARY_PATH", "").split(":"))
39+
environ["DYLD_LIBRARY_PATH"] = ":".join([str(libdir)] + environ.get("DYLD_LIBRARY_PATH", "").split(":"))
4340
else:
44-
environ["LD_LIBRARY_PATH"] = ":".join([libdir] + environ.get("LD_LIBRARY_PATH", "").split(":"))
41+
environ["LD_LIBRARY_PATH"] = ":".join([str(libdir)] + environ.get("LD_LIBRARY_PATH", "").split(":"))
4542

4643
os.execvpe(idlc, sys.argv[1:], environ)

0 commit comments

Comments
 (0)