コード例 #1
0
ファイル: _dependency.py プロジェクト: udaykondreddy/dephell
    def from_params(cls,
                    *,
                    raw_name: str,
                    constraint,
                    source: Dependency,
                    url: Optional[str] = None,
                    repo=None,
                    marker: Union[Markers, str] = None,
                    extras: Optional[List[str]] = None,
                    envs=None,
                    **kwargs) -> List[Union[Dependency, ExtraDependency]]:

        # make link
        if not url or isinstance(url, str):
            link = parse_link(url)
        else:
            link = url
        if link and not isinstance(link, UnknownLink):
            if link.name and rex_hash.fullmatch(raw_name):
                raw_name = link.name

        # make constraint
        if isinstance(constraint, str):
            constraint = Constraint(source, constraint)
            if isinstance(link, VCSLink) and link.rev:
                constraint._specs[source.name] = GitSpecifier()

        # make repo
        if repo is None:
            default_repo = None
            if source.repo and source.repo.propagate:
                default_repo = source.repo
            repo = get_repo(link, default=default_repo)

        # make marker
        if isinstance(marker, Markers):
            marker = copy(marker)
        else:
            marker = Markers(marker)

        # make envs
        if envs is None:
            envs = {'main'}
        envs.update(marker.extract('extra'))

        base_dep = cls.dep_class(
            link=link,
            repo=repo,
            raw_name=raw_name,
            constraint=constraint,
            marker=MarkerTracker().apply(source=source, markers=marker),
            envs=envs,
            **kwargs,
        )
        deps = [base_dep]
        if extras:
            for extra in extras:
                deps.append(cls.extra_class.from_dep(dep=base_dep,
                                                     extra=extra))
        return deps
コード例 #2
0
    def from_requirement(
            cls,
            source,
            req,
            *,
            url=None,
            envs=None,
            marker: Union[Markers, str] = None,
            editable=False) -> List[Union[Dependency, ExtraDependency]]:
        if type(req) is str:
            req = PackagingRequirement(req)
        # https://github.com/pypa/packaging/blob/master/packaging/requirements.py
        link = parse_link(url or req.url)
        # make constraint
        constraint = Constraint(source, req.specifier)
        if isinstance(link, VCSLink) and link.rev:
            constraint._specs[source.name] = GitSpecifier()

        if isinstance(marker, Markers):
            marker = copy(marker)
        else:
            marker = Markers(marker)
        if req.marker is not None:
            # some libs uses `in` for python_version,
            # but dephell_markers isn't ready for this
            try:
                marker &= Markers(req.marker)
            except ValueError:
                logger.warning('cannot parse marker',
                               extra=dict(marker=req.marker))

        if envs is None:
            envs = {'main'}
        envs.update(marker.extract('extra'))

        default_repo = None
        if source.repo and source.repo.propagate:
            default_repo = source.repo

        name = req.name
        # drop version from the end
        if rex_vers.fullmatch(name):
            name = name.rsplit('-', maxsplit=1)[0]

        base_dep = cls.dep_class(
            raw_name=name,
            constraint=constraint,
            repo=get_repo(link, default=default_repo),
            link=link,
            marker=MarkerTracker().apply(source=source, markers=marker),
            editable=editable,
            envs=envs,
        )
        deps = [base_dep]
        if req.extras:
            for extra in req.extras:
                deps.append(cls.extra_class.from_dep(dep=base_dep,
                                                     extra=extra))
        return deps
コード例 #3
0
ファイル: egginfo.py プロジェクト: DriverX/dephell
 def parse_dependency_links(self, content: str) -> Dict[str, str]:
     urls = dict()
     for url in content.split('\n'):
         url = url.strip()
         if not url or url[0] == '#':
             continue
         parsed = parse_link(url)
         name = parsed.name.split('-')[0]
         urls[name] = url
     return urls
