Exemplo n.º 1
0
def test_resolvable_directory():
  builder = ResolverOptionsBuilder()
  interpreter = PythonInterpreter.get()

  with make_source_dir(name='my_project') as td:
    rdir = ResolvableDirectory.from_string(td, builder, interpreter)
    assert rdir.name == pkg_resources.safe_name('my_project')
    assert rdir.extras() == []

    rdir = ResolvableDirectory.from_string(td + '[extra1,extra2]', builder, interpreter)
    assert rdir.name == pkg_resources.safe_name('my_project')
    assert rdir.extras() == ['extra1', 'extra2']
Exemplo n.º 2
0
def test_resolvable_directory():
    builder = ResolverOptionsBuilder()
    interpreter = PythonInterpreter.get()

    with make_source_dir(name='my_project') as td:
        rdir = ResolvableDirectory.from_string(td, builder, interpreter)
        assert rdir.name == pkg_resources.safe_name('my_project')
        assert rdir.extras() == []

        rdir = ResolvableDirectory.from_string(td + '[extra1,extra2]', builder,
                                               interpreter)
        assert rdir.name == pkg_resources.safe_name('my_project')
        assert rdir.extras() == ['extra1', 'extra2']
Exemplo n.º 3
0
    def _fixup_install(
            dist,  # type: str
            install_dir,  # type: str
    ):
        # type: (...) -> None

        # The dist-info metadata directory is named as specifed in:
        #   https://www.python.org/dev/peps/pep-0427/
        #   https://packaging.python.org/specifications/recording-installed-packages/#the-dist-info-directory
        project_name_and_version = dist_metadata.project_name_and_version(
            dist) or ProjectNameAndVersion.from_filename(dist)
        project_name = safe_name(
            project_name_and_version.project_name).replace("-", "_")
        version = safe_version(project_name_and_version.version).replace(
            "-", "_")
        dist_info_dir = os.path.join(
            install_dir,
            "{project_name}-{version}.dist-info".format(
                project_name=project_name, version=version),
        )

        # The `direct_url.json` file is both mandatory for Pip to install and non-hermetic for
        # Pex's purpose, since it contains the absolute local filesystem path to any local wheel
        # file Pex installs via Pip. We remove the file and its entry in RECORD so that PEX files
        # are bytewise reproducible. The absence of the direct_url.json file only affects Pex venvs
        # where further mutation by PEP-compatible packaging tooling (e.g.: Pip) may be hindered.
        # In particular, `pip freeze` for any distributions provided by local projects or archives
        # will produce unuseful entries for those distributions.
        #
        # See:
        #   https://www.python.org/dev/peps/pep-0610/
        #   https://packaging.python.org/specifications/direct-url/#specification
        direct_url_relpath = os.path.join(os.path.basename(dist_info_dir),
                                          "direct_url.json")
        direct_url_abspath = os.path.join(os.path.dirname(dist_info_dir),
                                          direct_url_relpath)
        if not os.path.exists(direct_url_abspath):
            return

        with open(direct_url_abspath) as fp:
            if urlparse.urlparse(json.load(fp)["url"]).scheme != "file":
                return

        os.unlink(direct_url_abspath)

        # The RECORD is a csv file with the path to each installed file in the 1st column.
        # See: https://www.python.org/dev/peps/pep-0376/#record
        with closing(
                fileinput.input(files=[os.path.join(dist_info_dir, "RECORD")],
                                inplace=True)) as record_fi:
            for line in record_fi:
                if line.split(",")[0] != direct_url_relpath:
                    # N.B.: These lines include the newline already.
                    sys.stdout.write(line)
Exemplo n.º 4
0
 def scan(link):
     # Process a URL to see if it's for a package page
     if link.startswith(self.index_url):
         parts = list(
             map(urllib.parse.unquote,
                 link[len(self.index_url):].split('/')))
         if len(parts) == 2 and '#' not in parts[1]:
             # it's a package page, sanitize and index it
             pkg = safe_name(parts[0])
             ver = safe_version(parts[1])
             self.package_pages.setdefault(pkg.lower(), {})[link] = True
             return to_filename(pkg), to_filename(ver)
     return None, None
Exemplo n.º 5
0
  def satisfies(self, requirement, allow_prereleases=None):
    """Determine whether this package matches the requirement.

    :param requirement: The requirement to compare this Package against
    :type requirement: string or :class:`pkg_resources.Requirement`
    :param Optional[bool] allow_prereleases: Whether to allow prereleases to satisfy
      the `requirement`.
    :returns: True if the package matches the requirement, otherwise False
    """
    requirement = maybe_requirement(requirement)
    link_name = safe_name(self.name).lower()
    if link_name != requirement.key:
      return False

    # NB: If we upgrade to setuptools>=34 the SpecifierSet used here (requirement.specifier) will
    # come from a non-vendored `packaging` package and pex's bootstrap code in `PEXBuilder` will
    # need an update.
    return requirement.specifier.contains(self.raw_version, prereleases=allow_prereleases)
Exemplo n.º 6
0
 def normalize(cls, name):
     return safe_name(name).lower()
Exemplo n.º 7
0
 def allow_unverified(self, key):
   self._allow_unverified.add(safe_name(key).lower())
   return self
Exemplo n.º 8
0
 def allow_external(self, key):
   self._allow_external.add(safe_name(key).lower())
   return self
Exemplo n.º 9
0
 def normalize(cls, name):
   return safe_name(name).lower()
Exemplo n.º 10
0
 def name(self):
     return safe_name(self.distribution.get_name())
Exemplo n.º 11
0
 def allow_external(self, key):
   self._allow_external.add(safe_name(key).lower())
   return self
Exemplo n.º 12
0
 def allow_unverified(self, key):
   self._allow_unverified.add(safe_name(key).lower())
   return self
Exemplo n.º 13
0
 def name(self):
   return safe_name(self._name)