Skip to content

Commit

Permalink
Merge pull request #1113 from TeamCOMPAS/use_default_config_for_ci
Browse files Browse the repository at this point in the history
add option to use default config (and remove redundant test config file)
  • Loading branch information
ilyamandel committed May 10, 2024
2 parents abcfe78 + f7cffad commit e1896d2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 288 deletions.
23 changes: 15 additions & 8 deletions compas_python_utils/preprocessing/runSubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
from subprocess import call
import yaml
import argparse
import warnings

# Check if we are using python 3
python_version = sys.version_info[0]
print("python_version =", python_version)

HERE = os.path.dirname(__file__)
DEFAULT_CONFIG_FILE = os.path.join(HERE, 'compasConfigDefault.yaml')

REPO_ROOT = os.path.abspath(os.path.join(HERE, "../../"))

class pythonProgramOptions:
"""
Expand Down Expand Up @@ -42,10 +43,15 @@ def __init__(self, config_file=DEFAULT_CONFIG_FILE, grid_filename=None,
self.stringChoices = config['stringChoices'] if config['stringChoices'] else {}
self.listChoices = config['listChoices'] if config['listChoices'] else {}

compas_executable_override = os.environ.get(
'COMPAS_EXECUTABLE_PATH',
os.path.join(os.environ.get('COMPAS_ROOT_DIR'), 'src/COMPAS')
)
compas_root_dir = os.environ.get('COMPAS_ROOT_DIR', REPO_ROOT)
if compas_root_dir is None:
warnings.warn(
'COMPAS_ROOT_DIR environment variable not set. Setting '
f'`export COMPAS_ROOT_DIR={REPO_ROOT}`'
)
os.environ['COMPAS_ROOT_DIR'] = REPO_ROOT
compas_exe = os.path.join(compas_root_dir, 'src/COMPAS')
compas_executable_override = os.environ.get('COMPAS_EXECUTABLE_PATH', compas_exe)
print('compas_executable_override', compas_executable_override)
self.compas_executable = compas_executable_override

Expand Down Expand Up @@ -148,14 +154,15 @@ def makeCommandString(self):
return


def runSubmit(cli_args=[DEFAULT_CONFIG_FILE], execute=True):
def runSubmit(cli_args=None, execute=True):
parser = argparse.ArgumentParser(
description='Run COMPAS using a config yaml (for settings refer to ./COMPAS --help)'
)
parser.add_argument('config_file', type=str, default=DEFAULT_CONFIG_FILE)
parser.add_argument('config_file', type=str, nargs="?", default=DEFAULT_CONFIG_FILE)
parser.add_argument('--grid', type=str, default=None)
args = parser.parse_args(cli_args)
# -- Get the program options
myoptions = pythonProgramOptions(config_file=args.config_file)
myoptions = pythonProgramOptions(config_file=args.config_file, grid_filename=args.grid)
print(myoptions.shellCommand)
if execute: # Execute COMPAS shell string
call(myoptions.shellCommand, shell=True)
Expand Down
7 changes: 4 additions & 3 deletions py_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

HERE = os.path.dirname(__file__)
TEST_CONFIG_DIR = os.path.join(HERE, "test_data")
TEST_CONFIG_FNAME = os.path.join(TEST_CONFIG_DIR, "fiducial_bbh_config.yaml")
TEST_GRID = os.path.join(TEST_CONFIG_DIR, "grid.txt")
TEST_ARCHIVE_DIR = os.path.join(HERE, "test_artifacts")

REPO_ROOT = os.getenv("COMPAS_ROOT_DIR", os.path.abspath(os.path.join(HERE, "..")))
COMPAS_EXE = os.path.join(REPO_ROOT, "src", "COMPAS")

@pytest.fixture()
def example_compas_output_path(clean=False):
Expand All @@ -26,7 +27,7 @@ def example_compas_output_path(clean=False):
if not os.path.exists(compas_data_path) or clean: # Check if path exists
curr_dir = os.getcwd()
os.chdir(TEST_CONFIG_DIR)
cmd = f"compas_run_submit {TEST_CONFIG_FNAME}"
cmd = f"{COMPAS_EXE} --detailed-output --grid {TEST_GRID}"
# run the command in shell "compas_run_submit {TEST_CONFIG_FNAME}" with subprocess
subprocess.run(cmd, shell=True, check=True)

Expand Down

0 comments on commit e1896d2

Please sign in to comment.