11#!/usr/bin/env python3
22"""
3- Tiny helper for GitHub Actions.
3+ Tiny helper for GitHub Actions *and* Docker builds .
44
55Usage:
6- python3 scripts/ci/ get_excludes.py flows # → prints "id1;id2;…"
7- python3 scripts/ci/ get_excludes.py nodes # → prints "url1;url2;…"
6+ python3 get_excludes.py flows # → prints "id1;id2;…"
7+ python3 get_excludes.py nodes # → prints "url1;url2;…"
88
9- It simply echoes the semicolon-joined list so the caller can redirect it
10- into the desired environment variable.
9+ It echoes a semicolon-joined list so callers can assign it to an environment variable, e.g.:
10+
11+ VISIONATRIX_INSTALL_EXCLUDE_NODES="$(python /get_excludes.py nodes)"
1112"""
1213
1314from __future__ import annotations
@@ -28,21 +29,43 @@ def _import_list(file: Path, var: str) -> Sequence[str]:
2829 return value
2930
3031
32+ def find_repo_root () -> Path :
33+ """
34+ Locate directory that contains ex_app/lib/ .
35+ Strategy (first match wins):
36+ 1. Walk up from this script's directory.
37+ 2. Walk up from CWD (useful if script is executed via absolute path).
38+ 3. Fallback to filesystem root (where Dockerfile copies it as /ex_app/lib).
39+ """
40+ def search_up (start : Path ) -> Path | None :
41+ for p in [start , * list (start .parents )]:
42+ if (p / "ex_app" / "lib" ).is_dir ():
43+ return p
44+ return None
45+
46+ here = Path (__file__ ).resolve ().parent
47+ return search_up (here ) or search_up (Path .cwd ()) or Path ("/" )
48+
49+
3150def main () -> None :
3251 if len (sys .argv ) != 2 or sys .argv [1 ] not in {"flows" , "nodes" }:
3352 print ("Usage: get_excludes.py [flows|nodes]" , file = sys .stderr )
3453 sys .exit (1 )
3554
3655 mode = sys .argv [1 ]
37- repo_root = Path ( __file__ ). resolve (). parents [ 2 ] # <repo>/scripts/ci/…
56+ repo_root = find_repo_root () # <repo root> or "/" inside container
3857
3958 if mode == "flows" :
4059 py_file = repo_root / "ex_app" / "lib" / "exclude_flows.py"
4160 var_name = "EXCLUDE_FLOWS_IDS"
42- else : # nodes
61+ else :
4362 py_file = repo_root / "ex_app" / "lib" / "exclude_nodes.py"
4463 var_name = "EXCLUDE_NODES_IDS"
4564
65+ if not py_file .is_file ():
66+ print (f"Error: cannot locate { py_file } " , file = sys .stderr )
67+ sys .exit (2 )
68+
4669 items = _import_list (py_file , var_name )
4770 print (";" .join (items ))
4871
0 commit comments