Skip to content

Commit 256f6da

Browse files
authored
Merge pull request #1383 from tetov/rhino_8_uninstall_update
compas_rhino.uninstall updated for ipy rhino8
2 parents 98a43e2 + 172f977 commit 256f6da

3 files changed

Lines changed: 34 additions & 36 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
* Renamed `Tolerance.units` to `Tolerance.unit` to better reflect the documented properties. Left `units` with deprecation warning.
2222
* Fixed `NotImplementedErorr` when calling `BrepLoop.vertices`.
2323
* Fixed `python -m compas` to detect extensions based on `importlib` rather than `pkg_resources`.
24+
* `compas_rhino.uninstall` will try to remove compas packages from all possible install locations.
2425

2526
### Removed
2627

‎src/compas_rhino/install.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ def install(version=None, packages=None, clean=False):
4343
"""
4444
version = compas_rhino._check_rhino_version(version)
4545

46-
# We install COMPAS packages in the scripts folder
47-
# instead of directly as IPy module.
48-
# scripts_path = compas_rhino._get_rhino_scripts_path(version)
49-
5046
if version == "8.0":
5147
raise ValueError("Installing to Rhino8 using this script is no longer supported. See https://compas.dev/compas/latest/userguide/cad.rhino8.html")
5248
else:
49+
# We install COMPAS packages in the scripts folder
50+
# instead of directly as IPy module.
5351
installation_path = compas_rhino._get_rhino_scripts_path(version)
5452

5553
# This is for old installs

‎src/compas_rhino/uninstall.py‎

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ def uninstall(version=None, packages=None):
4040
"""
4141
version = compas_rhino._check_rhino_version(version)
4242

43-
# We install COMPAS packages in the scripts folder
43+
installation_paths = []
44+
45+
# In Rhino <8 We install COMPAS packages in the scripts folder
4446
# instead of directly as IPy module.
45-
scripts_path = compas_rhino._get_rhino_scripts_path(version)
47+
installation_paths.append(compas_rhino._get_rhino_scripts_path(version))
48+
49+
# In Rhino 8 there is no scripts folder
50+
try:
51+
installation_paths.append(compas_rhino._get_default_rhino_ironpython_sitepackages_path(version))
52+
except NotImplementedError:
53+
pass
4654

4755
# This is for old installs
4856
ipylib_path = compas_rhino._get_rhino_ironpython_lib_path(version)
57+
if ipylib_path:
58+
installation_paths.append(ipylib_path)
4959

5060
# Filter the provided list of packages
5161
# If no packages are provided
@@ -54,31 +64,26 @@ def uninstall(version=None, packages=None):
5464

5565
# Also remove all broken symlinks
5666
# because ... they're broken!
57-
for name in os.listdir(scripts_path):
58-
path = os.path.join(scripts_path, name)
59-
if os.path.islink(path):
60-
if not os.path.exists(path):
61-
if name not in packages:
62-
packages.append(name)
67+
for installation_path in installation_paths:
68+
for name in os.listdir(installation_path):
69+
path = os.path.join(installation_path, name)
70+
if os.path.islink(path):
71+
if not os.path.exists(path):
72+
if name not in packages:
73+
packages.append(name)
6374

6475
# Collect paths for removal based on package names
6576
symlinks_to_uninstall = []
6677

6778
for package in packages:
68-
symlink_path = os.path.join(scripts_path, package)
69-
symlinks_to_uninstall.append(dict(name=package, link=symlink_path))
70-
71-
# Handle legacy install location
72-
# This does not always work,
73-
# and especially not in cases where it is in any case not necessary :)
74-
if ipylib_path:
75-
legacy_path = os.path.join(ipylib_path, package)
76-
if os.path.exists(legacy_path):
77-
symlinks_to_uninstall.append(dict(name=package, link=legacy_path))
79+
for installation_path in installation_paths:
80+
symlink_path = os.path.join(installation_path, package)
81+
if os.path.exists(symlink_path):
82+
symlinks_to_uninstall.append(dict(name=package, link=symlink_path))
7883

7984
# There is nothing to uninstall
8085
if not symlinks_to_uninstall:
81-
print("\nNo packages to uninstall from Rhino {0} scripts folder: \n{1}.".format(version, scripts_path))
86+
print("\nNo packages to uninstall from Rhino {0} scripts folders: \n{1}.".format(version, installation_paths))
8287
return
8388

8489
# -------------------------
@@ -113,7 +118,12 @@ def uninstall(version=None, packages=None):
113118
)
114119

115120
else:
116-
if compas_rhino._try_remove_bootstrapper(scripts_path):
121+
bootstrapper_removed = False
122+
for installation_path in installation_paths:
123+
if compas_rhino._try_remove_bootstrapper(installation_path):
124+
bootstrapper_removed = True
125+
126+
if bootstrapper_removed:
117127
results.append(("compas_bootstrapper", "OK"))
118128
else:
119129
results.append(
@@ -123,22 +133,11 @@ def uninstall(version=None, packages=None):
123133
)
124134
)
125135

126-
# Handle legacy bootstrapper
127-
# Again, only if possible...
128-
if ipylib_path:
129-
if not compas_rhino._try_remove_bootstrapper(ipylib_path):
130-
results.append(
131-
(
132-
"compas_bootstrapper",
133-
"ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.",
134-
)
135-
)
136-
137136
# -------------------------
138137
# Output results
139138
# -------------------------
140139

141-
print("Uninstalling COMPAS packages from Rhino {0} scripts folder: \n{1}".format(version, scripts_path))
140+
print("Uninstalling COMPAS packages from Rhino {0} scripts folders: \n{1}".format(version, installation_paths))
142141
print("\nThe following packages have been detected and will be uninstalled:\n")
143142

144143
for package, status in results:

0 commit comments

Comments
 (0)