Skip to content

Commit 9f4f7d5

Browse files
committed
process also all installable packages
1 parent fc38172 commit 9f4f7d5

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

src/compas_rhino/install.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,29 @@ def install(version=None, packages=None):
5656

5757
packages = _filter_installable_packages(version, packages)
5858

59-
print('Installing COMPAS packages to Rhino {0} scripts folder:'.format(version))
60-
print('{}\n'.format(scripts_path))
61-
6259
results = []
6360
symlinks_to_install = []
6461
symlinks_to_uninstall = []
6562
exit_code = 0
6663

64+
# check all installable packages
65+
# add the packages that can't be imported from the current env to the list of symlinks to uninstall
66+
# and remove the package name from the list of installable packages
67+
# make a copy of the list to avoid problems with removing items
68+
# note: perhaps this should already happen in the filter function...
69+
for name in packages[:]:
70+
try:
71+
importlib.import_module(name)
72+
except ImportError:
73+
symlink_path = os.path.join(scripts_path, name)
74+
symlinks_to_uninstall.append(dict(name=name, link=symlink_path))
75+
packages.remove(name)
76+
77+
# check all the compas packages/folders in the scripts directory
78+
# if one of them is not importable from the current env
79+
# it should be listed for un-installation
80+
# otherwise it should be added to the list of packages to install
81+
# if it wasn't already in there
6782
for name in os.listdir(scripts_path):
6883
if name.startswith('compas') and not name.endswith('.py'):
6984
try:
@@ -75,6 +90,9 @@ def install(version=None, packages=None):
7590
if name not in packages:
7691
packages.append(name)
7792

93+
# add all of the packages in the list of installable packages
94+
# to the list of symlinks to uninstall
95+
# and to the list of symlinks to install
7896
for package in packages:
7997
symlink_path = os.path.join(scripts_path, package)
8098
symlinks_to_uninstall.append(dict(name=package, link=symlink_path))
@@ -104,10 +122,21 @@ def install(version=None, packages=None):
104122
if not compas_rhino._try_remove_bootstrapper(ipylib_path):
105123
results.append(('compas_bootstrapper', 'ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.'))
106124

125+
# -------------------------
107126
# Ready to start installing
127+
# -------------------------
128+
129+
# create new symlinks and register the results
108130
symlinks = [(link['source_path'], link['link']) for link in symlinks_to_install]
109131
install_results = compas._os.create_symlinks(symlinks)
110132

133+
# set the exit code based on the installation results
134+
if not all(install_results):
135+
exit_code = -1
136+
137+
# make a list of installed packages
138+
# based on the installation results
139+
# and update the general results list
111140
installed_packages = []
112141
for install_data, success in zip(symlinks_to_install, install_results):
113142
if success:
@@ -117,9 +146,7 @@ def install(version=None, packages=None):
117146
result = 'ERROR: Cannot create symlink, try to run as administrator.'
118147
results.append((install_data['name'], result))
119148

120-
if not all(install_results):
121-
exit_code = -1
122-
149+
# finalize the general results list with info about the bootstrapper
123150
if exit_code == -1:
124151
results.append(('compas_bootstrapper', 'WARNING: One or more packages failed, will not install bootstrapper, try uninstalling first'))
125152
else:
@@ -129,9 +156,13 @@ def install(version=None, packages=None):
129156
except: # noqa: E722
130157
results.append(('compas_bootstrapper', 'ERROR: Could not create compas_bootstrapper to auto-determine Python environment'))
131158

159+
# output the outcome of the installation process
160+
# perhaps we should more info here
161+
print('Installing COMPAS packages to Rhino {0} scripts folder:'.format(version))
162+
print('{}\n'.format(scripts_path))
163+
132164
for package, status in results:
133165
print(' {} {}'.format(package.ljust(20), status))
134-
135166
if status != 'OK':
136167
exit_code = -1
137168

0 commit comments

Comments
 (0)