Example #1
0
def deduce_helpful_msg(req):
    """Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
        msg = " It does exist."
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, 'r') as fp:
                # parse first line only
                parse_requirements(fp.read()).next()
                msg += " The argument you provided " + \
                    "(%s) appears to be a" % (req) + \
                    " requirements file. If that is the" + \
                    " case, use the '-r' flag to install" + \
                    " the packages specified within it."
        except RequirementParseError:
            logger.debug("Cannot parse '%s' as requirements \
            file" % (req),
                         exc_info=1)
    else:
        msg += " File '%s' does not exist." % (req)
    return msg
Example #2
0
def deduce_helpful_msg(req):
    """Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
        msg = " It does exist."
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, 'r') as fp:
                # parse first line only
                parse_requirements(fp.read()).next()
                msg += " The argument you provided " + \
                    "(%s) appears to be a" % (req) + \
                    " requirements file. If that is the" + \
                    " case, use the '-r' flag to install" + \
                    " the packages specified within it."
        except RequirementParseError:
            logger.debug("Cannot parse '%s' as requirements \
            file" % (req), exc_info=1)
    else:
        msg += " File '%s' does not exist." % (req)
    return msg
Example #3
0
def deduce_helpful_msg(req):
    # type: (str) -> str
    """Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
        msg = " It does exist."
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, "r") as fp:
                # parse first line only
                next(parse_requirements(fp.read()))
                msg += (
                    "The argument you provided "
                    "({}) appears to be a"
                    " requirements file. If that is the"
                    " case, use the '-r' flag to install"
                    " the packages specified within it."
                ).format(req)
        except RequirementParseError:
            logger.debug("Cannot parse '%s' as requirements file", req, exc_info=True)
    else:
        msg += " File '{}' does not exist.".format(req)
    return msg
Example #4
0
    def build_pinned_package(self, version, args, extra_args):
        try:
            # we want the exact versions from our downloaded requirement_set
            # so let's create a requirements.txt file and say to FPM to use it
            downloaded_requirements = \
                self.downloaded_req_set.requirement_versions()

            # however, when we specify a version in setup_py,
            # we want to use that one
            setup_py = setupreader.load('setup.py')
            package_requirements = list(
                pkg_resources.parse_requirements(setup_py['install_requires']))

            # when 'specs' is defined, we have a dependency specified (>=1.0.0)
            specs_requirements = {
                x.project_name: x.__str__()
                for x in package_requirements if x.specs
            }  # noqa

            write_requirements_txt(self.directory, downloaded_requirements,
                                   specs_requirements,
                                   PIN_MARKS[self.args.pin_versions])

            extra_args.append("--python-obey-requirements-txt")

            super(PinnedVersionPackageBuilder,
                  self).build_package(version, args, extra_args)
        finally:
            delete_requirements_txt(self.directory)
    def build_pinned_package(self, version, args, extra_args):
        try:
            # we want the exact versions from our downloaded requirement_set
            # so let's create a requirements.txt file and say to FPM to use it
            downloaded_requirements = \
                self.downloaded_req_set.requirement_versions()

            # however, when we specify a version in setup_py,
            # we want to use that one
            setup_py = setupreader.load('setup.py')
            package_requirements = list(pkg_resources.parse_requirements(
                setup_py['install_requires']))

            # when 'specs' is defined, we have a dependency specified (>=1.0.0)
            specs_requirements = {
                x.project_name: x.__str__() for x in package_requirements if x.specs}  # noqa

            write_requirements_txt(
                self.directory, downloaded_requirements, specs_requirements,
                PIN_MARKS[self.args.pin_versions])

            extra_args.append("--python-obey-requirements-txt")

            super(PinnedVersionPackageBuilder, self).build_package(
                version, args, extra_args)
        finally:
            delete_requirements_txt(self.directory)
def parse_requirements(path: Path) -> Iterable[str]:
    with open(path) as req_file:
        for line in req_file:
            if line.startswith('-'):
                continue
            if DROP_LINE_P.search(line):
                continue
            for req in pkg_resources.parse_requirements(line):
                yield req.key
                for ext in req.extras:
                    yield ext.lower()
Example #7
0
def deduce_helpful_msg(req):
    # type: (str) -> str
    """Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
        msg = " It does exist."
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, 'r') as fp:
                # parse first line only
                next(parse_requirements(fp.read()))
