def from_pipfile(cls, name, pipfile): creation_args = {} pipfile_keys = [ k for k in ("ref", "vcs", "subdirectory", "path", "editable", "file", "uri", "extras") + VCS_LIST if k in pipfile ] for key in pipfile_keys: if key == "extras": extras = pipfile.get(key, None) if extras: pipfile[key] = sorted( dedup([extra.lower() for extra in extras])) if key in VCS_LIST: creation_args["vcs"] = key target = pipfile.get(key) drive, path = os.path.splitdrive(target) if not drive and not os.path.exists(target) and ( is_valid_url(target) or is_file_url(target) or target.startswith('git@')): creation_args["uri"] = target else: creation_args["path"] = target if os.path.isabs(target): creation_args["uri"] = path_to_url(target) else: creation_args[key] = pipfile.get(key) creation_args["name"] = name return cls(**creation_args)
def from_line(cls, line): line = line.strip('"').strip("'") link = None path = None editable = line.startswith("-e ") line = line.split(" ", 1)[1] if editable else line setup_path = None if not any( [is_installable_file(line), is_valid_url(line), is_file_url(line)]): raise RequirementError( "Supplied requirement is not installable: {0!r}".format(line)) vcs_type, prefer, relpath, path, uri, link = cls.get_link_from_line( line) setup_path = Path(path) / "setup.py" if path else None arg_dict = { "path": relpath if relpath else path, "uri": unquote(link.url_without_fragment), "link": link, "editable": editable, "setup_path": setup_path, "uri_scheme": prefer, } if link and link.is_wheel: from pip_shims import Wheel arg_dict["name"] = Wheel(link.filename).name elif link.egg_fragment: arg_dict["name"] = link.egg_fragment created = cls(**arg_dict) return created
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 is_local(self): if is_file_url(self.uri): return True return False