def from_line(cls, line, editable=None, extras=None): relpath = None if line.startswith("-e "): editable = True line = line.split(" ", 1)[1] vcs_type, prefer, relpath, path, uri, link = cls.get_link_from_line( line) if not extras and link.egg_fragment: name, extras = _strip_extras(link.egg_fragment) if extras: extras = parse_extras(extras) else: name = link.egg_fragment subdirectory = link.subdirectory_fragment ref = None if "@" in link.show_url and "@" in uri: uri, ref = uri.rsplit("@", 1) if relpath and "@" in relpath: relpath, ref = relpath.rsplit("@", 1) return cls(name=name, ref=ref, vcs=vcs_type, subdirectory=subdirectory, link=link, path=relpath or path, editable=editable, uri=uri, extras=extras, base_line=line)
def pipfile_part(self): excludes = ["_repo", "_base_line", "setup_path", "_has_hashed_name"] filter_func = lambda k, v: bool(v) is True and k.name not in excludes pipfile_dict = attr.asdict(self, filter=filter_func).copy() if "vcs" in pipfile_dict: pipfile_dict = self._choose_vcs_source(pipfile_dict) name, _ = _strip_extras(pipfile_dict.pop("name")) return {name: pipfile_dict}
def pipfile_part(self): pipfile_dict = attr.asdict( self, filter=lambda k, v: bool(v) is True and k.name != '_repo').copy() if "vcs" in pipfile_dict: pipfile_dict = self._choose_vcs_source(pipfile_dict) name, _ = _strip_extras(pipfile_dict.pop("name")) return {name: pipfile_dict}
def from_line(cls, line): from pip_shims import InstallRequirement if isinstance(line, InstallRequirement): line = format_requirement(line) hashes = None if "--hash=" in line: hashes = line.split(" --hash=") line, hashes = hashes[0], hashes[1:] editable = line.startswith("-e ") line = line.split(" ", 1)[1] if editable else line line, markers = split_markers_from_line(line) line, extras = _strip_extras(line) specifiers = '' if extras: extras = parse_extras(extras) line = line.strip('"').strip("'").strip() line_with_prefix = "-e {0}".format(line) if editable else line vcs = None # Installable local files and installable non-vcs urls are handled # as files, generally speaking line_is_vcs = is_vcs(line) if is_installable_file(line) or ( (is_file_url(line) or is_valid_url(line)) and not line_is_vcs): r = FileRequirement.from_line(line_with_prefix) elif line_is_vcs: r = VCSRequirement.from_line(line_with_prefix, extras=extras) vcs = r.vcs elif line == "." and not is_installable_file(line): raise RequirementError( "Error parsing requirement %s -- are you sure it is installable?" % line) else: specs = "!=<>~" spec_matches = set(specs) & set(line) version = None name = line if spec_matches: spec_idx = min((line.index(match) for match in spec_matches)) name = line[:spec_idx] version = line[spec_idx:] specifiers = version if not extras: name, extras = _strip_extras(name) if extras: extras = parse_extras(extras) if version: name = "{0}{1}".format(name, version) r = NamedRequirement.from_line(line) req_markers = None if markers: req_markers = PackagingRequirement("fakepkg; {0}".format(markers)) r.req.marker = getattr(req_markers, "marker", None) r.req.local_file = getattr(r.req, "local_file", False) name = getattr(r.req, "name", None) if not name: name = getattr(r.req, "project_name", None) r.req.name = name if not name: name = getattr(r.req, "key", None) if name: r.req.name = name args = { "name": r.name, "vcs": vcs, "req": r, "markers": markers, "editable": editable, } if extras: extras = sorted(dedup([extra.lower() for extra in extras])) args["extras"] = extras r.req.extras = extras r.extras = extras elif r.extras: args["extras"] = sorted( dedup([extra.lower() for extra in r.extras])) if hashes: args["hashes"] = hashes return cls(**args)
def pipfile_part(self): pipfile_dict = attr.asdict(self, filter=filter_none).copy() if "vcs" in pipfile_dict: pipfile_dict = self._choose_vcs_source(pipfile_dict) name, _ = _strip_extras(pipfile_dict.pop("name")) return {name: pipfile_dict}