Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
def is_vcs(pipfile_entry):
    """Determine if dictionary entry from Pipfile is for a vcs dependency."""
    if hasattr(pipfile_entry, "keys"):
        return any(key for key in pipfile_entry.keys() if key in VCS_LIST)

    elif isinstance(pipfile_entry, six.string_types):
        if not is_valid_url(pipfile_entry) and pipfile_entry.startswith("git+"):
            from .models.utils import add_ssh_scheme_to_git_uri
            pipfile_entry = add_ssh_scheme_to_git_uri(pipfile_entry)
        parsed_entry = urlsplit(pipfile_entry)
        return parsed_entry.scheme in VCS_SCHEMES
    return False
Exemplo n.º 4
0
def is_vcs(pipfile_entry):
    # type: (PipfileType) -> bool
    """Determine if dictionary entry from Pipfile is for a vcs dependency."""
    if isinstance(pipfile_entry, Mapping):
        return any(key for key in pipfile_entry.keys() if key in VCS_LIST)

    elif isinstance(pipfile_entry, six.string_types):
        if not is_valid_url(pipfile_entry) and pipfile_entry.startswith(
                "git+"):
            pipfile_entry = add_ssh_scheme_to_git_uri(pipfile_entry)

        parsed_entry = urlsplit(pipfile_entry)
        return parsed_entry.scheme in VCS_SCHEMES
    return False
def convert_direct_url_to_url(direct_url):
    # type: (AnyStr) -> AnyStr
    """Converts direct URLs to standard, link-style URLs

    Given a direct url as defined by *PEP 508*, convert to a :class:`~pip_shims.shims.Link`
    compatible URL by moving the name and extras into an **egg_fragment**.

    :param str direct_url: A pep-508 compliant direct url.
    :return: A reformatted URL for use with Link objects and :class:`~pip_shims.shims.InstallRequirement` objects.
    :rtype: AnyStr
    """
    direct_match = DIRECT_URL_RE.match(direct_url)  # type: Optional[Match]
    if direct_match is None:
        url_match = URL_RE.match(direct_url)
        if url_match or is_valid_url(direct_url):
            return direct_url
    match_dict = (
        {}
    )  # type: Dict[STRING_TYPE, Union[Tuple[STRING_TYPE, ...], STRING_TYPE]]
    if direct_match is not None:
        match_dict = direct_match.groupdict()  # type: ignore
    if not match_dict:
        raise ValueError(
            "Failed converting value to normal URL, is it a direct URL? {0!r}".
            format(direct_url))
    url_segments = [
        match_dict.get(s) for s in ("scheme", "host", "path", "pathsep")
    ]
    url = ""  # type: STRING_TYPE
    url = "".join([s for s in url_segments if s is not None])  # type: ignore
    new_url = build_vcs_uri(
        None,
        url,
        ref=match_dict.get("ref"),
        name=match_dict.get("name"),
        extras=match_dict.get("extras"),
        subdirectory=match_dict.get("subdirectory"),
    )
    return new_url
Exemplo n.º 6
0
 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)