Coverage for src/gridtk/script/grid.py: 0%

17 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-04-22 14:25 +0200

1# Copyright © 2022 Idiap Research Institute <contact@idiap.ch> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4"""Executes a given command within the context of a shell script that has its 

5enviroment set like Idiap's 'SETSHELL grid' does.""" 

6 

7from __future__ import annotations 

8 

9import os 

10import shutil 

11import sys 

12 

13 

14def main() -> None: 

15 from ..setshell import environ 

16 

17 # get the name of the script that we actually want to execute 

18 # (as defined in the setup.py) 

19 prog = os.path.basename(sys.argv[0]) 

20 

21 # get the base environment for searching for the command 

22 env = environ("grid") 

23 

24 # removes the location from the current program from the list of paths to 

25 # search 

26 install_dir = os.path.realpath(os.path.dirname(sys.argv[0])) 

27 paths = env.get("PATH", os.defpath).split(os.pathsep) 

28 paths = [k for k in paths if os.path.realpath(k) != install_dir] 

29 env["PATH"] = os.pathsep.join(paths) 

30 

31 # check that this program is avalid on that environment 

32 app = shutil.which(prog, path=env["PATH"]) 

33 

34 if app is None: 

35 raise RuntimeError( 

36 f"The CLI {prog} is not available when SETSHELL " 

37 f"grid is executed. Are you at an Idiap computer?" 

38 ) 

39 

40 # call that specific command on the grid environment 

41 os.execvpe(prog, sys.argv, env)