Skip to content

Commit

Permalink
Reorganize functions following @jhkennedy's suggestions
Browse files Browse the repository at this point in the history
Move env definitions to the top of the script.

Pull out running shell commands into a single function.

Move host-related info higher in the script for easier editing.
  • Loading branch information
xylar committed Jul 16, 2020
1 parent bc74adf commit 4f19832
Showing 1 changed file with 55 additions and 59 deletions.
114 changes: 55 additions & 59 deletions e3sm_supported_machines/create_new_e3sm_unified_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,22 @@
import socket
import glob
import stat
import pwd
import grp
import requests
import progressbar


def check_env(base_path, env_name):
print("Checking the environment {}".format(env_name))
env = os.environ
env['CDAT_ANONYMOUS_LOG'] = 'no'
def get_envs():

activate = 'source {}/etc/profile.d/conda.sh; conda activate {}'.format(
base_path, env_name)

imports = ['vcs', 'ILAMB', 'acme_diags', 'mpas_analysis', 'livvkit',
'IPython', 'globus_cli', 'zstash']
for import_name in imports:
command = '{}; python -c "import {}"'.format(activate, import_name)
try:
subprocess.check_call(command, env=env, executable='/bin/bash',
shell=True)
except subprocess.CalledProcessError as e:
print(' {} failed'.format(import_name))
raise e
print(' {} passes'.format(import_name))

commands = [['e3sm_diags', '--help'],
['mpas_analysis', '-h'],
['livv', '--version'],
['globus', '--help'],
['zstash', '--help'],
['processflow', '-v']]

for command in commands:
exec = command[0]
command = '{}; {}'.format(activate, ' '.join(command))
try:
subprocess.check_call(command, env=env, executable='/bin/bash',
shell=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
print(' {} failed'.format(exec))
raise e
print(' {} passes'.format(exec))

package = 'tempest-remap'
command = '{}; GenerateCSMesh --res 64 --alt --file ' \
'gravitySam.000000.3d.cubedSphere.g'.format(activate)
try:
subprocess.check_call(command, env=env, executable='/bin/bash',
shell=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
print(' {} failed'.format(package))
raise e
print(' {} passes'.format(package))
envs = [{'suffix': '',
'version': '1.3.1',
'python': '3.7',
'mpi': 'nompi'},
{'suffix': '_mpich',
'version': '1.3.1',
'python': '3.7',
'mpi': 'mpich'}]
return envs


def get_host_info():
Expand Down Expand Up @@ -95,25 +57,60 @@ def get_host_info():
activ_path = "/home/xylar/Desktop/test_e3sm_unified"
group = "xylar"
else:
raise ValueError("Unknown host name {}. Add env_path and group for "
"this machine to the script.".format(hostname))
raise ValueError(
"Unknown host name {}. Add env_path and group for "
"this machine to the script.".format(hostname))

return base_path, activ_path, group


def check_env(base_path, env_name):
print("Checking the environment {}".format(env_name))
env = os.environ
env['CDAT_ANONYMOUS_LOG'] = 'no'

activate = 'source {}/etc/profile.d/conda.sh; conda activate {}'.format(
base_path, env_name)

imports = ['vcs', 'ILAMB', 'acme_diags', 'mpas_analysis', 'livvkit',
'IPython', 'globus_cli', 'zstash']
for import_name in imports:
command = '{}; python -c "import {}"'.format(activate, import_name)
test_command(command, env, import_name)

commands = [['e3sm_diags', '--help'],
['mpas_analysis', '-h'],
['livv', '--version'],
['globus', '--help'],
['zstash', '--help'],
['processflow', '-v']]

for command in commands:
command = '{}; {}'.format(activate, ' '.join(command))
test_command(command, env, command[0])

command = '{}; GenerateCSMesh --res 64 --alt --file ' \
'gravitySam.000000.3d.cubedSphere.g'.format(activate)

test_command(command, env, package='tempest-remap')


def test_command(command, env, package):
try:
subprocess.check_call(command, env=env, executable='/bin/bash',
shell=True)
except subprocess.CalledProcessError as e:
print(' {} failed'.format(package))
raise e
print(' {} passes'.format(package))


def main():
# Modify the following list of dictionaries to choose which e3sm-unified
# version, python version, and which mpi variant (nompi, mpich or openmpi)
# to use.

envs = [{'suffix': '',
'version': '1.3.1',
'python': '3.7',
'mpi': 'nompi'},
{'suffix': '_mpich',
'version': '1.3.1',
'python': '3.7',
'mpi': 'mpich'}]
envs = get_envs()

base_path, activ_path, group = get_host_info()

Expand Down Expand Up @@ -229,7 +226,6 @@ def main():
except OSError:
continue


for file_name in files:
progress += 1
bar.update(progress)
Expand Down

0 comments on commit 4f19832

Please sign in to comment.