kumquat-buildroot/package/python-flit-core/0001-Fix-ast-version-parser-for-multiple-assignments.patch

81 lines
3.0 KiB
Diff
Raw Normal View History

From 2cd8b5708be88b90ea2fa0fb35407a5ec2038c8e Mon Sep 17 00:00:00 2001
From: James Hilliard <james.hilliard1@gmail.com>
Date: Sat, 27 Nov 2021 02:36:15 -0700
Subject: [PATCH] Fix ast version parser for multiple assignments
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
[Upstream status:
https://github.com/takluyver/flit/pull/474]
---
flit_core/common.py | 21 +++++++++++--------
.../tests/samples/moduleunimportabledouble.py | 8 +++++++
flit_core/tests/test_common.py | 5 +++++
3 files changed, 25 insertions(+), 9 deletions(-)
create mode 100644 flit_core/tests/samples/moduleunimportabledouble.py
diff --git a/flit_core/common.py b/flit_core/common.py
index f1f378f..86bcf4b 100644
--- a/flit_core/common.py
+++ b/flit_core/common.py
@@ -132,15 +132,18 @@ def get_docstring_and_version_via_ast(target):
for child in node.body:
# Only use the version from the given module if it's a simple
# string assignment to __version__
- is_version_str = (
- isinstance(child, ast.Assign)
- and len(child.targets) == 1
- and isinstance(child.targets[0], ast.Name)
- and child.targets[0].id == "__version__"
- and isinstance(child.value, ast.Str)
- )
- if is_version_str:
- version = child.value.s
+ if isinstance(child, ast.Assign):
+ for target in child.targets:
+ is_version_str = (
+ isinstance(target, ast.Name)
+ and target.id == "__version__"
+ and isinstance(child.value, ast.Str)
+ )
+ if is_version_str:
+ version = child.value.s
+ break
+ else:
+ continue
break
else:
version = None
diff --git a/flit_core/tests/samples/moduleunimportabledouble.py b/flit_core/tests/samples/moduleunimportabledouble.py
new file mode 100644
index 0000000..42d51f3
--- /dev/null
+++ b/flit_core/tests/samples/moduleunimportabledouble.py
@@ -0,0 +1,8 @@
+
+"""
+A sample unimportable module with double assignment
+"""
+
+raise ImportError()
+
+VERSION = __version__ = "0.1"
diff --git a/flit_core/tests/test_common.py b/flit_core/tests/test_common.py
index 02cfab7..42e230b 100644
--- a/flit_core/tests/test_common.py
+++ b/flit_core/tests/test_common.py
@@ -70,6 +70,11 @@ class ModuleTests(TestCase):
'version': '0.1'}
)
+ info = get_info_from_module(Module('moduleunimportabledouble', samples_dir))
+ self.assertEqual(info, {'summary': 'A sample unimportable module with double assignment',
+ 'version': '0.1'}
+ )
+
info = get_info_from_module(Module('module1', samples_dir / 'constructed_version'))
self.assertEqual(info, {'summary': 'This module has a __version__ that requires runtime interpretation',
'version': '1.2.3'}
--
2.33.1