Skip to content

Commit 25ab547

Browse files
authored
Trying to remove the embedded version of VTK (#25)
* First try to extract VTK from the wheel * Working on removing the embedded version of VTK
1 parent 5639090 commit 25ab547

File tree

2 files changed

+95
-93
lines changed

2 files changed

+95
-93
lines changed

.github/workflows/build-wheel.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ jobs:
2121
steps:
2222

2323
# see https://github.com/marketplace/actions/download-workflow-artifact
24-
- name: Download artifact
25-
uses: dawidd6/action-download-artifact@v2
26-
if: ${{ matrix.os == 'ubuntu-22.04' }}
27-
with:
28-
workflow: build-vtk.yml
29-
path: /tmp/vtk-wheels
30-
31-
- name: List downloaded wheels
32-
if: ${{ matrix.os == 'ubuntu-22.04' }}
33-
run: |
34-
find /tmp/vtk-wheels -ls
35-
ls -ld /tmp/vtk-wheels/*-cp${{ matrix.python-version }}/vtk-*.whl
24+
# - name: Download artifact
25+
# uses: dawidd6/action-download-artifact@v2
26+
# if: ${{ matrix.os == 'ubuntu-22.04' }}
27+
# with:
28+
# workflow: build-vtk.yml
29+
# path: /tmp/vtk-wheels
30+
31+
# - name: List downloaded wheels
32+
# if: ${{ matrix.os == 'ubuntu-22.04' }}
33+
# run: |
34+
# find /tmp/vtk-wheels -ls
35+
# ls -ld /tmp/vtk-wheels/*-cp${{ matrix.python-version }}/vtk-*.whl
3636

3737
- name: Checkout project
3838
uses: actions/checkout@v2
@@ -59,6 +59,7 @@ jobs:
5959
shell: bash -l {0}
6060
run: |
6161
if [ "$RUNNER_OS" == "Linux" ]; then
62+
sudo apt update
6263
sudo apt install -y libegl1 libegl1-mesa-dev
6364
fi
6465
@@ -72,7 +73,7 @@ jobs:
7273
if: ${{ matrix.os == 'ubuntu-22.04' }}
7374
shell: bash -l {0}
7475
run: |
75-
conda install -c cadquery -n cadquery-ocp -y ocp=7.7.2.* vtk=9.2.* occt=7.7.2=all*
76+
conda install -c cadquery -n cadquery-ocp -y ocp=7.7.2.* vtk=9.2.* occt=7.7.2=all* auditwheel
7677
7778
- name: Pip Deps Setup 1
7879
shell: bash -l {0}
@@ -86,17 +87,16 @@ jobs:
8687
run: |
8788
pip install auditwheel patchelf
8889
89-
- name: Manylinux Build 1
90-
shell: bash -l {0}
91-
if: ${{ matrix.os == 'ubuntu-22.04' }}
92-
run: |
93-
export VTK_MANYLINUX=/tmp/vtk-manylinux
94-
pip install -t $VTK_MANYLINUX --no-deps /tmp/vtk-wheels/*-cp${{ matrix.python-version }}/vtk-*.whl
95-
python -m build --no-isolation --wheel
90+
# - name: Manylinux Build 1
91+
# shell: bash -l {0}
92+
# if: ${{ matrix.os == 'ubuntu-22.04' }}
93+
# run: |
94+
# export VTK_MANYLINUX=/tmp/vtk-manylinux
95+
# pip install -t $VTK_MANYLINUX --no-deps /tmp/vtk-wheels/*-cp${{ matrix.python-version }}/vtk-*.whl
96+
# python -m build --no-isolation --wheel
9697

9798
- name: Conda-only Build
9899
shell: bash -l {0}
99-
if: ${{ matrix.os != 'ubuntu-22.04' }}
100100
run: |
101101
python -m build --no-isolation --wheel
102102
@@ -113,6 +113,7 @@ jobs:
113113
conda deactivate
114114
conda create --yes -n cadquerytest python=${{ matrix.python-version }}
115115
conda activate cadquerytest
116+
ls dist/*
116117
pip install dist/*.whl
117118
python -c "import OCP;print('OCP imported successfully')"
118119

setup.py

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -55,54 +55,54 @@
5555
import zipfile
5656

5757

58-
VTK_MANYLINUX = None
59-
if platform.system() == "Linux" and os.getenv("VTK_MANYLINUX"):
60-
VTK_MANYLINUX = pathlib.Path(os.getenv("VTK_MANYLINUX")).resolve()
61-
if not (VTK_MANYLINUX / "vtkmodules" / "__init__.py").exists():
62-
raise Exception(f"invalid VTK_MANYLINUX: {VTK_MANYLINUX}")
63-
64-
65-
def populate_lib_dir(conda_prefix, vtk_manylinux, out_dir):
66-
"""Merge non-vtk conda libs and vtk manylinux libs into a single directory"""
67-
68-
conda_prefix = pathlib.Path(conda_prefix)
69-
vtk_manylinux = pathlib.Path(vtk_manylinux)
70-
out_dir = pathlib.Path(out_dir)
71-
72-
fns = list((conda_prefix / "conda-meta").glob("vtk-9*-qt_*.json"))
73-
if len(fns) != 1:
74-
raise Exception(f"could not find unique vtk meta: {fns}")
75-
vtk_meta = json.loads(fns[0].read_text())
76-
vtk_files = {conda_prefix / f for f in vtk_meta["files"]}
77-
78-
# Do not copy regular VTK files because we will use manylinux
79-
# files instead. Do copy VTK symlinks because they're expected by
80-
# other conda packages which we may bundle into the wheel.
81-
vtk_skipped_files = []
82-
for f in (conda_prefix / "lib").iterdir():
83-
if f.is_dir():
84-
continue
85-
if f in vtk_files and not f.is_symlink():
86-
vtk_skipped_files.append(f)
87-
else:
88-
shutil.copy2(f, out_dir, follow_symlinks=False)
89-
90-
# Copy VTK files. Symlinks in the target will be followed so we
91-
# are fixing broken symlinks.
92-
for f in (vtk_manylinux / "vtkmodules").glob("lib*.so*"):
93-
shutil.copy2(f, out_dir, follow_symlinks=False)
94-
95-
# The VTK manylinux wheel may not provide all the libraries of the
96-
# VTK conda pkg, so there may be missing files or broken symlinks.
97-
# If this is problematic then auditwheel will fail. For now,
98-
# print some helpful information.
99-
for f in vtk_skipped_files:
100-
if not (out_dir / f.name).exists():
101-
print("manylinux whl did not provide:", f)
102-
103-
# Copy the rest of the libraries bundled in the VTK wheel.
104-
for f in (vtk_manylinux / "vtk.libs").glob("lib*.so*"):
105-
shutil.copy2(f, out_dir, follow_symlinks=False)
58+
# VTK_MANYLINUX = None
59+
# if platform.system() == "Linux" and os.getenv("VTK_MANYLINUX"):
60+
# VTK_MANYLINUX = pathlib.Path(os.getenv("VTK_MANYLINUX")).resolve()
61+
# if not (VTK_MANYLINUX / "vtkmodules" / "__init__.py").exists():
62+
# raise Exception(f"invalid VTK_MANYLINUX: {VTK_MANYLINUX}")
63+
64+
65+
# def populate_lib_dir(conda_prefix, vtk_manylinux, out_dir):
66+
# """Merge non-vtk conda libs and vtk manylinux libs into a single directory"""
67+
68+
# conda_prefix = pathlib.Path(conda_prefix)
69+
# vtk_manylinux = pathlib.Path(vtk_manylinux)
70+
# out_dir = pathlib.Path(out_dir)
71+
72+
# fns = list((conda_prefix / "conda-meta").glob("vtk-9*-qt_*.json"))
73+
# if len(fns) != 1:
74+
# raise Exception(f"could not find unique vtk meta: {fns}")
75+
# vtk_meta = json.loads(fns[0].read_text())
76+
# vtk_files = {conda_prefix / f for f in vtk_meta["files"]}
77+
78+
# # Do not copy regular VTK files because we will use manylinux
79+
# # files instead. Do copy VTK symlinks because they're expected by
80+
# # other conda packages which we may bundle into the wheel.
81+
# vtk_skipped_files = []
82+
# for f in (conda_prefix / "lib").iterdir():
83+
# if f.is_dir():
84+
# continue
85+
# if f in vtk_files and not f.is_symlink():
86+
# vtk_skipped_files.append(f)
87+
# else:
88+
# shutil.copy2(f, out_dir, follow_symlinks=False)
89+
90+
# # Copy VTK files. Symlinks in the target will be followed so we
91+
# # are fixing broken symlinks.
92+
# for f in (vtk_manylinux / "vtkmodules").glob("lib*.so*"):
93+
# shutil.copy2(f, out_dir, follow_symlinks=False)
94+
95+
# # The VTK manylinux wheel may not provide all the libraries of the
96+
# # VTK conda pkg, so there may be missing files or broken symlinks.
97+
# # If this is problematic then auditwheel will fail. For now,
98+
# # print some helpful information.
99+
# for f in vtk_skipped_files:
100+
# if not (out_dir / f.name).exists():
101+
# print("manylinux whl did not provide:", f)
102+
103+
# # Copy the rest of the libraries bundled in the VTK wheel.
104+
# for f in (vtk_manylinux / "vtk.libs").glob("lib*.so*"):
105+
# shutil.copy2(f, out_dir, follow_symlinks=False)
106106

107107

108108
class copy_installed(setuptools.command.build_ext.build_ext):
@@ -116,22 +116,22 @@ def build_extension(self, ext):
116116
# OCP is a single-file extension; just copy it
117117
shutil.copy(OCP.__file__, self.build_lib)
118118
# vtkmodules is a package; copy it while excluding __pycache__
119-
if VTK_MANYLINUX:
120-
# Copy python source files and python extensions, but not
121-
# shared libraries. We will point auditwheel to them
122-
# separately to be bundled in.
123-
shutil.copytree(
124-
os.path.join(VTK_MANYLINUX, "vtkmodules"),
125-
os.path.join(self.build_lib, "vtkmodules"),
126-
ignore=shutil.ignore_patterns("__pycache__", "libvtk*.so*"),
127-
)
128-
else:
129-
assert vtkmodules.__file__.endswith(os.path.join(os.sep, "vtkmodules", "__init__.py"))
130-
shutil.copytree(
131-
os.path.dirname(vtkmodules.__file__),
132-
os.path.join(self.build_lib, "vtkmodules"),
133-
ignore=shutil.ignore_patterns("__pycache__"),
134-
)
119+
# if VTK_MANYLINUX:
120+
# # Copy python source files and python extensions, but not
121+
# # shared libraries. We will point auditwheel to them
122+
# # separately to be bundled in.
123+
# shutil.copytree(
124+
# os.path.join(VTK_MANYLINUX, "vtkmodules"),
125+
# os.path.join(self.build_lib, "vtkmodules"),
126+
# ignore=shutil.ignore_patterns("__pycache__", "libvtk*.so*"),
127+
# )
128+
# else:
129+
# assert vtkmodules.__file__.endswith(os.path.join(os.sep, "vtkmodules", "__init__.py"))
130+
# shutil.copytree(
131+
# os.path.dirname(vtkmodules.__file__),
132+
# os.path.join(self.build_lib, "vtkmodules"),
133+
# ignore=shutil.ignore_patterns("__pycache__"),
134+
# )
135135

136136

137137
class bdist_wheel_repaired(wheel.bdist_wheel.bdist_wheel):
@@ -163,12 +163,12 @@ def run(self):
163163
out_dir = os.path.join(self.dist_dir, "repaired")
164164
system = platform.system()
165165
if system == "Linux":
166-
if VTK_MANYLINUX:
167-
# Create a lib dir with VTK manylinux files merged in,
168-
# and point auditwheel to it.
169-
merged_lib_dir = tempfile.mkdtemp()
170-
populate_lib_dir(conda_prefix, VTK_MANYLINUX, merged_lib_dir)
171-
lib_path = merged_lib_dir
166+
# if VTK_MANYLINUX:
167+
# # Create a lib dir with VTK manylinux files merged in,
168+
# # and point auditwheel to it.
169+
# merged_lib_dir = tempfile.mkdtemp()
170+
# populate_lib_dir(conda_prefix, VTK_MANYLINUX, merged_lib_dir)
171+
# lib_path = merged_lib_dir
172172
repair_wheel_linux(lib_path, bad_whl, out_dir)
173173
elif system == "Darwin":
174174
repair_wheel_macos(lib_path, bad_whl, out_dir)
@@ -272,7 +272,7 @@ def add_licenses_bundled(conda_prefix, whl, added_files):
272272
with open(os.path.join(dist_info,"LICENSES_bundled"), "w") as f:
273273
f.write("This wheel distribution bundles a number of libraries that\n")
274274
f.write("are compatibly licensed. We list them here.\n")
275-
write_licenses(conda_prefix, whl, ["ocp", "vtk"], added_files, f)
275+
write_licenses(conda_prefix, whl, ["ocp"], added_files, f) # , "vtk"
276276

277277
subprocess.check_call(["wheel", "pack", "-d", os.path.dirname(whl), os.path.dirname(dist_info)])
278278

@@ -378,7 +378,7 @@ def try_unmangle(n):
378378
setup(
379379
name="cadquery-ocp",
380380
version=wheel_version,
381-
description="OCP+VTK wheel with shared library dependencies bundled.",
381+
description="OCP wheel with shared library dependencies bundled.",
382382
long_description=open("README.md").read(),
383383
long_description_content_type='text/markdown',
384384
author="adam-urbanczyk, fp473 (wheel generation), roipoussiere (wheel generation)",
@@ -396,6 +396,7 @@ def try_unmangle(n):
396396
"Topic :: Software Development :: Libraries :: Python Modules",
397397
"Topic :: Scientific/Engineering"
398398
],
399+
install_requires=["vtk"],
399400
# Dummy extension to trigger build_ext
400401
ext_modules=[Extension("__dummy__", sources=[])],
401402
cmdclass={"bdist_wheel": bdist_wheel_repaired, "build_ext": copy_installed},

0 commit comments

Comments
 (0)