def copy_packages_to_userobjects(directory): """Copy Ladybug Tools user object packages to the current user's userobject folder. Args: directory: The path to a directory that contains the Ladybug Tools Grasshopper python packages to be copied. """ uo_folders = find_grasshopper_userobjects() for uo_folder in uo_folders: for pkg in PACKAGES: lib_folder = os.path.join(directory, pkg) dest_folder = os.path.join(uo_folder, pkg) if os.path.isdir(lib_folder): copy_file_tree(lib_folder, dest_folder, True) print('UserObjects copied to: {}'.format(dest_folder))
def copy_packages_to_libraries(directory): """Copy Ladybug tools Libraries packages to the current user's libraries folder. Args: directory: The path to a directory that contains the Ladybug Tools Grasshopper python packages. """ lib_folders = find_grasshopper_libraries() for lib_folder in lib_folders: for pkg in DOTNET_PACKAGES: src_folder = os.path.join(directory, pkg) dest_folder = os.path.join(lib_folder, pkg) if os.path.isdir(src_folder): copy_file_tree(src_folder, dest_folder, True) print('Components copied to: {}'.format(dest_folder))
def write_inputs_json(self, project_folder=None, indent=4, cpu_count=None): """Write the inputs.json file that gets passed to queenbee luigi. Note that running this method will automatically handle all of the inputs. Args: project_folder: The full path to where the inputs json file will be written. If None, the default_project_folder on this recipe will be used. indent: The indent at which the JSON will be written (Default: 4). cpu_count: An optional integer to override any inputs that are named "cpu-count". This can be used to coordinate such recipe inputs with the number of workers specified in recipe settings. If None, no overriding will happen. (Default: None). """ # create setup the project folder in which the inputs json will be written p_fold = project_folder if project_folder else self.default_project_folder if not os.path.isdir(p_fold): preparedir(p_fold) file_path = os.path.join(p_fold, '{}_inputs.json'.format(self.simulation_id)) # create the inputs dictionary, ensuring all inputs are handled in the process inp_dict = {} for inp in self.inputs: inp.handle_value() if inp.is_path and inp.value is not None and inp.value != '': # copy artifact to project folder path_basename = os.path.basename(inp.value) dest = os.path.join(p_fold, path_basename) if os.path.isfile(inp.value): try: shutil.copyfile(inp.value, dest) except shutil.SameFileError: pass # the file is already in the right place; no need to copy elif os.path.isdir(inp.value): copy_file_tree(inp.value, dest, overwrite=True) inp_dict[inp.name] = path_basename elif inp.is_path and (inp.value is None or inp.value == ''): # conditional artifact; ignore it pass elif inp.name == 'cpu-count' and cpu_count is not None: inp_dict[inp.name] = cpu_count else: inp_dict[inp.name] = inp.value # write the inputs dictionary to a file with open(file_path, 'w') as fp: json.dump(inp_dict, fp, indent=indent) return file_path
def copy_packages_to_rhino_scripts(python_package_dir, directory=None): """Copy Ladybug tools packages into a directory. Args: python_package_dir: The path to a directory that contains the Ladybug Tools core libraries. directory: The directory into which the packages will be copied. If None, the function will search for all installed copies of the current user's Rhino scripts folder. """ folders = find_installed_rhino_scripts() if directory is None else [ directory ] for fold in folders: for pkg in PACKAGES: lib_folder = os.path.join(python_package_dir, pkg) dest_folder = os.path.join(fold, pkg) if os.path.isdir(lib_folder): copy_file_tree(lib_folder, dest_folder, True) print('Python packages copied to: {}'.format(dest_folder))
remove_dist_info_files(recipe_dir) # remove the dist-info files else: give_warning(ghenv.Component, stderr) print(stderr) # install the honeybee-openstudio ruby gem gem_ver = ver_dict['honeybee-openstudio-gem'] print('Installing Honeybee-OpenStudio gem version {}.'.format(gem_ver)) gem_dir = get_gem_directory() base_folder = download_repo_github('honeybee-openstudio-gem', gem_dir, gem_ver) source_folder = os.path.join(base_folder, 'lib') lib_folder = os.path.join(gem_dir, 'honeybee_openstudio_gem', 'lib') print('Copying "honeybee_openstudio_gem" source code to {}\n '.format( lib_folder)) copy_file_tree(source_folder, lib_folder) nukedir(base_folder, True) # always update the honeybee-energy-standards package print('Installing Honeybee energy standards.') stand_dir = get_standards_directory() hes_ver = ver_dict['honeybee-energy-standards'] if os.path.isdir(os.path.join(stand_dir, 'honeybee_energy_standards')): nukedir(os.path.join(stand_dir, 'honeybee_energy_standards'), True) stderr = update_libraries_pip(py_exe, 'honeybee-energy-standards', hes_ver, stand_dir) if os.path.isdir( os.path.join( stand_dir, 'honeybee_energy_standards-{}.dist-info'.format(hes_ver))): print('Honeybee energy standards successfully installed!\n ')
def change_installed_version(version_to_install=None): """Change the currently installed version of Ladybug Tools. This requires an internet connection and will update all core libraries and Grasshopper components to the specified version_to_install. Args: version_to_install: An optional text string for the version of the LBT plugin to be installed. The input should contain only integers separated by two periods (eg. 1.0.0). If None, the Ladybug Tools plugin shall be updated to the latest available version. The version specified here does not need to be newer than the current installation and can be older but grasshopper plugin versions less than 0.3.0 are not supported. A list of all versions of the Grasshopper plugin can be found here - https://github.com/ladybug-tools/lbt-grasshopper/releases """ # ensure that Python has been installed in the ladybug_tools folder py_exe, py_lib = folders.python_exe_path, folders.python_package_path assert py_exe is not None and py_lib is not None, \ 'No valid Python installation was found at: {}.\nThis is a requirement in ' \ 'order to continue with installation'.format( os.path.join(folders.ladybug_tools_folder, 'python')) # get the compatible versions of all the dependencies temp_folder = os.path.join(folders.ladybug_tools_folder, 'temp') lbt_gh_folder = download_repo_github('lbt-grasshopper', temp_folder, version_to_install) ver_dict = parse_lbt_gh_versions(lbt_gh_folder) if version_to_install is None: version_to_install = latest_github_version('lbt-grasshopper', temp_folder) ver_dict['lbt-grasshopper'] = version_to_install # install the core libraries print('Installing Ladybug Tools core Python libraries.') config_dict = get_config_dict( ) # load configs so they can be put back after update df_ver = ver_dict['lbt-dragonfly'] stderr = update_libraries_pip(py_exe, 'lbt-dragonfly', df_ver) if os.path.isdir( os.path.join(py_lib, 'lbt_dragonfly-{}.dist-info'.format(df_ver))): print('Ladybug Tools core Python libraries successfully installed!\n ') else: print(stderr) set_config_dict(config_dict) # restore the previous configurations # install the lbt_recipes package print('Installing Ladybug Tools Recipes.') rec_ver = ver_dict['lbt-recipes'] stderr = update_libraries_pip(py_exe, 'lbt-recipes', rec_ver) if os.path.isdir( os.path.join(py_lib, 'lbt_recipes-{}.dist-info'.format(rec_ver))): print('Ladybug Tools Recipes successfully installed!\n ') else: print(stderr) # install the library needed for interaction with Rhino print('Installing ladybug-rhino Python library.') rh_ver = ver_dict['ladybug-rhino'] stderr = update_libraries_pip(py_exe, 'ladybug-rhino', rh_ver) if os.path.isdir( os.path.join(py_lib, 'ladybug_rhino-{}.dist-info'.format(rh_ver))): print('Ladybug-rhino Python library successfully installed!\n ') else: print(stderr) # make sure libraries are copied to the rhino scripts folder on Mac if os.name != 'nt': iron_python_search_path(create_python_package_dir()) # install the grasshopper components print('Installing Ladybug Tools Grasshopper components.') gh_ver = ver_dict['lbt-grasshopper'] stderr = update_libraries_pip(py_exe, 'lbt-grasshopper', gh_ver, UO_DIRECTORY) lb_gh_ver = ver_dict['ladybug-grasshopper'] lb_gh_info = 'ladybug_grasshopper-{}.dist-info'.format(lb_gh_ver) if os.path.isdir(os.path.join(UO_DIRECTORY, lb_gh_info)): print( 'Ladybug Tools Grasshopper components successfully installed!\n ') remove_dist_info_files(UO_DIRECTORY) # remove the .dist-info files else: print(stderr) if version_to_install is not None: update_requirements_version(UO_DIRECTORY, version_to_install) # install the .gha Grasshopper components gha_location = os.path.join(GHA_DIRECTORY, 'ladybug_grasshopper_dotnet') if os.path.isdir(gha_location): msg = '.gha files already exist in your Components folder and cannot be ' \ 'deleted while Grasshopper is open.\nThese .gha files rarely change ' \ 'and so it is not critical that they be updated. However, if you ' \ 'want to be sure that you have the latest version installed, then close ' \ 'Grasshopper, delete the ladybug_grasshopper_dotnet folder at\n{}\nand ' \ 'rerun this versioner component to get the new .gha files.\n'.format( gha_location) print(msg) else: gha_ver = ver_dict['ladybug-grasshopper-dotnet'] stderr = update_libraries_pip(py_exe, 'ladybug-grasshopper-dotnet', gha_ver, GHA_DIRECTORY) package_dir = os.path.join( GHA_DIRECTORY, 'ladybug_grasshopper_dotnet-{}.dist-info'.format(gha_ver)) if os.path.isdir(package_dir): print( 'Ladybug Tools .gha Grasshopper components successfully installed!\n ' ) remove_dist_info_files(GHA_DIRECTORY) # remove the dist-info files else: print(stderr) # install the honeybee-openstudio ruby gem gem_ver = ver_dict['honeybee-openstudio-gem'] print('Installing Honeybee-OpenStudio gem version {}.'.format(gem_ver)) gem_dir = get_gem_directory() base_folder = download_repo_github('honeybee-openstudio-gem', gem_dir, gem_ver) source_folder = os.path.join(base_folder, 'lib') lib_folder = os.path.join(gem_dir, 'honeybee_openstudio_gem', 'lib') print('Copying "honeybee_openstudio_gem" source code to {}\n '.format( lib_folder)) copy_file_tree(source_folder, lib_folder) nukedir(base_folder, True) # install the lbt-measures ruby gem mea_ver = ver_dict['lbt-measures'] print('Installing Ladybug Tools Measures version {}.'.format(mea_ver)) base_folder = download_repo_github('lbt-measures', gem_dir, mea_ver) source_folder = os.path.join(base_folder, 'lib') print('Copying "lbt_measures" source code to {}\n '.format(gem_dir)) copy_file_tree(source_folder, gem_dir) nukedir(base_folder, True) # always update the honeybee-energy-standards package print('Installing Honeybee energy standards.') stand_dir = get_standards_directory() hes_ver = ver_dict['honeybee-energy-standards'] if os.path.isdir(os.path.join(stand_dir, 'honeybee_energy_standards')): nukedir(os.path.join(stand_dir, 'honeybee_energy_standards'), True) stderr = update_libraries_pip(py_exe, 'honeybee-energy-standards', hes_ver, stand_dir) hes_info = 'honeybee_energy_standards-{}.dist-info'.format(hes_ver) if os.path.isdir(os.path.join(stand_dir, hes_info)): print('Honeybee energy standards successfully installed!\n ') remove_dist_info_files(stand_dir) # remove the dist-info files else: print(stderr) # delete the temp folder and give a completion message nukedir(temp_folder, True) version = 'LATEST' if version_to_install is None else version_to_install success_msg = 'Change to Version {} Successful!'.format(version) restart_msg = 'RESTART RHINO to load the new components + library.' sync_msg = 'The "LB Sync Grasshopper File" component can be used\n' \ 'to sync Grasshopper definitions with your new installation.' for msg in (success_msg, restart_msg, sync_msg): print(msg)