Example #8
0
def requirement_is_installed(expr):
    """
    Check whether a requirement is installed.

    :param expr: A requirement specification similar to those used in pip
                 requirement files (a string).
    :returns: :data:`True` if the requirement is available (installed),
              :data:`False` otherwise.
    """
    required_dist = next(parse_requirements(expr))
    try:
        installed_dist = get_distribution(required_dist.key)
        return installed_dist in required_dist
    except DistributionNotFound:
        return False
Example #9
0
def check_pip():
    try:
        from pip._vendor.pkg_resources import parse_requirements
    except ImportError:
        return

    reqs = metadata['install_requires']

    try:
        [r for s in reqs for r in parse_requirements(s)]
    except ValueError:
        exit("\n"
             "To install this library your must upgrade pip.\n"
             "Please run:\n"
             "   python -m pip install --upgrade pip\n")
Example #10
0
    def setuptools_supports_wheels(self):
        """
        Check whether setuptools should be upgraded to ``>= 0.8`` for wheel support.

        :returns: :data:`True` when setuptools needs to be upgraded, :data:`False` otherwise.
        """
        # Don't use pkg_resources.Requirement.parse, to avoid the override
        # in distribute, that converts `setuptools' to `distribute'.
        setuptools_requirement = next(pkg_resources.parse_requirements('setuptools >= 0.8'))
        try:
            installed_setuptools = pkg_resources.get_distribution('setuptools')
            if installed_setuptools in setuptools_requirement:
                # setuptools >= 0.8 is already installed; nothing to do.
                return True
        except pkg_resources.DistributionNotFound:
            pass
        # We need to install setuptools >= 0.8.
        return False
Example #11
0
    def setuptools_supports_wheels(self):
        """
        Check whether setuptools should be upgraded to ``>= 0.8`` for wheel support.

        :returns: ``True`` when setuptools needs to be upgraded, ``False`` otherwise.
        """
        # Don't use pkg_resources.Requirement.parse, to avoid the override
        # in distribute, that converts `setuptools' to `distribute'.
        setuptools_requirement = next(pkg_resources.parse_requirements('setuptools >= 0.8'))
        try:
            installed_setuptools = pkg_resources.get_distribution('setuptools')
            if installed_setuptools in setuptools_requirement:
                # setuptools >= 0.8 is already installed; nothing to do.
                return True
        except pkg_resources.DistributionNotFound:
            pass
        # We need to install setuptools >= 0.8.
        return False
Example #12
0
 def read(self):
     """
     >>> DepsReader("__requires__=['foo']").read()
     ['foo']
     """
     reqs_raw = self._read('__requires__')
     strings = map(str, pkg_resources.parse_requirements(reqs_raw))
     deps = Dependencies(strings)
     try:
         deps.index_url = self._read('__index_url__')
     except Exception:
         pass
     try:
         raw_links = self._read('__dependency_links__')
     except Exception:
         pass
     else:
         deps.dependency_links = list(pkg_resources.yield_lines(raw_links))
     return deps
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
<<<<<<< HEAD
        msg = " The path does exist. "
=======
        msg = " It does exist."
>>>>>>> 74c061954d5e927be4caafbd793e96a50563c265
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, 'r') as fp:
                # parse first line only
                next(parse_requirements(fp.read()))
                msg += (
                    "The argument you provided "
                    "({}) appears to be a"
                    " requirements file. If that is the"
                    " case, use the '-r' flag to install"
                    " the packages specified within it."
                ).format(req)
        except RequirementParseError:
            logger.debug(
                "Cannot parse '%s' as requirements file", req, exc_info=True
            )
    else:
        msg += " File '{}' does not exist.".format(req)
    return msg