def _best(self): return pipper.get( self.pinned, index_url=self.index_url, env=self.env, extra_index_url=self.extra_index_url, )
def __init__(self, req_string, parent=None, index_url=None, env=None, extra_index_url=None): self.dist_path = None if req_string.endswith(".whl") and os.path.isfile(req_string): self.dist_path = req_string whl = WheelFile(req_string) whl_name_info = whl.parsed_filename.groupdict() self.name = canonicalize_name(whl_name_info["name"]) self.specifier = "==" + canonicalize_version(whl_name_info["ver"]) self.req = pkg_resources.Requirement.parse(self.name + self.specifier) else: self.req = pkg_resources.Requirement.parse(req_string) self.name = canonicalize_name(self.req.name) self.specifier = str(self.req.specifier) self.extras_requested = sorted(self.req.extras) log = self.log = logger.bind(dist=str(self.req)) log.info("init johnnydist", parent=parent and str(parent.req)) if parent is not None: self.index_url = parent.index_url self.extra_index_url = parent.extra_index_url self.required_by = [str(parent.req)] self.env = parent.env self.env_data = parent.env_data else: self.index_url = index_url self.extra_index_url = extra_index_url self.required_by = [] self.env = env if self.env is None: self.env_data = default_environment() else: self.env_data = dict(self.env) log.debug("target env", **self.env_data) if self.dist_path is None: log.debug("fetching best wheel") with wimpy.working_directory(self.tmp()): data = pipper.get( req_string, index_url=self.index_url, env=self.env, extra_index_url=self.extra_index_url, ) self.dist_path = data["path"] self.parent = parent self._recursed = False
def _get_info(dist_name, index_url=None, env=None, extra_index_url=None): log = logger.bind(dist_name=dist_name) tmpdir = tempfile.mkdtemp() log.debug("created scratch", tmpdir=tmpdir) try: with wimpy.working_directory(tmpdir): data = pipper.get( dist_name, index_url=index_url, env=env, extra_index_url=extra_index_url, tmpdir=".", ) dist_path = data["path"] # extract any info we may need from downloaded dist right now, so the # downloaded file can be cleaned up immediately import_names = _discover_import_names(dist_path) metadata = _extract_metadata(dist_path) finally: log.debug("removing scratch", tmpdir=tmpdir) shutil.rmtree(tmpdir) return import_names, metadata
def get_wheel(dist_name, index_url=DEFAULT_INDEX): return pipper.get(dist_name=dist_name, index_url=index_url)
def __init__(self, req_string, parent=None, index_url=None, env=None, extra_index_url=None): self.dist_path = None if req_string.endswith(".whl") and os.path.isfile(req_string): self.dist_path = req_string whl = WheelFile(req_string) whl_name_info = whl.parsed_filename.groupdict() self.name = canonicalize_name(whl_name_info["name"]) self.specifier = "==" + canonicalize_version(whl_name_info["ver"]) self.req = pkg_resources.Requirement.parse(self.name + self.specifier) else: self.req = pkg_resources.Requirement.parse(req_string) self.name = canonicalize_name(self.req.name) self.specifier = str(self.req.specifier) self.extras_requested = sorted(self.req.extras) log = self.log = logger.bind(dist=str(self.req)) log.info("init johnnydist", parent=parent and str(parent.req)) if parent is not None: self.index_url = parent.index_url self.extra_index_url = parent.extra_index_url self.required_by = [str(parent.req)] self.env = parent.env self.env_data = parent.env_data else: self.index_url = index_url self.extra_index_url = extra_index_url self.required_by = [] self.env = env if self.env is None: self.env_data = default_environment() else: self.env_data = dict(self.env) log.debug("target env", **self.env_data) if self.dist_path is None: log.debug("fetching best wheel") tmpdir = tempfile.mkdtemp() log.debug("created scratch", tmpdir=tmpdir) try: with wimpy.working_directory(tmpdir): data = pipper.get( req_string, index_url=self.index_url, env=self.env, extra_index_url=self.extra_index_url, tmpdir=tmpdir, ) self.dist_path = data["path"] # triggers retrieval of any info we need from downloaded dist self.import_names self.metadata finally: log.debug("removing scratch", tmpdir=tmpdir) shutil.rmtree(tmpdir) self.parent = parent self._recursed = False