summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python3/deterministic_imports.patch
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2025-04-29 16:29:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-05-01 14:22:53 +0100
commit83d0d473d6d5a8d59875b0af581d27267e804ba9 (patch)
tree52144fc0087e5f8e9836813b2611d3f5d585c76b /meta/recipes-devtools/python/python3/deterministic_imports.patch
parentcf9c5ac2c152a7b53a1306cbde88bc3c0131028f (diff)
downloadpoky-83d0d473d6d5a8d59875b0af581d27267e804ba9.tar.gz
python3: backport the full fix for importlib scanning invalid distributions
Even with our fixes in deterministic_imports.patch the importlib.metadata package scan was still returning Distribution objects for empty directories. This interacts badly with rebuilds when recipes are changing as when a recipe is removed from the sysroot directories are not removed[1]. In particular this breaks python3-meson-python-native rebuilds when Meson upgrades from 1.7 to 1.8: the site-packages directory has an empty meson-1.7.dist-info/ and populated meson-1.8.dist-info/. Whilst it's deterministic to return the empty 1.7 first, this breaks pypa/build as it looks through the distributions in order. We had discussed this with upstream previously and there's a more comprehensive fix upstream (actually in importlib_metadata, not cpython) which ensures that valid distribution objects are listed first. So we can drop our patch and replace it with a backport to fix these rebuilds. [1] oe-core 4f94d929639 ("sstate/staging: Handle directory creation race issue") (From OE-Core rev: 73de8daa6293403f5b92d313af32882c47bce396) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/python/python3/deterministic_imports.patch')
-rw-r--r--meta/recipes-devtools/python/python3/deterministic_imports.patch39
1 files changed, 0 insertions, 39 deletions
diff --git a/meta/recipes-devtools/python/python3/deterministic_imports.patch b/meta/recipes-devtools/python/python3/deterministic_imports.patch
deleted file mode 100644
index 61f136ef42..0000000000
--- a/meta/recipes-devtools/python/python3/deterministic_imports.patch
+++ /dev/null
@@ -1,39 +0,0 @@
1From 0a02e3b85176a5ce4dd98830bb65dac8596142e9 Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Fri, 27 May 2022 17:05:44 +0100
4Subject: [PATCH] python3: Ensure stale empty python module directories don't
5
6There are two issues here. Firstly, the modules are accessed in on disk order. This
7means behaviour seen on one system might not reproduce on another and is a real headache.
8
9Secondly, empty directories left behind by previous modules might be looked at. This
10has caused a long string of different issues for us.
11
12As a result, patch this to a behaviour which works for us.
13
14Upstream-Status: Submitted [https://github.com/python/cpython/issues/120492; need to first talk to upstream to see if they'll take one or both fixes]
15Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
16---
17 Lib/importlib/metadata/__init__.py | 9 ++++++++-
18 1 file changed, 8 insertions(+), 1 deletion(-)
19
20diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
21index 8ce62dd..a6ea6e9 100644
22--- a/Lib/importlib/metadata/__init__.py
23+++ b/Lib/importlib/metadata/__init__.py
24@@ -786,7 +786,14 @@ class Lookup:
25 self.infos = FreezableDefaultDict(list)
26 self.eggs = FreezableDefaultDict(list)
27
28- for child in path.children():
29+ for child in sorted(path.children()):
30+ childpath = pathlib.Path(path.root, child)
31+ try:
32+ if childpath.is_dir() and not any(childpath.iterdir()):
33+ # Empty directories aren't interesting
34+ continue
35+ except PermissionError:
36+ continue
37 low = child.lower()
38 if low.endswith((".dist-info", ".egg-info")):
39 # rpartition is faster than splitext and suitable for this purpose.