Ejemplo n.º 1
0
 def __init__(self, path, **kwargs):
     message = "{} {}\n{}".format(
         click.style("Corrupt cache file", fg="cyan"),
         click.style(f"{path!s}", fg="reset", bg="reset"),
         click.style('Consider trying "pipenv lock --clear" to clear the cache.'),
     )
     PipenvException.__init__(self, message=message)
Ejemplo n.º 2
0
 def __init__(self, filename="Pipfile.lock", extra=None, **kwargs):
     extra = kwargs.pop("extra", [])
     message = "{} {} {}".format(
         click.style("You need to run", bold=True),
         click.style("$ pipenv lock", bold=True, fg="red"),
         click.style("before you can continue.", bold=True),
     )
     super().__init__(filename, message=message, extra=extra, **kwargs)
Ejemplo n.º 3
0
 def __init__(self, message=None, ctx=None, **kwargs):
     formatted_message = "{0}: {1}"
     msg_prefix = click.style("ERROR:", fg="red", bold=True)
     if not message:
         message = "Pipenv encountered a problem and had to exit."
     message = formatted_message.format(msg_prefix, click.style(message, bold=True))
     self.message = message
     extra = kwargs.pop("extra", [])
     UsageError.__init__(self, decode_for_output(message), ctx)
     self.extra = extra
Ejemplo n.º 4
0
 def __init__(self, message):
     extra = [
         "{} {}".format(
             click.style("The operation failed...", bold=True, fg="red"),
             click.style(
                 "A dependency conflict was detected and could not be resolved.",
                 fg="red",
             ),
         )
     ]
     PipenvException.__init__(self, message, extra=extra)
Ejemplo n.º 5
0
 def __init__(self, filename="Pipfile", extra=None, **kwargs):
     extra = kwargs.pop("extra", [])
     message = "{} {}".format(
         click.style("Aborting!", bold=True, fg="red"),
         click.style(
             "Please ensure that the file exists and is located in your"
             " project root directory.",
             bold=True,
         ),
     )
     super().__init__(filename, message=message, extra=extra, **kwargs)
Ejemplo n.º 6
0
 def __init__(self, filename, message=None, **kwargs):
     extra = kwargs.pop("extra", [])
     if not message:
         message = click.style("Please ensure that the file exists!", bold=True)
     message = self.formatted_message.format(
         click.style(f"{filename} not found!", bold=True), message
     )
     FileError.__init__(
         self, filename=filename, hint=decode_for_output(message), **kwargs
     )
     self.extra = extra
Ejemplo n.º 7
0
 def __init__(self, package, **kwargs):
     package_message = ""
     if package is not None:
         package_message = "Couldn't install package: {}\n".format(
             click.style(f"{package!s}", bold=True)
         )
     message = "{} {}".format(
         f"{package_message}",
         click.style("Package installation failed...", fg="yellow"),
     )
     extra = kwargs.pop("extra", [])
     PipenvException.__init__(self, message=message, extra=extra, **kwargs)
Ejemplo n.º 8
0
 def __init__(self, option_name="system", message=None, ctx=None, **kwargs):
     extra = kwargs.pop("extra", [])
     extra += [
         "{}: --system is intended to be used for Pipfile installation, "
         "not installation of specific packages. Aborting.".format(
             click.style("Warning", bold=True, fg="red")
         ),
     ]
     if message is None:
         message = "{} --deploy flag".format(
             click.style("See also: {}", fg="cyan"),
         )
     super().__init__(option_name, message=message, ctx=ctx, extra=extra, **kwargs)
Ejemplo n.º 9
0
class PipenvFileError(FileError):
    formatted_message = "{0} {{0}} {{1}}".format(
        click.style("ERROR:", fg="red", bold=True)
    )

    def __init__(self, filename, message=None, **kwargs):
        extra = kwargs.pop("extra", [])
        if not message:
            message = click.style("Please ensure that the file exists!", bold=True)
        message = self.formatted_message.format(
            click.style(f"{filename} not found!", bold=True), message
        )
        FileError.__init__(
            self, filename=filename, hint=decode_for_output(message), **kwargs
        )
        self.extra = extra

    def show(self, file=None):
        if file is None:
            file = vistir.misc.get_text_stderr()
        if self.extra:
            if isinstance(self.extra, str):
                self.extra = [self.extra]
            for extra in self.extra:
                click_echo(decode_for_output(extra, file), file=file)
        click_echo(self.message, file=file)
