Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/performance update #3158

Merged
merged 7 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3158.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved runtime performance of no-op commands such as ``pipenv --venv`` by around 2/3.
74 changes: 59 additions & 15 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, message=None, ctx=None, **kwargs):
message = formatted_message.format(msg_prefix, crayons.white(message, bold=True))
self.message = message
extra = kwargs.pop("extra", [])
UsageError.__init__(self, message, ctx)
UsageError.__init__(self, fix_utf8(message), ctx)
self.extra = extra

def show(self, file=None):
Expand All @@ -98,8 +98,8 @@ def show(self, file=None):
self.extra = [self.extra,]
for extra in self.extra:
if color:
extra = getattr(crayons, color, "normal")
click_echo(extra, file=file)
extra = getattr(crayons, color, "blue")(extra)
click_echo(fix_utf8(extra), file=file)
hint = ''
if (self.cmd is not None and
self.cmd.get_help_option(self.ctx) is not None):
Expand All @@ -123,7 +123,7 @@ def __init__(self, filename, message=None, **kwargs):
crayons.white("{0} not found!".format(filename), bold=True),
message
)
FileError.__init__(self, filename=filename, hint=message, **kwargs)
FileError.__init__(self, filename=filename, hint=fix_utf8(message), **kwargs)
self.extra = extra

def show(self, file=None):
Expand All @@ -133,20 +133,20 @@ def show(self, file=None):
if isinstance(self.extra, six.string_types):
self.extra = [self.extra,]
for extra in self.extra:
click_echo(extra, file=file)
click_echo(fix_utf8(extra), file=file)
click_echo(self.message, file=file)


class PipfileNotFound(PipenvFileError):
def __init__(self, filename="Pipfile", extra=None, **kwargs):
extra = kwargs.pop("extra", [])
message = ("{0}. {1}".format(
message = ("{0} {1}".format(
crayons.red("Aborting!", bold=True),
crayons.white("Please ensure that the file exists and is located in your"
" project root directory.", bold=True)
)
)
super(PipfileNotFound, self).__init__(filename, message=message, extra=extra, **kwargs)
super(PipfileNotFound, self).__init__(filename, message=fix_utf8(message), extra=extra, **kwargs)


class LockfileNotFound(PipenvFileError):
Expand All @@ -157,21 +157,21 @@ def __init__(self, filename="Pipfile.lock", extra=None, **kwargs):
crayons.red("$ pipenv lock", bold=True),
crayons.white("before you can continue.", bold=True)
)
super(LockfileNotFound, self).__init__(filename, message=message, extra=extra, **kwargs)
super(LockfileNotFound, self).__init__(filename, message=fix_utf8(message), extra=extra, **kwargs)


class DeployException(PipenvUsageError):
def __init__(self, message=None, **kwargs):
if not message:
message = crayons.normal("Aborting deploy", bold=True)
extra = kwargs.pop("extra", [])
PipenvUsageError.__init__(message=message, extra=extra, **kwargs)
PipenvUsageError.__init__(message=fix_utf8(message), extra=extra, **kwargs)


class PipenvOptionsError(PipenvUsageError):
def __init__(self, option_name, message=None, ctx=None, **kwargs):
extra = kwargs.pop("extra", [])
PipenvUsageError.__init__(self, message=message, ctx=ctx, **kwargs)
PipenvUsageError.__init__(self, message=fix_utf8(message), ctx=ctx, **kwargs)
self.extra = extra
self.option_name = option_name

Expand All @@ -184,7 +184,7 @@ def __init__(self, hint=None, **kwargs):
hint = "{0} {1}".format(crayons.red("ERROR (PACKAGE NOT INSTALLED):"), hint)
filename = project.pipfile_location
extra = kwargs.pop("extra", [])
PipenvFileError.__init__(self, filename, hint, extra=extra, **kwargs)
PipenvFileError.__init__(self, filename, fix_utf8(hint), extra=extra, **kwargs)


class SetupException(PipenvException):
Expand All @@ -200,7 +200,7 @@ def __init__(self, message=None, **kwargs):
"There was an unexpected error while activating your virtualenv. "
"Continuing anyway..."
)
PipenvException.__init__(self, message, **kwargs)
PipenvException.__init__(self, fix_utf8(message), **kwargs)


