From 279304ef306220d0cfe2beb85deb2bd078e95142 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 09:34:04 -0500 Subject: [PATCH] fixtures: tracker generators load _tracker by path (tools/fixtures/ on sys.path shadowed xml with xml.py) --- tools/fixtures/it.py | 10 ++++++++-- tools/fixtures/mod.py | 10 ++++++++-- tools/fixtures/s3m.py | 10 ++++++++-- tools/fixtures/xm.py | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tools/fixtures/it.py b/tools/fixtures/it.py index 39ae6d6..493d525 100644 --- a/tools/fixtures/it.py +++ b/tools/fixtures/it.py @@ -5,8 +5,14 @@ # duration (openmpt's song length), plain (for "compressed": the same song uncompressed) } import os, sys -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import _tracker as T # noqa: E402 +# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml) +T = sys.modules.get("_tracker") +if T is None: + import importlib.util + _spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py")) + T = importlib.util.module_from_spec(_spec) + sys.modules["_tracker"] = T + _spec.loader.exec_module(T) INPUTS = ["tools/fixtures/_tracker.py"] diff --git a/tools/fixtures/mod.py b/tools/fixtures/mod.py index 6b63f81..25b9b67 100644 --- a/tools/fixtures/mod.py +++ b/tools/fixtures/mod.py @@ -3,8 +3,14 @@ # duration (openmpt's song length) } import os, sys -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import _tracker as T # noqa: E402 +# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml) +T = sys.modules.get("_tracker") +if T is None: + import importlib.util + _spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py")) + T = importlib.util.module_from_spec(_spec) + sys.modules["_tracker"] = T + _spec.loader.exec_module(T) INPUTS = ["tools/fixtures/_tracker.py"] diff --git a/tools/fixtures/s3m.py b/tools/fixtures/s3m.py index 17ea196..d8a983e 100644 --- a/tools/fixtures/s3m.py +++ b/tools/fixtures/s3m.py @@ -3,8 +3,14 @@ # duration (openmpt's song length) } import os, sys -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import _tracker as T # noqa: E402 +# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml) +T = sys.modules.get("_tracker") +if T is None: + import importlib.util + _spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py")) + T = importlib.util.module_from_spec(_spec) + sys.modules["_tracker"] = T + _spec.loader.exec_module(T) INPUTS = ["tools/fixtures/_tracker.py"] diff --git a/tools/fixtures/xm.py b/tools/fixtures/xm.py index fd40898..812302e 100644 --- a/tools/fixtures/xm.py +++ b/tools/fixtures/xm.py @@ -4,8 +4,14 @@ # duration (openmpt's song length) } import os, sys -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import _tracker as T # noqa: E402 +# the shared tracker module, loaded by path (tools/fixtures/ must not go on sys.path: xml.py there would shadow xml) +T = sys.modules.get("_tracker") +if T is None: + import importlib.util + _spec = importlib.util.spec_from_file_location("_tracker", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_tracker.py")) + T = importlib.util.module_from_spec(_spec) + sys.modules["_tracker"] = T + _spec.loader.exec_module(T) INPUTS = ["tools/fixtures/_tracker.py"]