Exemplo n.º 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
                next(parse_requirements(fp.read()))
                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
Exemplo n.º 2
0
def deduce_helpful_msg(req: 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 = " The path does exist. "
        # Try to parse and check if it is a requirements file.
        try:
            with open(req) 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 += f" File '{req}' does not exist."
    return msg