-
Notifications
You must be signed in to change notification settings - Fork 0
Add get-mach-env utility executable #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
""" Main entry point for cacts""" | ||
|
||
from cacts.cacts import main as cacts_main | ||
from cacts.get_mach_env import print_mach_env | ||
|
||
__version__ = "0.1.0" | ||
|
||
def main() -> None: | ||
cacts_main() | ||
|
||
def get_mach_env() -> None: | ||
print_mach_env() | ||
bartgol marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import sys | ||
import pathlib | ||
import argparse | ||
|
||
from .parse_config import parse_project, parse_machine | ||
from .utils import check_minimum_python_version, GoodFormatter | ||
|
||
check_minimum_python_version(3, 4) | ||
|
||
############################################################################### | ||
def print_mach_env(): | ||
############################################################################### | ||
from . import __version__ # Import __version__ here to avoid circular import | ||
|
||
args = vars(parse_command_line(sys.argv, __doc__, __version__)) | ||
|
||
project = parse_project(args['config_file'],args['root_dir']) | ||
machine = parse_machine(args['config_file'],project,args['machine_name']) | ||
|
||
print(" && ".join(machine.env_setup)) | ||
|
||
sys.exit(0) | ||
|
||
############################################################################### | ||
def parse_command_line(args, description, version): | ||
############################################################################### | ||
parser = argparse.ArgumentParser( | ||
usage="""\n{0} <ARGS> [--verbose] | ||
OR | ||
{0} --help | ||
|
||
\033[1mEXAMPLES:\033[0m | ||
\033[1;32m# Get the env setup command for machine 'foo' using config file my_config.yaml \033[0m | ||
> ./{0} foo -f my_config.yaml | ||
""".format(pathlib.Path(args[0]).name), | ||
description=description, | ||
formatter_class=GoodFormatter | ||
) | ||
|
||
parser.add_argument("-f","--config-file", default=f"{os.getcwd()}/cacts.yaml", | ||
help="YAML file containing valid project/machine settings") | ||
|
||
parser.add_argument("-r", "--root-dir", default=f"{os.getcwd()}", | ||
help="The root directory of the project, where the main CMakeLists.txt file is located") | ||
|
||
parser.add_argument("machine_name", help="The machine name for which you want the scream env") | ||
|
||
return parser.parse_args(args[1:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import pathlib | ||
import yaml | ||
|
||
from .project import Project | ||
from .machine import Machine | ||
from .build_type import BuildType | ||
from .utils import expect, check_minimum_python_version | ||
|
||
check_minimum_python_version(3, 4) | ||
|
||
############################################################################### | ||
def parse_project(config_file,root_dir): | ||
############################################################################### | ||
content = yaml.load(open(config_file,"r"),Loader=yaml.SafeLoader) | ||
|
||
expect ('project' in content.keys(), | ||
"Missing 'project' section in configuration file\n" | ||
f" - config file: {config_file}\n" | ||
f" - sections found: {','.join(content.keys())}\n") | ||
|
||
# Build Project | ||
return Project(content['project'],root_dir) | ||
|
||
############################################################################### | ||
def parse_machine(config_file,project,machine_name): | ||
############################################################################### | ||
content = yaml.load(open(config_file,"r"),Loader=yaml.SafeLoader) | ||
|
||
expect ('machines' in content.keys(), | ||
"Missing 'machines' section in configuration file\n" | ||
f" - config file: {config_file}\n" | ||
f" - sections found: {','.join(content.keys())}\n") | ||
|
||
# Special handling of 'local' machine | ||
machs = content['machines'] | ||
if machine_name=="local": | ||
local_yaml = pathlib.Path("~/.cime/cacts.yaml").expanduser() | ||
local_content = yaml.load(open(local_yaml,'r'),Loader=yaml.SafeLoader) | ||
machs.update(local_content['machines']) | ||
machine_name = 'local' | ||
|
||
# Build Machine | ||
return Machine(machine_name,project,machs) | ||
|
||
############################################################################### | ||
def parse_builds(config_file,project,machine,generate,build_types=None): | ||
############################################################################### | ||
content = yaml.load(open(config_file,"r"),Loader=yaml.SafeLoader) | ||
|
||
expect ('configurations' in content.keys(), | ||
"Missing 'configurations' section in configuration file\n" | ||
f" - config file: {config_file}\n" | ||
f" - sections found: {','.join(content.keys())}\n") | ||
|
||
# Get builds | ||
builds = [] | ||
if build_types: | ||
for name in build_types: | ||
build = BuildType(name,project,machine,content['configurations']) | ||
# Skip non-baselines builds when generating baselines | ||
if not generate or build.uses_baselines: | ||
builds.append(build) | ||
else: | ||
# Add all build types that are on by default | ||
for name in configs.keys(): | ||
if name=='default': | ||
continue | ||
build = BuildType(name,project,machine,content['configurations']) | ||
|
||
# Skip non-baselines builds when generating baselines | ||
if (not generate or build.uses_baselines) and build.on_by_default: | ||
builds.append(build) | ||
|
||
return builds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.