コード例 #4
0
ファイル: setuppy.py プロジェクト: pombredanne/dephell
    def load(self, path) -> RootDependency:
        if isinstance(path, str):
            path = Path(path)
        path = self._make_source_path_absolute(path)
        self._resolve_path = path.parent

        info = self._execute(path=path)
        if info is None:
            with chdir(path.parent):
                info = run_setup(path.name)

        root = RootDependency(
            raw_name=self._get(info, 'name'),
            version=self._get(info, 'version') or '0.0.0',
            package=PackageRoot(
                path=self.project_path or Path(),
                name=self._get(info, 'name') or None,
            ),

            description=self._get(info, 'description'),
            license=self._get(info, 'license'),

            keywords=tuple(self._get_list(info, 'keywords')),
            classifiers=tuple(self._get_list(info, 'classifiers')),
            platforms=tuple(self._get_list(info, 'platforms')),

            python=RangeSpecifier(self._get(info, 'python_requires')),
            readme=Readme.from_code(path=path),
        )

        # links
        for key, name in (('home', 'url'), ('download', 'download_url')):
            link = self._get(info, name)
            if link:
                root.links[key] = link

        # authors
        for name in ('author', 'maintainer'):
            author = self._get(info, name)
            if author:
                root.authors += (
                    Author(name=author, mail=self._get(info, name + '_email')),
                )

        # entrypoints
        entrypoints = []
        for group, content in (getattr(info, 'entry_points', {}) or {}).items():
            for entrypoint in content:
                entrypoints.append(EntryPoint.parse(text=entrypoint, group=group))
        root.entrypoints = tuple(entrypoints)

        # dependency_links
        urls = dict()
        for url in self._get_list(info, 'dependency_links'):
            parsed = parse_link(url)
            name = parsed.name.split('-')[0]
            urls[name] = url

        # dependencies
        for req in self._get_list(info, 'install_requires'):
            req = Requirement(req)
            root.attach_dependencies(DependencyMaker.from_requirement(
                source=root,
                req=req,
                url=urls.get(req.name),
            ))

        # extras
        for extra, reqs in getattr(info, 'extras_require', {}).items():
            extra, marker = self._split_extra_and_marker(extra)
            envs = {extra} if extra == 'dev' else {'main', extra}
            for req in reqs:
                req = Requirement(req)
                root.attach_dependencies(DependencyMaker.from_requirement(
                    source=root,
                    req=req,
                    marker=marker,
                    envs=envs,
                ))

        return root
コード例 #5
0
    def load(self, path) -> RootDependency:
        if isinstance(path, str):
            path = Path(path)
        path = self._make_source_path_absolute(path)
        self._resolve_path = path.parent

        data = read_setup(path=path, error_handler=logger.debug)
        root = RootDependency(
            raw_name=data['name'],
            version=data.get('version', '0.0.0'),
            package=PackageRoot(
                path=self.project_path or Path(),
                name=data['name'],
            ),

            description=data.get('description'),
            license=data.get('license'),

            keywords=tuple(data.get('keywords', ())),
            classifiers=tuple(data.get('classifiers', ())),
            platforms=tuple(data.get('platforms', ())),

            python=RangeSpecifier(data.get('python_requires')),
            readme=Readme.from_code(path=path),
        )

        # links
        fields = (
            (HOMEPAGE_FIELD, 'url'),
            (DOWNLOAD_FIELD, 'download_url'),
        )
        for key, name in fields:
            link = data.get(name)
            if link:
                root.links[key] = link

        # authors
        for name in ('author', 'maintainer'):
            author = data.get(name)
            if author:
                root.authors += (
                    Author(name=author, mail=data.get(name + '_email')),
                )

        # entrypoints
        entrypoints = []
        for group, content in data.get('entry_points', {}).items():
            for entrypoint in content:
                entrypoints.append(EntryPoint.parse(text=entrypoint, group=group))
        root.entrypoints = tuple(entrypoints)

        # dependency_links
        urls = dict()
        for url in data.get('dependency_links', ()):
            parsed = parse_link(url)
            name = parsed.name.split('-')[0]
            urls[name] = url

        # dependencies
        for req in data.get('install_requires', ()):
            req = Requirement(req)
            root.attach_dependencies(DependencyMaker.from_requirement(
                source=root,
                req=req,
                url=urls.get(req.name),
            ))

        # extras
        for extra, reqs in data.get('extras_require', {}).items():
            extra, marker = self._split_extra_and_marker(extra)
            envs = {extra} if extra == 'dev' else {'main', extra}
            for req in reqs:
                req = Requirement(req)
                root.attach_dependencies(DependencyMaker.from_requirement(
                    source=root,
                    req=req,
                    marker=marker,
                    envs=envs,
                ))

        return root