def _get_metadata(self, temp_dir): runner = SubprocessModuleRunner( self.get_setup_py(temp_dir), *settings.EXTRACT_DIST_COMMAND_ARGS + ['--stdout']) current_version = self.base_python_version or str(sys.version_info[0]) # the version provided with `-b` option or default paths_to_attempt = ( get_interpreter_path(version=ver) for ver in ( current_version, '2' if current_version == '3' else '3' # alternative Python version )) for path in paths_to_attempt: try: logger.info( "Running extract_dist command with: {0}".format(path)) runner.run(path) return runner.results except (JSONDecodeError, exc.ExtractionError) as e: logger.error( "Could not extract metadata with: {0}".format(path)) if all(hasattr(e, a) for a in ('msg', 'pos', 'doc')): logger.error("Could not parse JSON: {0} at {1}".format( e.msg, e.pos)) logger.error("The JSON was: {0}".format(e.doc)) self.unsupported_version = current_version else: sys.stderr.write("Failed to extract data from setup.py script.\n") sys.stderr.write("Check the log for details: {0}\n".format( ', '.join(pyp2rpm.logger.destinations))) raise SystemExit(3)
def _get_metadata(self, temp_dir): runner = SubprocessModuleRunner( self.get_setup_py(temp_dir), *settings.EXTRACT_DIST_COMMAND_ARGS + ['--stdout']) current_version = self.base_python_version or str(sys.version_info[0]) # the version provided with `-b` option or default paths_to_attempt = ( get_interpreter_path(version=ver) for ver in ( current_version, '2' if current_version == '3' else '3' # alternative Python version )) for path in paths_to_attempt: try: logger.info( "Running extract_dist command with: {0}".format(path)) runner.run(path) return runner.results except (JSONDecodeError, exc.ExtractionError): logger.error( "Could not extract metadata with: {0}".format(path)) self.unsupported_version = current_version else: sys.stdout.write("Failed to extract data from setup.py script.\n") raise SystemExit(3)
def _get_metadata(self, temp_dir): runner = SubprocessModuleRunner( self.get_setup_py(temp_dir), *settings.EXTRACT_DIST_COMMAND_ARGS + ['--stdout']) current_version = self.base_python_version or str(sys.version_info[0]) paths_to_attempt = (utils.get_interpreter_path(version=ver) for ver in ( current_version, # the version provided with `-b` option or default '2' if current_version == '3' else '3' # alternative Python version )) for path in paths_to_attempt: try: logger.info("Running extract_dist command with: {0}".format(path)) runner.run(path) return runner.results except (JSONDecodeError, exc.ExtractionError): logger.error("Could not extract metadata with: {0}".format(path)) self.unsupported_version = current_version else: sys.stdout.write("Failed to extract data from setup.py script.\n") raise SystemExit(3)
def __init__(self, *args, **kwargs): super(SetupPyMetadataExtractor, self).__init__(*args, **kwargs) temp_dir = tempfile.mkdtemp() try: with self.archive as a: a.extract_all(directory=temp_dir) try: runner = SubprocessModuleRunner(self.get_setup_py(temp_dir), *settings.EXTRACT_DIST_COMMAND_ARGS + ['--stdout']) logger.info("Running extract_dist command using current interpreter.") runner.run(utils.get_interpreter_path(current=True)) except (JSONDecodeError, exc.ExtractionError): logger.error("Error occured, trying alternative python interpreter.") self.unsupported_version = '3' if utils.PY3 else '2' try: runner.run(utils.get_interpreter_path(current=False)) except (JSONDecodeError, exc.ExtractionError): sys.stdout.write("Failed to extract data from setup.py script.\n") raise SystemExit(3) self.metadata = runner.results finally: shutil.rmtree(temp_dir)