Ejemplo n.º 10
0
 def show(self, file=None):
     if file is None:
         file = vistir.misc.get_text_stderr()
     message = "{}\n{}".format(
         click.style("Failed parsing JSON results:", bold=True),
         decode_for_output(self.message.strip(), file),
     )
     click_echo(message, err=True)
     if self.error_text:
         click_echo(
             "{} {}".format(
                 click.style("ERROR TEXT:", bold=True),
                 decode_for_output(self.error_text, file),
             ),
             err=True,
         )
Ejemplo n.º 11
0
 def __init__(self, package, command, return_values, return_code, **kwargs):
     extra = [
         "{} {}".format(
             click.style("Attempted to run command: ", fg="cyan"),
             click.style(f"$ {command!r}", bold=True, fg="yellow"),
         )
     ]
     extra.extend(
         [click.style(line.strip(), fg="cyan") for line in return_values.splitlines()]
     )
     if isinstance(package, (tuple, list, set)):
         package = " ".join(package)
     message = "{!s} {!s}...".format(
         click.style("Failed to uninstall package(s)", fg="reset"),
         click.style(f"{package}!s", bold=True, fg="yellow"),
     )
     self.exit_code = return_code
     PipenvException.__init__(self, message=message, extra=extra)
     self.extra = extra
Ejemplo n.º 12
0
 def __init__(self, message, no_version_found=False):
     extra = (
         "{}: Your dependencies could not be resolved. You likely have a "
         "mismatch in your sub-dependencies.\n  "
         "You can use {} to bypass this mechanism, then run "
         "{} to inspect the situation.\n  "
         "Hint: try {} if it is a pre-release dependency."
         "".format(
             click.style("Warning", fg="red", bold=True),
             click.style("$ pipenv install --skip-lock", fg="yellow"),
             click.style("$ pipenv graph", fg="yellow"),
             click.style("$ pipenv lock --pre", fg="yellow"),
         ),
     )
     if "no version found at all" in message:
         no_version_found = True
     message = click.style(f"{message}", fg="yellow")
     if no_version_found:
         message = "{}\n{}".format(
             message,
             click.style(
                 "Please check your version specifier and version number. "
                 "See PEP440 for more information.",
                 fg="cyan",
             ),
         )
     PipenvException.__init__(self, message, extra=extra)
Ejemplo n.º 13
0
 def __init__(self, message=None, **kwargs):
     if not message:
         message = "Failed to create virtual environment."
     self.message = message
     extra = kwargs.pop("extra", None)
     if extra is not None and isinstance(extra, str):
         extra = click.unstyle(f"{extra}")
         if "KeyboardInterrupt" in extra:
             extra = click.style(
                 "Virtualenv creation interrupted by user", fg="red", bold=True
             )
         self.extra = extra = [extra]
     VirtualenvException.__init__(self, message, extra=extra)
Ejemplo n.º 14
0
 def show(self, file=None):
     if file is None:
         file = vistir.misc.get_text_stderr()
     click.echo(
         "{} {}".format(
             click.style("Error running command: ", fg="red"),
             click.style(f"$ {self.cmd}", bold=True),
         ),
         err=True,
         file=file,
     )
     if self.out:
         click.echo(
             "{} {}".format("OUTPUT: ", self.out),
             file=file,
             err=True,
         )
     if self.err:
         click_echo(
             "{} {}".format("STDERR: ", self.err),
             file=file,
             err=True,
         )
Ejemplo n.º 15
0
    def __init__(self, req=None):
        from .utils import VCS_LIST

        keys = (
            (
                "name",
                "path",
            )
            + VCS_LIST
            + ("line", "uri", "url", "relpath")
        )
        if req is not None:
            possible_display_values = [getattr(req, value, None) for value in keys]
            req_value = next(
                iter(val for val in possible_display_values if val is not None), None
            )
            if not req_value:
                getstate_fn = getattr(req, "__getstate__", None)
                slots = getattr(req, "__slots__", None)
                keys_fn = getattr(req, "keys", None)
                if getstate_fn:
                    req_value = getstate_fn()
                elif slots:
                    slot_vals = [
                        (k, getattr(req, k, None)) for k in slots if getattr(req, k, None)
                    ]
                    req_value = "\n".join([f"    {k}: {v}" for k, v in slot_vals])
                elif keys_fn:
                    values = [(k, req.get(k)) for k in keys_fn() if req.get(k)]
                    req_value = "\n".join([f"    {k}: {v}" for k, v in values])
                else:
                    req_value = getattr(req.line_instance, "line", None)
        message = click.style(
            f"Failed creating requirement instance {req_value}",
            bold=False,
            fg="reset",
            bg="reset",
        )
        extra = [str(req)]
        PipenvException.__init__(self, message, extra=extra)
