Example #1
0
 def is_satisfied(self, req):
     match = next(
         iter(d for d in self.get_distributions()
              if canonicalize_name(d.project_name) == req.normalized_name),
         None,
     )
     if match is not None:
         if req.editable and req.line_instance.is_local and self.find_egg(
                 match):
             requested_path = req.line_instance.path
             return requested_path and vistir.compat.samefile(
                 requested_path, match.location)
         elif match.has_metadata("direct_url.json"):
             direct_url_metadata = json.loads(
                 match.get_metadata("direct_url.json"))
             commit_id = direct_url_metadata.get("vcs_info",
                                                 {}).get("commit_id", "")
             vcs_type = direct_url_metadata.get("vcs_info",
                                                {}).get("vcs", "")
             _, pipfile_part = req.as_pipfile().popitem()
             return (vcs_type == req.vcs and commit_id == req.commit_hash
                     and direct_url_metadata["url"]
                     == pipfile_part[req.vcs])
         elif req.is_vcs or req.is_file_or_url:
             return False
         elif req.line_instance.specifiers is not None:
             return req.line_instance.specifiers.contains(match.version,
                                                          prereleases=True)
         return True
     return False
Example #2
0
def get_canonical_names(packages):
    """Canonicalize a list of packages and return a set of canonical names"""
    from pipenv.vendor.packaging.utils import canonicalize_name

    if not isinstance(packages, Sequence):
        if not isinstance(packages, str):
            return packages
        packages = [packages]
    return {canonicalize_name(pkg) for pkg in packages if pkg}
Example #3
0
def get_dependencies_from_cache(ireq):
    """Retrieves dependencies for the given install requirement from the
    dependency cache.

    :param ireq: A single InstallRequirement
    :type ireq: :class:`~pipenv.patched.notpip._internal.req.req_install.InstallRequirement`
    :return: A set of dependency lines for generating new InstallRequirements.
    :rtype: set(str) or None
    """
    if ireq.editable or not is_pinned_requirement(ireq):
        return
    if ireq not in DEPENDENCY_CACHE:
        return
    cached = set(DEPENDENCY_CACHE[ireq])

    # Preserving sanity: Run through the cache and make sure every entry if
    # valid. If this fails, something is wrong with the cache. Drop it.
    try:
        broken = False
        for line in cached:
            dep_ireq = pip_shims.shims.InstallRequirement.from_line(line)
            name = canonicalize_name(dep_ireq.name)
            if _marker_contains_extra(dep_ireq):
                broken = True  # The "extra =" marker breaks everything.
            elif name == canonicalize_name(ireq.name):
                broken = True  # A package cannot depend on itself.
            if broken:
                break
    except Exception:
        broken = True

    if broken:
        del DEPENDENCY_CACHE[ireq]
        return

    return cached
Example #4
0
def get_name_variants(pkg):
    # type: (STRING_TYPE) -> Set[STRING_TYPE]
    """Given a packager name, get the variants of its name for both the
    canonicalized and "safe" forms.

    :param AnyStr pkg: The package to lookup
    :returns: A list of names.
    :rtype: Set
    """

    if not isinstance(pkg, str):
        raise TypeError("must provide a string to derive package names")
    from pipenv.vendor.packaging.utils import canonicalize_name
    from pkg_resources import safe_name

    pkg = pkg.lower()
    names = {safe_name(pkg), canonicalize_name(pkg), pkg.replace("-", "_")}
    return names