* [gentoo-commits] repo/gentoo:master commit in: dev-python/flit_core/, dev-python/flit_core/files/
@ 2022-02-23 2:52 Sam James
0 siblings, 0 replies; only message in thread
From: Sam James @ 2022-02-23 2:52 UTC (permalink / raw
To: gentoo-commits
commit: 7631422bf0e6ca3ee0bbacd361f84fa9c96d48ef
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 23 02:51:19 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Feb 23 02:51:52 2022 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7631422b
dev-python/flit_core: backport relative import fix
Fixes emerging e.g. pyparsing.
Bug: https://github.com/pypa/flit/pull/530
Bug: https://github.com/pypa/flit/pull/531
Signed-off-by: Sam James <sam <AT> gentoo.org>
...e-3.7.0-fix-relative-imports-init-version.patch | 107 +++++++++++++++++++++
...core-3.7.0.ebuild => flit_core-3.7.0-r1.ebuild} | 4 +
2 files changed, 111 insertions(+)
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
new file mode 100644
index 000000000000..858e66aee0b0
--- /dev/null
+++ b/dev-python/flit_core/files/flit_core-3.7.0-fix-relative-imports-init-version.patch
@@ -0,0 +1,107 @@
+https://github.com/pypa/flit/issues/530
+https://github.com/pypa/flit/pull/531
+
+From c7c79459b61fe11ff0179d0ca7a72e8a90c0ee7b Mon Sep 17 00:00:00 2001
+From: Thomas Kluyver <thomas@kluyver.me.uk>
+Date: Tue, 22 Feb 2022 16:21:11 +0000
+Subject: [PATCH 1/2] Add failing test for issue gh-530
+
+---
+ .../samples/imported_version/package1/__init__.py | 3 +++
+ .../samples/imported_version/package1/_version.py | 1 +
+ .../tests/samples/imported_version/pyproject.toml | 10 ++++++++++
+ flit_core/flit_core/tests/test_common.py | 5 +++++
+ 4 files changed, 19 insertions(+)
+ create mode 100644 flit_core/flit_core/tests/samples/imported_version/package1/__init__.py
+ create mode 100644 flit_core/flit_core/tests/samples/imported_version/package1/_version.py
+ create mode 100644 flit_core/flit_core/tests/samples/imported_version/pyproject.toml
+
+diff --git a/flit_core/tests/samples/imported_version/package1/__init__.py b/flit_core/tests/samples/imported_version/package1/__init__.py
+new file mode 100644
+index 0000000..49adc42
+--- /dev/null
++++ b/flit_core/tests/samples/imported_version/package1/__init__.py
+@@ -0,0 +1,3 @@
++"""This module has a __version__ that requires a relative import"""
++
++from ._version import __version__
+diff --git a/flit_core/tests/samples/imported_version/package1/_version.py b/flit_core/tests/samples/imported_version/package1/_version.py
+new file mode 100644
+index 0000000..91201fc
+--- /dev/null
++++ b/flit_core/tests/samples/imported_version/package1/_version.py
+@@ -0,0 +1 @@
++__version__ = '0.5.8'
+diff --git a/flit_core/tests/samples/imported_version/pyproject.toml b/flit_core/tests/samples/imported_version/pyproject.toml
+new file mode 100644
+index 0000000..b6d44e1
+--- /dev/null
++++ b/flit_core/tests/samples/imported_version/pyproject.toml
+@@ -0,0 +1,10 @@
++[build-system]
++requires = ["flit_core >=3.2,<4"]
++build-backend = "flit_core.buildapi"
++
++[project]
++name = "package1"
++authors = [
++ {name = "Sir Röbin", email = "robin@camelot.uk"}
++]
++dynamic = ["version", "description"]
+diff --git a/flit_core/tests/test_common.py b/flit_core/tests/test_common.py
+index 02cfab7..bd0995b 100644
+--- a/flit_core/tests/test_common.py
++++ b/flit_core/tests/test_common.py
+@@ -75,6 +75,11 @@ def test_get_info_from_module(self):
+ 'version': '1.2.3'}
+ )
+
++ info = get_info_from_module(Module('package1', samples_dir / 'imported_version'))
++ self.assertEqual(info, {'summary': 'This module has a __version__ that requires a relative import',
++ 'version': '0.5.8'}
++ )
++
+ with self.assertRaises(InvalidVersion):
+ get_info_from_module(Module('invalid_version1', samples_dir))
+
+
+From 8a0ce8897a743dde3b82cca02f1d82516ad393fd Mon Sep 17 00:00:00 2001
+From: Thomas Kluyver <thomas@kluyver.me.uk>
+Date: Tue, 22 Feb 2022 16:49:46 +0000
+Subject: [PATCH 2/2] Fix relative imports in __init__.py when exec-ing to get
+ __version__
+
+---
+ flit_core/flit_core/common.py | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/flit_core/common.py b/flit_core/common.py
+index 0d6716c..ce69c95 100644
+--- a/flit_core/common.py
++++ b/flit_core/common.py
+@@ -3,6 +3,7 @@
+ import hashlib
+ import logging
+ import os
++import sys
+
+ from pathlib import Path
+ import re
+@@ -168,7 +169,15 @@ def get_docstring_and_version_via_import(target):
+ spec = spec_from_file_location(mod_name, target.file)
+ with _module_load_ctx():
+ m = module_from_spec(spec)
+- spec.loader.exec_module(m)
++ # Add the module to sys.modules to allow relative imports to work.
++ # importlib has more code around this to handle the case where two
++ # threads are trying to load the same module at the same time, but Flit
++ # should always be running a single thread, so we won't duplicate that.
++ sys.modules[mod_name] = m
++ try:
++ spec.loader.exec_module(m)
++ finally:
++ sys.modules.pop(mod_name, None)
+
+ docstring = m.__dict__.get('__doc__', None)
+ version = m.__dict__.get('__version__', None)
+
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
similarity index 93%
rename from dev-python/flit_core/flit_core-3.7.0.ebuild
rename to dev-python/flit_core/flit_core-3.7.0-r1.ebuild
index 5a8e37d303be..65fd6ed76f45 100644
--- a/dev-python/flit_core/flit_core-3.7.0.ebuild
+++ b/dev-python/flit_core/flit_core-3.7.0-r1.ebuild
@@ -25,6 +25,10 @@ BDEPEND="
test? ( dev-python/testpath[${PYTHON_USEDEP}] )
"
+PATCHES=(
+ "${FILESDIR}"/${P}-fix-relative-imports-init-version.patch
+)
+
distutils_enable_tests pytest
src_prepare() {
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-23 2:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-23 2:52 [gentoo-commits] repo/gentoo:master commit in: dev-python/flit_core/, dev-python/flit_core/files/ Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox