From 4d5e0ca7a3a1b9914621813f6cb8827dd33a5c32 Mon Sep 17 00:00:00 2001 From: Will Miles Date: Sat, 11 Jan 2025 13:31:20 -0500 Subject: [PATCH] load_usermods: Expand name search Look for 'usermod_v2_x' as well. This could be removed later if we clean up the folder names. --- pio-scripts/load_usermods.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pio-scripts/load_usermods.py b/pio-scripts/load_usermods.py index ac7611319..55b9c4b1b 100644 --- a/pio-scripts/load_usermods.py +++ b/pio-scripts/load_usermods.py @@ -1,9 +1,26 @@ Import('env') +import os + +def find_usermod(mod_dir: str, mod: str): + """Locate this library in the usermods folder. + We do this to avoid needing to rename a bunch of folders; + this could be removed later + """ + # Check name match + mp = f"{mod_dir}/{mod}" + if os.path.exists(mp): + return mp + mp = f"{mod_dir}/usermod_v2_{mod}" + if os.path.exists(mp): + return mp + raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!") + usermods = env.GetProjectOption("custom_usermods","") if usermods: proj = env.GetProjectConfig() deps = env.GetProjectOption('lib_deps') src_dir = proj.get("platformio", "src_dir") src_dir = src_dir.replace('\\','/') - usermods = [f"{mod} = symlink://{src_dir}/../usermods/{mod}" for mod in usermods.split(" ")] + mod_paths = {mod: find_usermod(f"{src_dir}/../usermods", mod) for mod in usermods.split(" ")} + usermods = [f"{mod} = symlink://{path}" for mod, path in mod_paths.items()] proj.set("env:" + env['PIOENV'], 'lib_deps', deps + usermods)