summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.d/3776.misc.rst2
-rw-r--r--pkg_resources/__init__.py9
-rw-r--r--setuptools/__init__.py21
3 files changed, 31 insertions, 1 deletions
diff --git a/changelog.d/3776.misc.rst b/changelog.d/3776.misc.rst
new file mode 100644
index 00000000..3a9ba9d8
--- /dev/null
+++ b/changelog.d/3776.misc.rst
@@ -0,0 +1,2 @@
+Added note about using the ``--pep-517`` flag with ``pip`` to workaround
+``InvalidVersion`` errors for packages that are already installed in the system.
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index bba775b9..db4879d3 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2675,7 +2675,14 @@ class Distribution:
@property
def parsed_version(self):
if not hasattr(self, "_parsed_version"):
- self._parsed_version = parse_version(self.version)
+ try:
+ self._parsed_version = parse_version(self.version)
+ except packaging.version.InvalidVersion as ex:
+ info = f"(package: {self.project_name})"
+ if hasattr(ex, "add_note"):
+ ex.add_note(info) # PEP 678
+ raise
+ raise packaging.version.InvalidVersion(f"{str(ex)} {info}") from None
return self._parsed_version
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index 6c24cc2b..89f6f06e 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -77,7 +77,28 @@ def _install_setup_requires(attrs):
# Honor setup.cfg's options.
dist.parse_config_files(ignore_option_errors=True)
if dist.setup_requires:
+ _fetch_build_eggs(dist)
+
+
+def _fetch_build_eggs(dist):
+ try:
dist.fetch_build_eggs(dist.setup_requires)
+ except Exception as ex:
+ msg = """
+ It is possible a package already installed in your system
+ contains an version that is invalid according to PEP 440.
+ You can try `pip install --use-pep517` as a workaround for this problem,
+ or rely on a new virtual environment.
+
+ If the problem refers to a package that is not installed yet,
+ please contact that package's maintainers or distributors.
+ """
+ if "InvalidVersion" in ex.__class__.__name__:
+ if hasattr(ex, "add_note"):
+ ex.add_note(msg) # PEP 678
+ else:
+ dist.announce(f"\n{msg}\n")
+ raise
def setup(**attrs):