Skip to content

Commit e8f8d31

Browse files
bartgolmahf708
authored andcommitted
Add get-mach-env executable to the package
1 parent 5cb364b commit e8f8d31

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

cacts/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
""" Main entry point for cacts"""
22

33
from cacts.cacts import main as cacts_main
4+
from cacts.get_mach_env import print_mach_env
45

56
__version__ = "0.1.0"
67

78
def main() -> None:
89
cacts_main()
10+
11+
def get_mach_env() -> None:
12+
print_mach_env()

cacts/get_mach_env.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import sys
3+
import pathlib
4+
import argparse
5+
6+
from .parse_config import parse_project, parse_machine
7+
from .utils import check_minimum_python_version, GoodFormatter
8+
9+
check_minimum_python_version(3, 4)
10+
11+
###############################################################################
12+
def print_mach_env():
13+
###############################################################################
14+
from . import __version__ # Import __version__ here to avoid circular import
15+
16+
args = vars(parse_command_line(sys.argv, __doc__, __version__))
17+
18+
project = parse_project(args['config_file'],args['root_dir'])
19+
machine = parse_machine(args['config_file'],project,args['machine_name'])
20+
21+
print(" && ".join(machine.env_setup))
22+
23+
sys.exit(0)
24+
25+
###############################################################################
26+
def parse_command_line(args, description, version):
27+
###############################################################################
28+
parser = argparse.ArgumentParser(
29+
usage="""\n{0} <ARGS> [--verbose]
30+
OR
31+
{0} --help
32+
33+
\033[1mEXAMPLES:\033[0m
34+
\033[1;32m# Get the env setup command for machine 'foo' using config file my_config.yaml \033[0m
35+
> ./{0} foo -f my_config.yaml
36+
""".format(pathlib.Path(args[0]).name),
37+
description=description,
38+
formatter_class=GoodFormatter
39+
)
40+
41+
parser.add_argument("-f","--config-file", default=f"{os.getcwd()}/cacts.yaml",
42+
help="YAML file containing valid project/machine settings")
43+
44+
parser.add_argument("-r", "--root-dir", default=f"{os.getcwd()}",
45+
help="The root directory of the project, where the main CMakeLists.txt file is located")
46+
47+
parser.add_argument("machine_name", help="The machine name for which you want the scream env")
48+
49+
return parser.parse_args(args[1:])

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dev = [
2626

2727
[project.scripts]
2828
cacts = "cacts:main"
29+
get-mach-env = "cacts:get_mach_env"
2930

3031
[tool.hatch.version]
3132
path = "cacts/__init__.py"

0 commit comments

Comments
 (0)