remote = Remote() # Log in remote.setup(config.remote) # Get remote python session remote_python = remote.start_python_session(assume_pts=False) # Get all python packages installed on the remote host remote_packages = remote_python.installed_packages # Get local python package version local_packages = introspection.installed_python_packages() # Loop over all python packages necessary for PTS for dependency in introspection.get_all_dependencies(): # Skip standard modules if introspection.is_std_lib(dependency): continue # Check present and version locally if dependency in local_packages: locally_present = True local_version = local_packages[dependency] else: # Check again for present by importing locally_present = introspection.is_present_package(dependency) local_version = None # Check present and version remotely if dependency in remote_packages:
action="store_true", help="show import packages from the python standard library") parser.add_argument("-v", "--version", action="store_true", help="show the version numbers of the required packages") # Parse the command line arguments arguments = parser.parse_args() # ----------------------------------------------------------------- # If no script name is given, execute the "list_dependencies.py" script to list all dependencies of PTS and the # PTS modules that use them if arguments.script is None: dependencies = introspection.get_all_dependencies() else: scripts = introspection.get_scripts() tables = introspection.get_arguments_tables() # Find matching 'do' commands (actuall scripts or tabulated commands) matches = introspection.find_matches_scripts(arguments.script, scripts) table_matches = introspection.find_matches_tables(arguments.script, tables) # List the dependencies of the matching script dependencies = defaultdict(set) # No match if len(matches) + len(table_matches) == 0:
def get_dependencies(self): """ This function ... :return: """ # If no script name is given, list all dependencies of PTS and the # PTS modules that use them if self.config.script is None: if self.config.subprojects: self.dependencies = defaultdict(set) directories_for_subproject = defaultdict(list) # Loop over the subdirectories of the 'do' directory for path, name in fs.directories_in_path( introspection.pts_do_dir, returns=["path", "name"]): subproject = name directories_for_subproject[subproject].append(path) # Loop over the other directories in 'pts' (other than 'do' and 'doc') for path, name in fs.directories_in_path( introspection.pts_package_dir, returns=["path", "name"], exact_not_name=["do", "doc"]): subproject = name directories_for_subproject[subproject].append(path) encountered_internal_modules = set() for subproject in directories_for_subproject: # print(subproject, directories_for_subproject[subproject]) # List the dependencies of the matching script dependencies_for_this = defaultdict(set) for dir_path in directories_for_subproject[subproject]: for file_path in fs.files_in_path(dir_path, extension="py", recursive=True): # if subproject == "dustpedia": print(file_path) introspection.add_dependencies( dependencies_for_this, file_path, encountered_internal_modules) self.dependencies_for_subproject[ subproject] = dependencies_for_this.keys() for dependency in dependencies_for_this: for name in dependencies_for_this[dependency]: self.dependencies[dependency].add(name) # No subprojects are specified, list all PTS dependencies else: self.dependencies = introspection.get_all_dependencies() # If a script name is given else: scripts = introspection.get_scripts() tables = introspection.get_arguments_tables() # Find matching 'do' commands (actual scripts or tabulated commands) matches = introspection.find_matches_scripts( self.config.script, scripts) table_matches = introspection.find_matches_tables( self.config.script, tables) # List the dependencies of the matching script self.dependencies = defaultdict(set) # No match if len(matches) + len(table_matches) == 0: show_all_available(scripts, tables) exit() # More matches elif len(matches) + len(table_matches) > 1: show_possible_matches(matches, table_matches, tables) exit() # Exactly one match from existing do script elif len(matches) == 1 and len(table_matches) == 0: # Determine the full path to the matching script script_path = fs.join(introspection.pts_do_dir, matches[0][0], matches[0][1]) introspection.add_dependencies(self.dependencies, script_path, set()) # Exactly one match from tabulated command elif len(table_matches) == 1 and len(matches) == 0: # from pts.core.tools import logging # configuration # Path to class module table_match = table_matches[0] subproject = table_match[0] index = table_match[1] relative_class_module_path = tables[subproject]["Path"][ index].replace(".", "/").rsplit("/", 1)[0] + ".py" class_module_path = fs.join( introspection.pts_subproject_dir(subproject), relative_class_module_path) logging_path = fs.join(introspection.pts_package_dir, "core", "tools", "logging.py") command_name = tables[subproject]["Command"][index] configuration_name = tables[subproject]["Configuration"][index] if configuration_name == "--": configuration_name = command_name configuration_module_path = fs.join( introspection.pts_root_dir, "pts/" + subproject + "/config/" + configuration_name + ".py") # Add dependencies encountered = set() introspection.add_dependencies(self.dependencies, logging_path, encountered) introspection.add_dependencies(self.dependencies, configuration_module_path, encountered) introspection.add_dependencies(self.dependencies, class_module_path, encountered)
# Create the command-line parser parser = argparse.ArgumentParser() parser.add_argument("script", type=str, nargs="?", help="the name of the PTS do script for which to determine the dependencies") parser.add_argument("-m", "--modules", action="store_true", help="show the PTS modules which import a given package") parser.add_argument("-s", "--standard", action="store_true", help="show import packages from the python standard library") parser.add_argument("-v", "--version", action="store_true", help="show the version numbers of the required packages") # Parse the command line arguments arguments = parser.parse_args() # ----------------------------------------------------------------- # If no script name is given, execute the "list_dependencies.py" script to list all dependencies of PTS and the # PTS modules that use them if arguments.script is None: dependencies = introspection.get_all_dependencies() else: scripts = introspection.get_scripts() tables = introspection.get_arguments_tables() # Find matching 'do' commands (actuall scripts or tabulated commands) matches = introspection.find_matches_scripts(arguments.script, scripts) table_matches = introspection.find_matches_tables(arguments.script, tables) # List the dependencies of the matching script dependencies = defaultdict(set) # No match if len(matches) + len(table_matches) == 0:
def get_dependencies(self): """ This function ... :return: """ # If no script name is given, list all dependencies of PTS and the # PTS modules that use them if self.config.script is None: if self.config.subprojects: self.dependencies = defaultdict(set) directories_for_subproject = defaultdict(list) # Loop over the subdirectories of the 'do' directory for path, name in fs.directories_in_path(introspection.pts_do_dir, returns=["path", "name"]): subproject = name directories_for_subproject[subproject].append(path) # Loop over the other directories in 'pts' (other than 'do' and 'doc') for path, name in fs.directories_in_path(introspection.pts_package_dir, returns=["path", "name"], exact_not_name=["do", "doc"]): subproject = name directories_for_subproject[subproject].append(path) encountered_internal_modules = set() for subproject in directories_for_subproject: # print(subproject, directories_for_subproject[subproject]) # List the dependencies of the matching script dependencies_for_this = defaultdict(set) for dir_path in directories_for_subproject[subproject]: for file_path in fs.files_in_path(dir_path, extension="py", recursive=True): # if subproject == "dustpedia": print(file_path) introspection.add_dependencies(dependencies_for_this, file_path, encountered_internal_modules) self.dependencies_for_subproject[subproject] = dependencies_for_this.keys() for dependency in dependencies_for_this: for name in dependencies_for_this[dependency]: self.dependencies[dependency].add(name) # No subprojects are specified, list all PTS dependencies else: self.dependencies = introspection.get_all_dependencies() # If a script name is given else: scripts = introspection.get_scripts() tables = introspection.get_arguments_tables() # Find matching 'do' commands (actual scripts or tabulated commands) matches = introspection.find_matches_scripts(self.config.script, scripts) table_matches = introspection.find_matches_tables(self.config.script, tables) # List the dependencies of the matching script self.dependencies = defaultdict(set) # No match if len(matches) + len(table_matches) == 0: show_all_available(scripts, tables) exit() # More matches elif len(matches) + len(table_matches) > 1: show_possible_matches(matches, table_matches, tables) exit() # Exactly one match from existing do script elif len(matches) == 1 and len(table_matches) == 0: # Determine the full path to the matching script script_path = fs.join(introspection.pts_do_dir, matches[0][0], matches[0][1]) introspection.add_dependencies(self.dependencies, script_path, set()) # Exactly one match from tabulated command elif len(table_matches) == 1 and len(matches) == 0: # from pts.core.tools import logging # configuration # Path to class module table_match = table_matches[0] subproject = table_match[0] index = table_match[1] relative_class_module_path = tables[subproject]["Path"][index].replace(".", "/").rsplit("/", 1)[0] + ".py" class_module_path = fs.join(introspection.pts_subproject_dir(subproject), relative_class_module_path) logging_path = fs.join(introspection.pts_package_dir, "core", "basics", "log.py") command_name = tables[subproject]["Command"][index] configuration_name = tables[subproject]["Configuration"][index] if configuration_name == "--": configuration_name = command_name configuration_module_path = fs.join(introspection.pts_root_dir, "pts/" + subproject + "/config/" + configuration_name + ".py") # Add dependencies encountered = set() introspection.add_dependencies(self.dependencies, logging_path, encountered) introspection.add_dependencies(self.dependencies, configuration_module_path, encountered) introspection.add_dependencies(self.dependencies, class_module_path, encountered)