예제 #1
0
def find_direct_dependencies(dist, extras=None):
    """
    Find direct, declared dependencies for dist.
    """
    simple = (req for req in map(Requirement, always_iterable(dist.requires))
              if NullMarker.wrap(req).evaluate(dict(extra=None)))
    extra_deps = (req
                  for req in map(Requirement, always_iterable(dist.requires))
                  for extra in always_iterable(getattr(dist, 'extras', extras))
                  if NullMarker.wrap(req).evaluate(dict(extra=extra)))
    return itertools.chain(simple, extra_deps)
예제 #2
0
def find_packages(
    *,
    namespaces=True,
    fill_package_dir: Optional[Dict[str, str]] = None,
    root_dir: Optional[_Path] = None,
    **kwargs
) -> List[str]:
    """Works similarly to :func:`setuptools.find_packages`, but with all
    arguments given as keyword arguments. Moreover, ``where`` can be given
    as a list (the results will be simply concatenated).

    When the additional keyword argument ``namespaces`` is ``True``, it will
    behave like :func:`setuptools.find_namespace_packages`` (i.e. include
    implicit namespaces as per :pep:`420`).

    The ``where`` argument will be considered relative to ``root_dir`` (or the current
    working directory when ``root_dir`` is not given).

    If the ``fill_package_dir`` argument is passed, this function will consider it as a
    similar data structure to the ``package_dir`` configuration parameter add fill-in
    any missing package location.

    :rtype: list
    """
    from setuptools.discovery import construct_package_dir
    from setuptools.extern.more_itertools import unique_everseen, always_iterable

    if namespaces:
        from setuptools.discovery import PEP420PackageFinder as PackageFinder
    else:
        from setuptools.discovery import PackageFinder  # type: ignore

    root_dir = root_dir or os.curdir
    where = kwargs.pop('where', ['.'])
    packages: List[str] = []
    fill_package_dir = {} if fill_package_dir is None else fill_package_dir
    search = list(unique_everseen(always_iterable(where)))

    if len(search) == 1 and all(not _same_path(search[0], x) for x in (".", root_dir)):
        fill_package_dir.setdefault("", search[0])

    for path in search:
        package_path = _nest_path(root_dir, path)
        pkgs = PackageFinder.find(package_path, **kwargs)
        packages.extend(pkgs)
        if pkgs and not (
            fill_package_dir.get("") == path
            or os.path.samefile(package_path, root_dir)
        ):
            fill_package_dir.update(construct_package_dir(pkgs, path))

    return packages
예제 #3
0
 def _install_dependencies(self, ep):
     """
     Given an entry point, ensure that any declared extras for
     its distribution are installed.
     """
     reqs = {
         req
         for req in map(requirements.Requirement, always_iterable(ep.dist.requires))
         for extra in ep.extras
         if extra in req.extras
     }
     missing = itertools.filterfalse(self._is_installed, reqs)
     for req in missing:
         # fetch_build_egg expects pkg_resources.Requirement
         self.fetch_build_egg(pkg_resources.Requirement(str(req)))
예제 #4
0
def read_files(filepaths: Union[str, bytes, Iterable[_Path]],
               root_dir=None) -> str:
    """Return the content of the files concatenated using ``\n`` as str

    This function is sandboxed and won't reach anything outside ``root_dir``

    (By default ``root_dir`` is the current directory).
    """
    from setuptools.extern.more_itertools import always_iterable

    root_dir = os.path.abspath(root_dir or os.getcwd())
    _filepaths = (os.path.join(root_dir, path)
                  for path in always_iterable(filepaths))
    return '\n'.join(
        _read_file(path) for path in _filter_existing_files(_filepaths)
        if _assert_local(path, root_dir))