class VirtualenvActivationException(VirtualenvException):
Expand All @@ -211,15 +211,15 @@ def __init__(self, message=None, **kwargs):
"not activated. Continuing anyway…"
)
self.message = message
VirtualenvException.__init__(self, message, **kwargs)
VirtualenvException.__init__(self, fix_utf8(message), **kwargs)


class VirtualenvCreationException(VirtualenvException):
def __init__(self, message=None, **kwargs):
if not message:
message = "Failed to create virtual environment."
self.message = message
VirtualenvException.__init__(self, message, **kwargs)
VirtualenvException.__init__(self, fix_utf8(message), **kwargs)


class UninstallError(PipenvException):
Expand All @@ -235,5 +235,49 @@ def __init__(self, package, command, return_values, return_code, **kwargs):
crayons.yellow(package, bold=True)
)
self.exit_code = return_code
PipenvException.__init__(self, message=message, extra=extra)
PipenvException.__init__(self, message=fix_utf8(message), extra=extra)
self.extra = extra


class CacheError(PipenvException):
def __init__(self, path, **kwargs):
message = "{0} {1} {2}\n{0}".format(
crayons.red("ERROR:", bold=True),
crayons.blue("Corrupt cache file"),
crayons.white(path),
crayons.white('Consider trying "pipenv lock --clear" to clear the cache.')
)
super(PipenvException, self).__init__(message=fix_utf8(message))


class ResolutionFailure(PipenvException):
def __init__(self, message, no_version_found=False):
extra = (
"{0}: Your dependencies could not be resolved. You likely have a "
"mismatch in your sub-dependencies.\n "
"First try clearing your dependency cache with {1}, then try the original command again.\n "
"Alternatively, you can use {2} to bypass this mechanism, then run "
"{3} to inspect the situation.\n "
"Hint: try {4} if it is a pre-release dependency."
"".format(
crayons.red("Warning", bold=True),
crayons.red("$ pipenv lock --clear"),
crayons.red("$ pipenv install --skip-lock"),
crayons.red("$ pipenv graph"),
crayons.red("$ pipenv lock --pre"),
),
)
if "no version found at all" in message:
no_version_found = True
message = "{0} {1}".format(
crayons.red("ERROR:", bold=True), crayons.yellow(message)
)
if no_version_found:
messsage = "{0}\n{1}".format(
message,
crayons.blue(
"Please check your version specifier and version number. "
"See PEP440 for more information."
)
)
super(ResolutionFailure, self).__init__(fix_utf8(message), extra=extra)
4 changes: 2 additions & 2 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import glob
import base64
import itertools
import fnmatch
import hashlib
import contoml
Expand Down Expand Up @@ -47,7 +46,6 @@
PIPENV_DEFAULT_PYTHON_VERSION,
PIPENV_CACHE_DIR
)
from requirementslib.utils import is_vcs


def _normalized(p):
Expand Down Expand Up @@ -173,6 +171,7 @@ def path_to(self, p):

def _build_package_list(self, package_section):
"""Returns a list of packages for pip-tools to consume."""
from pipenv.vendor.requirementslib.utils import is_vcs
ps = {}
# TODO: Separate the logic for showing packages from the filters for supplying pip-tools
for k, v in self.parsed_pipfile.get(package_section, {}).items():
Expand Down Expand Up @@ -677,6 +676,7 @@ def _get_editable_packages(self, dev=False):
return packages

def _get_vcs_packages(self, dev=False):
from pipenv.vendor.requirementslib.utils import is_vcs
section = "dev-packages" if dev else "packages"
# section = "{0}-vcs".format(section)
packages = {
Expand Down
Loading