0001-Fix-ast-version-parser-for-multiple-assignments.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From 2cd8b5708be88b90ea2fa0fb35407a5ec2038c8e Mon Sep 17 00:00:00 2001
  2. From: James Hilliard <james.hilliard1@gmail.com>
  3. Date: Sat, 27 Nov 2021 02:36:15 -0700
  4. Subject: [PATCH] Fix ast version parser for multiple assignments
  5. Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
  6. [Upstream status:
  7. https://github.com/takluyver/flit/pull/474]
  8. ---
  9. flit_core/common.py | 21 +++++++++++--------
  10. .../tests/samples/moduleunimportabledouble.py | 8 +++++++
  11. flit_core/tests/test_common.py | 5 +++++
  12. 3 files changed, 25 insertions(+), 9 deletions(-)
  13. create mode 100644 flit_core/tests/samples/moduleunimportabledouble.py
  14. diff --git a/flit_core/common.py b/flit_core/common.py
  15. index f1f378f..86bcf4b 100644
  16. --- a/flit_core/common.py
  17. +++ b/flit_core/common.py
  18. @@ -132,15 +132,18 @@ def get_docstring_and_version_via_ast(target):
  19. for child in node.body:
  20. # Only use the version from the given module if it's a simple
  21. # string assignment to __version__
  22. - is_version_str = (
  23. - isinstance(child, ast.Assign)
  24. - and len(child.targets) == 1
  25. - and isinstance(child.targets[0], ast.Name)
  26. - and child.targets[0].id == "__version__"
  27. - and isinstance(child.value, ast.Str)
  28. - )
  29. - if is_version_str:
  30. - version = child.value.s
  31. + if isinstance(child, ast.Assign):
  32. + for target in child.targets:
  33. + is_version_str = (
  34. + isinstance(target, ast.Name)
  35. + and target.id == "__version__"
  36. + and isinstance(child.value, ast.Str)
  37. + )
  38. + if is_version_str:
  39. + version = child.value.s
  40. + break
  41. + else:
  42. + continue
  43. break
  44. else:
  45. version = None
  46. diff --git a/flit_core/tests/samples/moduleunimportabledouble.py b/flit_core/tests/samples/moduleunimportabledouble.py
  47. new file mode 100644
  48. index 0000000..42d51f3
  49. --- /dev/null
  50. +++ b/flit_core/tests/samples/moduleunimportabledouble.py
  51. @@ -0,0 +1,8 @@
  52. +
  53. +"""
  54. +A sample unimportable module with double assignment
  55. +"""
  56. +
  57. +raise ImportError()
  58. +
  59. +VERSION = __version__ = "0.1"
  60. diff --git a/flit_core/tests/test_common.py b/flit_core/tests/test_common.py
  61. index 02cfab7..42e230b 100644
  62. --- a/flit_core/tests/test_common.py
  63. +++ b/flit_core/tests/test_common.py
  64. @@ -70,6 +70,11 @@ class ModuleTests(TestCase):
  65. 'version': '0.1'}
  66. )
  67. + info = get_info_from_module(Module('moduleunimportabledouble', samples_dir))
  68. + self.assertEqual(info, {'summary': 'A sample unimportable module with double assignment',
  69. + 'version': '0.1'}
  70. + )
  71. +
  72. info = get_info_from_module(Module('module1', samples_dir / 'constructed_version'))
  73. self.assertEqual(info, {'summary': 'This module has a __version__ that requires runtime interpretation',
  74. 'version': '1.2.3'}
  75. --
  76. 2.33.1