def install(version='5.0', packages=None): """Install COMPAS for Rhino. Parameters ---------- version : {'5.0', '6.0'} The version number of Rhino. packages : list of str List of packages to install or None to use default package list. Examples -------- .. code-block:: python >>> import compas_rhino >>> compas_rhino.install('5.0') .. code-block:: python $ python -m compas_rhino.install 5.0 """ print('Installing COMPAS packages to Rhino IronPython lib:') ipylib_path = compas_rhino._get_ironpython_lib_path(version) results = [] exit_code = 0 for package in packages: base_path = _get_package_path(importlib.import_module(package)) package_path = os.path.join(base_path, package) symlink_path = os.path.join(ipylib_path, package) if os.path.exists(symlink_path): results.append(( package, 'ERROR: Package "{}" already found in Rhino lib, try uninstalling first' .format(package))) continue try: create_symlink(package_path, symlink_path) results.append((package, 'OK')) except OSError: results.append( (package, 'Cannot create symlink, try to run as administrator.')) for package, status in results: print(' {} {}'.format(package.ljust(20), status)) if status is not 'OK': exit_code = -1 print('\nCompleted.') sys.exit(exit_code)
def install(version=None, packages=None): """Install COMPAS for Rhino. Parameters ---------- version : {'5.0', '6.0'}, optional The version number of Rhino. Default is ``'6.0'``. packages : list of str, optional List of packages to install or None to use default package list. Default is ``['compas', 'compas_rhino', 'compas_ghpython']``. Examples -------- .. code-block:: python >>> import compas_rhino >>> compas_rhino.install('6.0') .. code-block:: python $ python -m compas_rhino.install -v 6.0 """ if version not in ('5.0', '6.0'): version = '6.0' if system == 'win32': print('Installing COMPAS packages to Rhino {0} IronPython lib:'.format(version)) elif system == 'darwin': print('Installing COMPAS packages to Rhino IronPython lib.') if not packages: packages = INSTALLABLE_PACKAGES ipylib_path = compas_rhino._get_ironpython_lib_path(version) results = [] exit_code = 0 for package in packages: package_path = _get_package_path(importlib.import_module(package)) symlink_path = os.path.join(ipylib_path, package) if os.path.exists(symlink_path): try: remove_symlink(symlink_path) except OSError: results.append((package, 'ERROR: Cannot remove symlink, try to run as administrator.')) try: create_symlink(package_path, symlink_path) results.append((package, 'OK')) except OSError: results.append((package, 'ERROR: Cannot create symlink, try to run as administrator.')) for _, status in results: if status is not 'OK': exit_code = -1 if exit_code == -1: results.append(('compas_bootstrapper', 'WARNING: One or more packages failed, will not install bootstrapper, try uninstalling first')) else: # Take either the CONDA environment directory or the current Python executable's directory python_directory = os.environ.get('CONDA_PREFIX', None) or os.path.dirname(sys.executable) environment_name = os.environ.get('CONDA_DEFAULT_ENV', '') compas_bootstrapper = os.path.join(ipylib_path, 'compas_bootstrapper.py') try: bootstrapper_data = _get_bootstrapper_data(compas_bootstrapper) installed_packages = bootstrapper_data.get('INSTALLED_PACKAGES', []) installed_packages = list(set(installed_packages + list(packages))) with open(compas_bootstrapper, 'w') as f: f.write('ENVIRONMENT_NAME = r"{}"\n'.format(environment_name)) f.write('PYTHON_DIRECTORY = r"{}"\n'.format(python_directory)) f.write('INSTALLED_PACKAGES = {}'.format(repr(installed_packages))) results.append(('compas_bootstrapper', 'OK')) except: results.append(('compas_bootstrapper', 'ERROR: Could not create compas_bootstrapper to auto-determine Python environment')) for package, status in results: print(' {} {}'.format(package.ljust(20), status)) if status is not 'OK': exit_code = -1 print('\nCompleted.') sys.exit(exit_code)
def install_plugin(plugin, version=None): """Install a Rhino Python Command Plugin. Parameters ---------- plugin : str The path to the plugin folder. version : str, optional The version of Rhino for which the plugin should be installed. Default is ``'6.0'``. Notes ----- The version info is only relevant for Rhino on Windows. The function creates an *editable install*, which means that the plugin folder is *symlinked* into the correct location so Rhino can find and load it. The contents of the source folder can still be edited and next time you start Rhino those canges will be reflected in the loaded plugin. Examples -------- Assuming the plugin folder is at the following location on your computer .. code-block:: none ~/Code/compas_xxx/ui/XXX{520ddb34-e56d-4a37-9c58-1da10edd1d62} It can be installed with the following command .. code-block:: bash $ cd ~/Code/compas_xxx/ui $ python -m compas_rhino.install_plugin XXX{520ddb34-e56d-4a37-9c58-1da10edd1d62} """ if version not in ('5.0', '6.0'): version = '6.0' plugin_path, plugin_name = os.path.split(plugin) if not plugin_path: plugin_path = os.getcwd() source = os.path.join(plugin_path, plugin_name) if not os.path.isdir(source): raise Exception('Cannot find the plugin: {}'.format(source)) if not os.path.isdir(os.path.join(source, 'dev')): raise Exception('The plugin does not contain a dev folder.') if not os.path.isfile(os.path.join(source, 'dev', '__plugin__.py')): raise Exception('The plugin does not contain plugin info.') python_plugins_path = compas_rhino._get_python_plugins_path(version) if not os.path.exists(python_plugins_path): os.mkdir(python_plugins_path) destination = os.path.join(python_plugins_path, plugin_name) print('Installing PlugIn {} to Rhino PythonPlugIns.'.format(plugin_name)) if os.path.exists(destination): remove_symlink(destination) create_symlink(source, destination) print('PlugIn {} Installed.'.format(plugin_name)) print() print('Restart Rhino and open the Python editor at least once to make it available.')