From 1aff91941d4de119e565bbcd4ca0296aee86cfa3 Mon Sep 17 00:00:00 2001 From: Anton Tetov Date: Tue, 1 Oct 2024 16:09:27 +0200 Subject: [PATCH] fix: compas_rhino.uninstall loops through all possible locations --- CHANGELOG.md | 2 + src/compas_rhino/uninstall.py | 69 ++++++++++++++++------------------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88a4ecdfeb2..f6173f59307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed the `__str__` of `compas.geometry.Frame`, `compas.geometry.Plane`, `compas.geometry.Polygon`, `compas.geometry.Polyhedron`, `compas.geometry.Quaternion` to use a limited number of decimals (determined by `Tolerance.PRECISION`). Note: `__repr__` will instead maintain full precision. * Changed the `__str__` of `compas.geometry.Pointcloud` to print total number of points instead of the long list of points. Note: `__repr__` will still print all the points with full precision. * Fixed bug in `Pointcloud.from_box()`. +* `compas_rhino.uninstall` will try to remove compas packages from all possible + install locations. ### Removed diff --git a/src/compas_rhino/uninstall.py b/src/compas_rhino/uninstall.py index c4307de285a..83faddde6d1 100644 --- a/src/compas_rhino/uninstall.py +++ b/src/compas_rhino/uninstall.py @@ -40,16 +40,22 @@ def uninstall(version=None, packages=None): """ version = compas_rhino._check_rhino_version(version) - if version == "8.0": - # In Rhino 8 there is no scripts folder - installation_path = compas_rhino._get_default_rhino_ironpython_sitepackages_path(version) - else: - # We install COMPAS packages in the scripts folder - # instead of directly as IPy module. - installation_path = compas_rhino._get_rhino_scripts_path(version) + installation_paths = [] + + # In Rhino <8 We install COMPAS packages in the scripts folder + # instead of directly as IPy module. + installation_paths.append(compas_rhino._get_rhino_scripts_path(version)) + + # In Rhino 8 there is no scripts folder + try: + installation_paths.append(compas_rhino._get_default_rhino_ironpython_sitepackages_path(version)) + except NotImplementedError: + pass # This is for old installs ipylib_path = compas_rhino._get_rhino_ironpython_lib_path(version) + if ipylib_path: + installation_paths.append(ipylib_path) # Filter the provided list of packages # If no packages are provided @@ -58,31 +64,26 @@ def uninstall(version=None, packages=None): # Also remove all broken symlinks # because ... they're broken! - for name in os.listdir(installation_path): - path = os.path.join(installation_path, name) - if os.path.islink(path): - if not os.path.exists(path): - if name not in packages: - packages.append(name) + for installation_path in installation_paths: + for name in os.listdir(installation_path): + path = os.path.join(installation_path, name) + if os.path.islink(path): + if not os.path.exists(path): + if name not in packages: + packages.append(name) # Collect paths for removal based on package names symlinks_to_uninstall = [] for package in packages: - symlink_path = os.path.join(installation_path, package) - symlinks_to_uninstall.append(dict(name=package, link=symlink_path)) - - # Handle legacy install location - # This does not always work, - # and especially not in cases where it is in any case not necessary :) - if ipylib_path: - legacy_path = os.path.join(ipylib_path, package) - if os.path.exists(legacy_path): - symlinks_to_uninstall.append(dict(name=package, link=legacy_path)) + for installation_path in installation_paths: + symlink_path = os.path.join(installation_path, package) + if os.path.exists(symlink_path): + symlinks_to_uninstall.append(dict(name=package, link=symlink_path)) # There is nothing to uninstall if not symlinks_to_uninstall: - print("\nNo packages to uninstall from Rhino {0} scripts folder: \n{1}.".format(version, installation_path)) + print("\nNo packages to uninstall from Rhino {0} scripts folders: \n{1}.".format(version, installation_paths)) return # ------------------------- @@ -117,7 +118,12 @@ def uninstall(version=None, packages=None): ) else: - if compas_rhino._try_remove_bootstrapper(installation_path): + bootstrapper_removed = False + for installation_path in installation_paths: + if compas_rhino._try_remove_bootstrapper(installation_path): + bootstrapper_removed = True + + if bootstrapper_removed: results.append(("compas_bootstrapper", "OK")) else: results.append( @@ -127,22 +133,11 @@ def uninstall(version=None, packages=None): ) ) - # Handle legacy bootstrapper - # Again, only if possible... - if ipylib_path: - if not compas_rhino._try_remove_bootstrapper(ipylib_path): - results.append( - ( - "compas_bootstrapper", - "ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.", - ) - ) - # ------------------------- # Output results # ------------------------- - print("Uninstalling COMPAS packages from Rhino {0} scripts folder: \n{1}".format(version, installation_path)) + print("Uninstalling COMPAS packages from Rhino {0} scripts folders: \n{1}".format(version, installation_paths)) print("\nThe following packages have been detected and will be uninstalled:\n") for package, status in results: