Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/flit_core/, dev-python/flit_core/files/
Date: Wed, 23 Feb 2022 02:52:32
Message-Id: 1645584712.7631422bf0e6ca3ee0bbacd361f84fa9c96d48ef.sam@gentoo
1 commit: 7631422bf0e6ca3ee0bbacd361f84fa9c96d48ef
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 23 02:51:19 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 23 02:51:52 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7631422b
7
8 dev-python/flit_core: backport relative import fix
9
10 Fixes emerging e.g. pyparsing.
11
12 Bug: https://github.com/pypa/flit/pull/530
13 Bug: https://github.com/pypa/flit/pull/531
14 Signed-off-by: Sam James <sam <AT> gentoo.org>
15
16 ...e-3.7.0-fix-relative-imports-init-version.patch | 107 +++++++++++++++++++++
17 ...core-3.7.0.ebuild => flit_core-3.7.0-r1.ebuild} | 4 +
18 2 files changed, 111 insertions(+)
19
20 diff --git a/dev-python/flit_core/files/flit_core-3.7.0-fix-relative-imports-init-version.patch b/dev-python/flit_core/files/flit_core-3.7.0-fix-relative-imports-init-version.patch
21 new file mode 100644
22 index 000000000000..858e66aee0b0
23 --- /dev/null
24 +++ b/dev-python/flit_core/files/flit_core-3.7.0-fix-relative-imports-init-version.patch
25 @@ -0,0 +1,107 @@
26 +https://github.com/pypa/flit/issues/530
27 +https://github.com/pypa/flit/pull/531
28 +
29 +From c7c79459b61fe11ff0179d0ca7a72e8a90c0ee7b Mon Sep 17 00:00:00 2001
30 +From: Thomas Kluyver <thomas@××××××××××.uk>
31 +Date: Tue, 22 Feb 2022 16:21:11 +0000
32 +Subject: [PATCH 1/2] Add failing test for issue gh-530
33 +
34 +---
35 + .../samples/imported_version/package1/__init__.py | 3 +++
36 + .../samples/imported_version/package1/_version.py | 1 +
37 + .../tests/samples/imported_version/pyproject.toml | 10 ++++++++++
38 + flit_core/flit_core/tests/test_common.py | 5 +++++
39 + 4 files changed, 19 insertions(+)
40 + create mode 100644 flit_core/flit_core/tests/samples/imported_version/package1/__init__.py
41 + create mode 100644 flit_core/flit_core/tests/samples/imported_version/package1/_version.py
42 + create mode 100644 flit_core/flit_core/tests/samples/imported_version/pyproject.toml
43 +
44 +diff --git a/flit_core/tests/samples/imported_version/package1/__init__.py b/flit_core/tests/samples/imported_version/package1/__init__.py
45 +new file mode 100644
46 +index 0000000..49adc42
47 +--- /dev/null
48 ++++ b/flit_core/tests/samples/imported_version/package1/__init__.py
49 +@@ -0,0 +1,3 @@
50 ++"""This module has a __version__ that requires a relative import"""
51 ++
52 ++from ._version import __version__
53 +diff --git a/flit_core/tests/samples/imported_version/package1/_version.py b/flit_core/tests/samples/imported_version/package1/_version.py
54 +new file mode 100644
55 +index 0000000..91201fc
56 +--- /dev/null
57 ++++ b/flit_core/tests/samples/imported_version/package1/_version.py
58 +@@ -0,0 +1 @@
59 ++__version__ = '0.5.8'
60 +diff --git a/flit_core/tests/samples/imported_version/pyproject.toml b/flit_core/tests/samples/imported_version/pyproject.toml
61 +new file mode 100644
62 +index 0000000..b6d44e1
63 +--- /dev/null
64 ++++ b/flit_core/tests/samples/imported_version/pyproject.toml
65 +@@ -0,0 +1,10 @@
66 ++[build-system]
67 ++requires = ["flit_core >=3.2,<4"]
68 ++build-backend = "flit_core.buildapi"
69 ++
70 ++[project]
71 ++name = "package1"
72 ++authors = [
73 ++ {name = "Sir Röbin", email = "robin@×××××××.uk"}
74 ++]
75 ++dynamic = ["version", "description"]
76 +diff --git a/flit_core/tests/test_common.py b/flit_core/tests/test_common.py
77 +index 02cfab7..bd0995b 100644
78 +--- a/flit_core/tests/test_common.py
79 ++++ b/flit_core/tests/test_common.py
80 +@@ -75,6 +75,11 @@ def test_get_info_from_module(self):
81 + 'version': '1.2.3'}
82 + )
83 +
84 ++ info = get_info_from_module(Module('package1', samples_dir / 'imported_version'))
85 ++ self.assertEqual(info, {'summary': 'This module has a __version__ that requires a relative import',
86 ++ 'version': '0.5.8'}
87 ++ )
88 ++
89 + with self.assertRaises(InvalidVersion):
90 + get_info_from_module(Module('invalid_version1', samples_dir))
91 +
92 +
93 +From 8a0ce8897a743dde3b82cca02f1d82516ad393fd Mon Sep 17 00:00:00 2001
94 +From: Thomas Kluyver <thomas@××××××××××.uk>
95 +Date: Tue, 22 Feb 2022 16:49:46 +0000
96 +Subject: [PATCH 2/2] Fix relative imports in __init__.py when exec-ing to get
97 + __version__
98 +
99 +---
100 + flit_core/flit_core/common.py | 11 ++++++++++-
101 + 1 file changed, 10 insertions(+), 1 deletion(-)
102 +
103 +diff --git a/flit_core/common.py b/flit_core/common.py
104 +index 0d6716c..ce69c95 100644
105 +--- a/flit_core/common.py
106 ++++ b/flit_core/common.py
107 +@@ -3,6 +3,7 @@
108 + import hashlib
109 + import logging
110 + import os
111 ++import sys
112 +
113 + from pathlib import Path
114 + import re
115 +@@ -168,7 +169,15 @@ def get_docstring_and_version_via_import(target):
116 + spec = spec_from_file_location(mod_name, target.file)
117 + with _module_load_ctx():
118 + m = module_from_spec(spec)
119 +- spec.loader.exec_module(m)
120 ++ # Add the module to sys.modules to allow relative imports to work.
121 ++ # importlib has more code around this to handle the case where two
122 ++ # threads are trying to load the same module at the same time, but Flit
123 ++ # should always be running a single thread, so we won't duplicate that.
124 ++ sys.modules[mod_name] = m
125 ++ try:
126 ++ spec.loader.exec_module(m)
127 ++ finally:
128 ++ sys.modules.pop(mod_name, None)
129 +
130 + docstring = m.__dict__.get('__doc__', None)
131 + version = m.__dict__.get('__version__', None)
132 +
133
134 diff --git a/dev-python/flit_core/flit_core-3.7.0.ebuild b/dev-python/flit_core/flit_core-3.7.0-r1.ebuild
135 similarity index 93%
136 rename from dev-python/flit_core/flit_core-3.7.0.ebuild
137 rename to dev-python/flit_core/flit_core-3.7.0-r1.ebuild
138 index 5a8e37d303be..65fd6ed76f45 100644
139 --- a/dev-python/flit_core/flit_core-3.7.0.ebuild
140 +++ b/dev-python/flit_core/flit_core-3.7.0-r1.ebuild
141 @@ -25,6 +25,10 @@ BDEPEND="
142 test? ( dev-python/testpath[${PYTHON_USEDEP}] )
143 "
144
145 +PATCHES=(
146 + "${FILESDIR}"/${P}-fix-relative-imports-init-version.patch
147 +)
148 +
149 distutils_enable_tests pytest
150
151 src_prepare() {