def query_nodes_edges_in_venv(self): """Generate Nodes and Edges of packages in virtual env. :rtype list, list :return: nodes, edges """ interrogation_file = pkg_res_resource_filename( 'magellan', 'env_interrogation.py') # execute self.add_file_to_extant_env_files('nodes.json') self.add_file_to_extant_env_files('edges.json') try: if self.name == "": run_in_subprocess("python {}".format(interrogation_file)) else: run_in_subprocess("vex {0} python {1}" .format(self.name, interrogation_file)) except Exception as e: maglog.exception(e) # Cleanup: self.remove_extant_env_files_from_disk() sys.exit("Error {} when trying to interrogate environment." .format(e)) # Load in nodes and edges pickles self.nodes = json.load(open('nodes.json', 'r')) self.edges = json.load(open('edges.json', 'r')) self.package_requirements = json.load( open('package_requirements.json', 'r')) self.add_file_to_extant_env_files('package_requirements.json')
def query_nodes_edges_in_venv(self): """Generate Nodes and Edges of packages in virtual env. :rtype list, list :return: nodes, edges """ interrogation_file = pkg_res_resource_filename('magellan', 'env_interrogation.py') # execute self.add_file_to_extant_env_files('nodes.json') self.add_file_to_extant_env_files('edges.json') try: if self.name == "": run_in_subprocess("python {}".format(interrogation_file)) else: run_in_subprocess("vex {0} python {1}".format( self.name, interrogation_file)) except Exception as e: maglog.exception(e) # Cleanup: self.remove_extant_env_files_from_disk() sys.exit( "Error {} when trying to interrogate environment.".format(e)) # Load in nodes and edges pickles self.nodes = json.load(open('nodes.json', 'r')) self.edges = json.load(open('edges.json', 'r')) self.package_requirements = json.load( open('package_requirements.json', 'r')) self.add_file_to_extant_env_files('package_requirements.json')
class MagellanConfig(object): """Holds magellan config info""" tmp_dir = '/tmp/magellan' caching = True cache_dir = os.path.join(tmp_dir, 'cache') tmp_env_dir = "MagellanTmp" vexrc = pkg_res_resource_filename('magellan', 'data/tmpVexRC') vex_options = '--config {}'.format(vexrc) @staticmethod def setup_cache(): """Setup cache dir""" mkdir_p(MagellanConfig.cache_dir) @staticmethod def tear_down_cache(): """remove cache dir""" # NB: mainly useful for debugging cmd_to_run = "rm -r {0}".format(MagellanConfig.tmp_dir) run_in_subprocess(cmd_to_run)
def get_deps_for_package_version(package, version, vex_options=None): """Gets dependencies for a specific version of a package. Specifically: 0. Check if this has already been done and cached & return that. 1. Set up temporary virtualenv 2. installs package/version into there using pip 3. Write file to interrogate through virtual env using vex/pip/setuptool combo 4. Run file, which pickles results to temp file 5. reads that file from current program 6. deletes file and returns info 7. Delete tmp env? """ if vex_options is None: vex_options = '' req_out_file = ("{0}_{1}_req.json".format(package.lower(), version.replace(".", "_"))) # 0. Check if this has already been done and cached & return that. cached_file = os.path.join(MagellanConfig.cache_dir, req_out_file) if os.path.exists(cached_file): maglog.info( "Using previously cached result at {0}".format(cached_file)) return json.load(open(cached_file, 'r')) # 1. Set up temporary virtualenv tmp_env = Environment(name=MagellanConfig.tmp_env_dir) tmp_env.create_vex_new_virtual_env( vex_options) # NB: delete if extant!! # todo (aj); by default? # 1.5 Upgrade pip run_in_subprocess("vex {} {} pip install pip --upgrade".format( vex_options, tmp_env.name)) # 2. installs package/version into there using pip # tmp_pip_options = "--cache-dir {}".format(MagellanConfig.cache_dir) tmp_pip_options = ("--cache-dir {} --no-deps".format( MagellanConfig.cache_dir)) pip_package_str = '{0}=={1}'.format(package, version) tmp_env.vex_install_requirement(tmp_env.name, pip_package_str, tmp_pip_options, vex_options) # 3. File to interrogate through virtual env for package interrogation_file = pkg_res_resource_filename( 'magellan', 'package_interrogation.py') # 4. Run file, which pickles results to temp file run_in_subprocess("vex {} {} python {} {} {}".format( vex_options, tmp_env.name, interrogation_file, package, MagellanConfig.cache_dir)) # 5. reads that file from current program try: result = json.load(open(cached_file, 'r')) except IOError: result = {} return result
def get_deps_for_package_version(package, version, vex_options=None): """Gets dependencies for a specific version of a package. Specifically: 0. Check if this has already been done and cached & return that. 1. Set up temporary virtualenv 2. installs package/version into there using pip 3. Write file to interrogate through virtual env using vex/pip/setuptool combo 4. Run file, which pickles results to temp file 5. reads that file from current program 6. deletes file and returns info 7. Delete tmp env? """ if vex_options is None: vex_options = '' req_out_file = ("{0}_{1}_req.json" .format(package.lower(), version.replace(".", "_"))) # 0. Check if this has already been done and cached & return that. cached_file = os.path.join(MagellanConfig.cache_dir, req_out_file) if os.path.exists(cached_file): maglog.info("Using previously cached result at {0}" .format(cached_file)) return json.load(open(cached_file, 'r')) # 1. Set up temporary virtualenv tmp_env = Environment(name=MagellanConfig.tmp_env_dir) tmp_env.create_vex_new_virtual_env(vex_options) # NB: delete if extant!! # todo (aj); by default? # 1.5 Upgrade pip run_in_subprocess("vex {} {} pip install pip --upgrade" .format(vex_options, tmp_env.name)) # 2. installs package/version into there using pip # tmp_pip_options = "--cache-dir {}".format(MagellanConfig.cache_dir) tmp_pip_options = ("--cache-dir {} --no-deps" .format(MagellanConfig.cache_dir)) pip_package_str = '{0}=={1}'.format(package, version) tmp_env.vex_install_requirement( tmp_env.name, pip_package_str, tmp_pip_options, vex_options) # 3. File to interrogate through virtual env for package interrogation_file = pkg_res_resource_filename( 'magellan', 'package_interrogation.py') # 4. Run file, which pickles results to temp file run_in_subprocess("vex {} {} python {} {} {}".format( vex_options, tmp_env.name, interrogation_file, package, MagellanConfig.cache_dir)) # 5. reads that file from current program try: result = json.load(open(cached_file, 'r')) except IOError: result = {} return result