Skip to content

Commit 3c3aed1

Browse files
committed
util.distrib: add fallback for dist.files=None on Python 3.10
- Handle case where importlib.metadata.Distribution.files is None in Python 3.10 - Fallback to constructing site-packages/conf/<dist_name> path directly - Ensures get_files() can still locate configuration files when metadata is incomplete
1 parent 4cebc55 commit 3c3aed1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ampel/util/distrib.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# License: BSD-3-Clause
55
# Author: valery brinnel <firstname.lastname@gmail.com>
66
# Date: 13.03.2021
7-
# Last Modified Date: 06.11.2025
7+
# Last Modified Date: 14.11.2025
88
# Last Modified By: valery brinnel <firstname.lastname@gmail.com>
99

1010
import os, re, importlib, json
@@ -48,15 +48,25 @@ def get_files(
4848
files: PathList = []
4949

5050
for dist in metadata.distributions():
51+
5152
if dist.name != dist_name:
5253
continue
5354

54-
# Try direct_url.json first — even if no .pth file exists
55+
# Try direct_url.json first
5556
mod_path = resolve_direct_url_path(dist_name)
5657
if mod_path and os.path.isdir(mod_path):
5758
files.extend(walk_dir(mod_path, lookup_dir, pattern))
5859
break # skip .pth parsing if direct path works
5960

61+
# dist.files may be None in 3.10
62+
if dist.files is None:
63+
# fallback: look directly in site-packages
64+
sp = Path(str(dist.locate_file("")))
65+
conf_dir = sp / (lookup_dir or "") / dist_name
66+
if conf_dir.exists():
67+
files.extend(walk_dir(str(conf_dir), lookup_dir, pattern))
68+
continue
69+
6070
for p in dist.files or []:
6171
if p.suffix == ".pth":
6272
pth_path = Path(str(dist.locate_file(p)))
@@ -73,8 +83,8 @@ def get_files(
7383
files.extend(walk_dir(mod_path, lookup_dir, pattern))
7484
else:
7585
raise ValueError(
76-
f"Could not resolve module path from editable hook or direct_url.json in {pth_path}. "
77-
f"Try installing {dist_name} normally (non-editable)."
86+
f"Could not resolve module path from editable hook or direct_url.json "
87+
f"in {pth_path}. Try installing {dist_name} normally (non-editable)."
7888
)
7989
else:
8090
raise ValueError(

0 commit comments

Comments
 (0)