def _parse_url(self) -> None: if not self.url: if self.path: self.url = path_to_url(self.path.as_posix()) else: try: self.path = Path(url_to_path(self.url)) except AssertionError: pass self._parse_name_from_url()
def get_dist_location(dist: Distribution) -> str: direct_url = dist.read_text("direct_url.json") if not direct_url: return "" direct_url_data = json.loads(direct_url) url = cast(str, direct_url_data["url"]) if url.startswith("file:"): path = url_to_path(url) editable = direct_url_data.get("dir_info", {}).get("editable", False) return f"{'-e ' if editable else ''}{path}" return ""
def _parse_url(self) -> None: if not self.url: if self.path: self.url = path_to_url(self.path.as_posix().replace( "${PROJECT_ROOT}", ".")) else: try: self.path = Path( url_to_path( self.url.replace( "${PROJECT_ROOT}", Path(".").absolute().as_posix().lstrip("/"), ))) except AssertionError: pass self._parse_name_from_url()
def open_file(url, session=None): if url.startswith("file://"): local_path = url_to_path(url) if os.path.isdir(local_path): raise ValueError("Cannot open directory for read: {}".format(url)) else: with open(local_path, "rb") as local_file: yield local_file else: headers = {"Accept-Encoding": "identity"} with session.get(url, headers=headers, stream=True) as resp: try: raw = getattr(resp, "raw", None) result = raw if raw else resp yield result finally: if raw: conn = getattr(raw, "_connection") if conn is not None: conn.close() result.close()