Build failure due to version=None
We're seeing a weird build failure with recent setuptools/packaging versions on Gentoo:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/setuptools/_normalization.py", line 62, in safe_version
return str(packaging.version.Version(v))
File "/usr/lib/python3.10/site-packages/packaging/version.py", line 197, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'None'
To be honest, I don't know why exactly it started failing — it may be related to some setuptools plugins that could be randomly installed on the user's system. However, it seems to be caused by passing version=version
to the setup()
function whereas version
could be None
(when using SCM version).
It seems better to be passing the version
parameter only when it actually has a value. Here's a proposed patch that makes version
and other keyword arguments passed only conditionally via **kwargs
construct:
From 85dceb18136d09ec10f0bc8f0464c50e07d4bb9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Sun, 26 Feb 2023 16:14:38 +0100
Subject: [PATCH] setup.py: Avoid passing version=None to setup()
Avoid passing `version=None` to the `setup()` command as this is causing
the following error on Gentoo:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/setuptools/_normalization.py", line 62, in safe_version
return str(packaging.version.Version(v))
File "/usr/lib/python3.10/site-packages/packaging/version.py", line 197, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'None'
It is unclear why it is happening, it may be due to one of the installed
setuptools plugins. However, the problem is easily avoided by passing
`version` only when it actually has a value.
While at it, let's move all the other conditional parameters
to a **kwargs dict.
---
setup.py | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/setup.py b/setup.py
index f851596..6a07928 100755
--- a/setup.py
+++ b/setup.py
@@ -20,10 +20,9 @@ Make sure you have pip >= 9.0.1.
sys.exit(error)
+kwargs = {}
if os.name == 'nt' or not bool(int(os.getenv("ENABLE_SETUPTOOLS_SCM", 1))):
# setuptools_scm doesn't work in MSYS2
- setup_deps = []
- scm_version = {}
if not os.path.exists('src/pyocr/_version.py'):
version = subprocess.run(
['git', 'describe', '--always'],
@@ -41,15 +40,15 @@ if os.name == 'nt' or not bool(int(os.getenv("ENABLE_SETUPTOOLS_SCM", 1))):
version = line.strip()
version = version.split(" ")[2][1:-1]
break
+ kwargs['version'] = version
else:
- setup_deps = [
+ kwargs['setup_requires'] = [
'setuptools_scm<7',
'setuptools_scm_git_archive',
]
- scm_version = {
+ kwargs['use_scm_version'] = {
'write_to': 'src/pyocr/_version.py',
}
- version = None
setup(
@@ -61,7 +60,6 @@ setup(
"A Python wrapper for OCR engines (Tesseract, Cuneiform, etc)"
),
keywords="tesseract cuneiform ocr",
- version=version,
url="https://gitlab.gnome.org/World/OpenPaperwork/pyocr",
classifiers=[
"Development Status :: 5 - Production/Stable",
@@ -96,6 +94,5 @@ setup(
install_requires=[
"Pillow",
],
- setup_requires=setup_deps,
- use_scm_version=scm_version,
+ **kwargs
)
--
2.39.2
Original bug report: https://bugs.gentoo.org/897690