Ejemplo n.º 16
0
 def show(self, file=None):
     if file is None:
         file = vistir.misc.get_text_stderr()
     color = None
     if self.ctx is not None:
         color = self.ctx.color
     if self.extra:
         if isinstance(self.extra, str):
             self.extra = [self.extra]
         for extra in self.extra:
             if color:
                 extra = click.style(extra, fg=color)
             click.echo(extra, file=file)
     hint = ""
     if self.cmd is not None and self.cmd.get_help_option(self.ctx) is not None:
         hint = 'Try "%s %s" for help.\n' % (
             self.ctx.command_path,
             self.ctx.help_option_names[0],
         )
     if self.ctx is not None:
         click.echo(self.ctx.get_usage() + "\n%s" % hint, file=file, color=color)
     click.echo(self.message, file=file)
Ejemplo n.º 17
0
class PipenvException(ClickException):
    message = "{0}: {{0}}".format(click.style("ERROR", fg="red", bold=True))

    def __init__(self, message=None, **kwargs):
        if not message:
            message = "Pipenv encountered a problem and had to exit."
        extra = kwargs.pop("extra", [])
        message = self.message.format(message)
        ClickException.__init__(self, message)
        self.extra = extra

    def show(self, file=None):
        if file is None:
            file = vistir.misc.get_text_stderr()
        if self.extra:
            if isinstance(self.extra, str):
                self.extra = [self.extra]
            for extra in self.extra:
                extra = "[pipenv.exceptions.{!s}]: {}".format(
                    self.__class__.__name__, extra
                )
                click.echo(extra, file=file)
        click.echo(f"{self.message}", file=file)
Ejemplo n.º 18
0
def cli(ctx,
        find=False,
        which=False,
        findall=False,
        version=False,
        ignore_unsupported=True):
    if version:
        click.echo("{0} version {1}".format(
            click.style("PythonFinder", fg="white", bold=True),
            click.style(str(__version__), fg="yellow")))
        ctx.exit()
    finder = Finder(ignore_unsupported=ignore_unsupported)
    if findall:
        versions = [v for v in finder.find_all_python_versions()]
        if versions:
            click.secho("Found python at the following locations:", fg="green")
            for v in versions:
                py = v.py_version
                comes_from = getattr(py, "comes_from", None)
                if comes_from is not None:
                    comes_from_path = getattr(comes_from, "path", v.path)
                else:
                    comes_from_path = v.path
                click.secho(
                    "{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}"
                    .format(py=py, comes_from=comes_from_path),
                    fg="yellow",
                )
            ctx.exit()
        else:
            click.secho(
                "ERROR: No valid python versions found! Check your path and try again.",
                fg="red",
            )
    if find:
        click.secho("Searching for python: {0!s}".format(find.strip()),
                    fg="yellow")
        found = finder.find_python_version(find.strip())
        if found:
            py = found.py_version
            comes_from = getattr(py, "comes_from", None)
            if comes_from is not None:
                comes_from_path = getattr(comes_from, "path", found.path)
            else:
                comes_from_path = found.path
            arch = getattr(py, "architecture", None)
            click.secho("Found python at the following locations:", fg="green")
            click.secho(
                "{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}"
                .format(py=py, comes_from=comes_from_path),
                fg="yellow",
            )
            ctx.exit()
        else:
            click.secho("Failed to find matching executable...", fg="yellow")
            ctx.exit(1)
    elif which:
        found = finder.system_path.which(which.strip())
        if found:
            click.secho("Found Executable: {0}".format(found), fg="white")
            ctx.exit()
        else:
            click.secho("Failed to find matching executable...", fg="yellow")
            ctx.exit(1)
    else:
        click.echo("Please provide a command", color="red")
        ctx.exit(1)
    ctx.exit()
Ejemplo n.º 19
0
 def __init__(self, message=None, **kwargs):
     if not message:
         message = click.style("Aborting deploy", bold=True)
     extra = kwargs.pop("extra", [])
     PipenvUsageError.__init__(self, message=message, extra=extra, **kwargs)