Files
pipenv/pipenv/utils/exceptions.py
T
Matt Davis 6ac1451ec8 stop using requirementslib models (#5793)
* Move away from requirementslib models

* Revise test since PEP-440 does not support wildcard versions but does support equivalent compatible release specifiers.

* simplify and remove dead code

* Ensure the os_name marker is AND with the other markers.

* Move what we still need from requirementslib into the pipenv utils and stop vendoring it.

* Remove requirementslib.

* force upgrade of virtualenv for python 3.12

* remove virtualenv-clone

* Update vcs specifiers documentation; infer name from specific pip line formats where possible.

* Provide helpful text and error for recently removed commands

* Set the right log levels and verbosity to show users the errors generated by pip resolver when supplying -v flag

* Fix the collection of all matching package hashes for non-pypi indexes.  Plus lesson from testing torch which contains local identifiers.
2023-08-19 16:36:52 -04:00

93 lines
3.0 KiB
Python

import errno
import os
import sys
class RequirementError(Exception):
pass
class MissingParameter(Exception):
def __init__(self, param):
self.message = self.get_message(param)
super().__init__(self.message)
@classmethod
def get_message(cls, param):
return "Missing Parameter: %s" % param
def show(self, param):
print(self.message, file=sys.stderr, flush=True)
class FileCorruptException(OSError):
def __init__(self, path, *args, **kwargs):
backup_path = kwargs.pop("backup_path", None)
if not backup_path and args:
args = reversed(args)
backup_path = args.pop()
if not isinstance(backup_path, str) or not os.path.exists(
os.path.abspath(os.path.dirname(backup_path))
):
args.append(backup_path)
backup_path = None
if args:
args = reversed(args)
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load file at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour lockfile is corrupt, {msg}"
return message
def show(self):
print(self.message, file=sys.stderr, flush=True)
class LockfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load lockfile at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour lockfile is corrupt, {msg}"
return message
def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)
class PipfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super().__init__(self.message)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load Pipfile at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced on the next lock."
message = f"{message}\nYour Pipfile is corrupt, {msg}"
return message
def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)
class PipfileNotFound(FileNotFoundError):
def __init__(self, path, *args, **kwargs):
self.errno = errno.ENOENT
self.filename = path
super().__init__(self.filename)