From ec1d3365299a0214db448e41e70fd8b80809dfb9 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Tue, 29 Oct 2024 13:58:28 +0100 Subject: [PATCH] Fix detection of editable installation This synchronises this code with kolla-ansible [1], preemptively fixing issues with Python 3.12. [1] https://review.opendev.org/c/openstack/kolla-ansible/+/933633 Change-Id: I027c48d7ff6fe06e1898720273fef3da571aabe4 --- kayobe/utils.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kayobe/utils.py b/kayobe/utils.py index f53d8e2b6..b70cb1029 100644 --- a/kayobe/utils.py +++ b/kayobe/utils.py @@ -54,15 +54,20 @@ def _detect_install_prefix(path): return prefix_path -def _get_direct_url(dist): +def _get_direct_url_if_editable(dist): direct_url = os.path.join(dist._path, 'direct_url.json') + editable = None if os.path.isfile(direct_url): with open(direct_url, 'r') as f: direct_url_content = json.loads(f.readline().strip()) - url = direct_url_content['url'] - prefix = 'file://' - if url.startswith(prefix): - return url[len(prefix):] + dir_info = direct_url_content.get('dir_info') + if dir_info is not None: + editable = dir_info.get('editable') + if editable: + url = direct_url_content['url'] + prefix = 'file://' + if url.startswith(prefix): + return url[len(prefix):] return None @@ -74,7 +79,7 @@ def _get_base_path(): kayobe_dist = list(Distribution.discover(name="kayobe")) if kayobe_dist: - direct_url = _get_direct_url(kayobe_dist[0]) + direct_url = _get_direct_url_if_editable(kayobe_dist[0]) if direct_url: return direct_url