Python pkg_resources.RequirementParseError() Examples

The following are 7 code examples of pkg_resources.RequirementParseError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pkg_resources , or try the search function .
Example #1
Source File: check_requirements.py    From requirements-tools with MIT License 6 votes vote down vote up
def get_raw_requirements(filename):
    ret = []
    for line in get_lines_from_file(filename):
        # allow something to editably install itself
        if line.strip() == '-e .':
            continue
        try:
            ret.append((parse_requirement(line), filename))
        except pkg_resources.RequirementParseError as e:
            raise AssertionError(
                'Requirements must be <<pkg>> or <<pkg>>==<<version>>\n'
                ' - git / http / etc. urls may be mutable (unpinnable)\n'
                ' - transitive dependencies from urls are not traceable\n'
                ' - line of error: {}\n'
                ' - inner exception: {!r}\n'.format(line.strip(), e),
            )
    return ret 
Example #2
Source File: cache.py    From q2cli with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _get_cached_requirements(self):
        import os.path
        import pkg_resources

        path = os.path.join(self._cache_dir, 'requirements.txt')

        if not os.path.exists(path):
            # No cached requirements. The empty set will always trigger a cache
            # refresh because the current requirements will, at minimum,
            # contain q2cli.
            return set()
        else:
            with open(path, 'r') as fh:
                contents = fh.read()
            try:
                return set(pkg_resources.parse_requirements(contents))
            except pkg_resources.RequirementParseError:
                # Unreadable cached requirements, trigger a cache refresh.
                return set() 
Example #3
Source File: db_interface.py    From tfutils with MIT License 5 votes vote down vote up
def version_info(module):
    """Get version of a standard python module.

    Args:
        module (module): python module object to get version info for.

    Returns:
        dict: dictionary of version info.

    """
    if hasattr(module, '__version__'):
        version = module.__version__
    elif hasattr(module, 'VERSION'):
        version = module.VERSION
    else:
        pkgname = module.__name__.split('.')[0]
        try:
            info = pkg_resources.get_distribution(pkgname)
        except (pkg_resources.DistributionNotFound, pkg_resources.RequirementParseError):
            version = None
            log.warning(
                'version information not found for %s -- what package is this from?' % module.__name__)
        else:
            version = info.version

    return {'version': version} 
Example #4
Source File: env.py    From lore with MIT License 5 votes vote down vote up
def check_requirements():
    """Make sure all listed packages from requirements.txt have been installed into the virtualenv at boot.
    """
    if not os.path.exists(REQUIREMENTS):
        sys.exit(
            ansi.error() + ' %s is missing. Please check it in.' % ansi.underline(REQUIREMENTS)
        )

    with open(REQUIREMENTS, 'r', encoding='utf-8') as f:
        dependencies = f.readlines()

    vcs = [d for d in dependencies if re.match(r'^(-e )?(git|svn|hg|bzr).*', d)]

    dependencies = list(set(dependencies) - set(vcs))

    missing = []
    try:
        pkg_resources.require(dependencies)
    except (
        pkg_resources.ContextualVersionConflict,
        pkg_resources.DistributionNotFound,
        pkg_resources.VersionConflict
    ) as error:
        missing.append(str(error))
    except pkg_resources.RequirementParseError:
        pass

    if missing:
        missing = ' missing requirement:\n  ' + os.linesep.join(missing)
        if '--env-checked' in sys.argv:
            sys.exit(ansi.error() + missing + '\nRequirement installation failure, please check for errors in:\n $ lore install\n')
        else:
            print(ansi.warning() + missing)
            import lore.__main__
            lore.__main__.install_requirements(None)
            reboot('--env-checked') 
Example #5
Source File: PySafetyBear.py    From coala-bears with GNU Affero General Public License v3.0 5 votes vote down vote up
def try_parse_requirements(lines: typed_list(str)):
        """
        Yields all package requirements parsable from the given lines.

        :param lines: An iterable of lines from a requirements file.
        """
        for line in lines:
            try:
                yield from pkg_resources.parse_requirements(line)
            except pkg_resources.RequirementParseError:
                # unsupported requirement specification
                pass 
Example #6
Source File: util.py    From guildai with Apache License 2.0 5 votes vote down vote up
def find_python_interpreter(version_spec):
    import pkg_resources

    try:
        # Requirement.parse wants a package name, so we use 'python'
        # here, but anything would do.
        req = pkg_resources.Requirement.parse("python%s" % version_spec)
    except pkg_resources.RequirementParseError:
        raise ValueError(version_spec)
    python_interps = {ver: path for path, ver in python_interpreters()}
    matching = list(req.specifier.filter(sorted(python_interps)))
    if matching:
        matching_ver = matching[0]
        return python_interps[matching_ver], matching_ver
    return None 
Example #7
Source File: setup.py    From flocker with Apache License 2.0 4 votes vote down vote up
def requirements_list_from_file(requirements_file, dependency_links):
    """
    Parse a requirements file.

    Requirements that have an environment marker will only be included
    in the list if the marker evaluates True.

    ``--find-links`` lines will be added to the supplied ``dependency_links``
    list.

    XXX There's a package called ``pbr`` which is also supposed to do this
    job. I couldn't get it to work --RichardW.
    """
    requirements = []
    with open(requirements_file) as f:
        for line in f:
            line = line.rstrip()
            if line.startswith('#'):
                continue
            elif line.startswith('--find-links'):
                link = line.split(None, 1)[1]
                dependency_links.append(link)
            else:
                parsed_requirements = parse_requirements(line)
                try:
                    (req,) = list(parsed_requirements)
                except RequirementParseError as original_error:
                    # XXX Buildbot has an old version of setuptools /
                    # pkg_resources which can't parse environment markers.
                    message = unicode(original_error)
                    if environ['HOME'] != "/srv/buildslave":
                        raise
                    if not message.startswith("Expected version spec in "):
                        raise
                    if ";" not in line:
                        raise
                    continue
                if getattr(req, "marker", None) and not req.marker.evaluate():
                    continue
                requirements.append(unicode(req))
    return requirements

# Parse the ``.in`` files. This will allow the dependencies to float when
# Flocker is installed using ``pip install .``.
# It also allows Flocker to be imported as a package alongside other Python
# libraries that may require different versions than those specified in
# Flocker's pinned dependency files.