Skip to content

Commit

Permalink
Merge pull request #279 from NOAA-GFDL/fix_ambiguous_click_command_calls
Browse files Browse the repository at this point in the history
rename fre/pp/*.py files to not clash with click cli command names.
  • Loading branch information
ceblanton authored Nov 27, 2024
2 parents eaa05ed + 4409b58 commit 2a49f1d
Show file tree
Hide file tree
Showing 28 changed files with 525 additions and 463 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create_test_conda_env.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: create_test_conda_env

on: [push, pull_request]
on: [pull_request]

jobs:
build-linux:
Expand Down
10 changes: 0 additions & 10 deletions fre/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
# turn xxxx.y into xxxx.0y
import importlib.metadata
version_unexpanded = importlib.metadata.version('fre-cli')
version_unexpanded_split = version_unexpanded.split('.')
if len(version_unexpanded_split[1]) == 1:
version_minor = "0" + version_unexpanded_split[1]
else:
version_minor = version_unexpanded_split[1]
version = version_unexpanded_split[0] + '.' + version_minor
__version__ = version
1 change: 1 addition & 0 deletions fre/app/freapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def app_cli():
def regrid(context,
input_dir, output_dir, begin, tmp_dir,
remap_dir, source, grid_spec, def_xy_interp ):
# pylint: disable=unused-argument
''' regrid target netcdf file '''
context.forward(_regrid_xy)

Expand Down
19 changes: 17 additions & 2 deletions fre/fre.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
be called via this script. I.e. 'fre' is the entry point
"""

#versioning... always fun...
# turn xxxx.y into xxxx.0y
import importlib.metadata
version_unexpanded = importlib.metadata.version('fre-cli')
version_unexpanded_split = version_unexpanded.split('.')
if len(version_unexpanded_split[1]) == 1:
version_minor = "0" + version_unexpanded_split[1]
else:
version_minor = version_unexpanded_split[1]
version = version_unexpanded_split[0] + '.' + version_minor





import click
from .lazy_group import LazyGroup

Expand All @@ -29,12 +44,12 @@


@click.version_option(
package_name = "fre-cli"
package_name = "fre-cli",
version=version
)

def fre():
''' entry point function to subgroup functions '''


if __name__ == '__main__':
fre()
116 changes: 0 additions & 116 deletions fre/make/createCheckout.py

This file was deleted.

119 changes: 119 additions & 0 deletions fre/make/create_checkout_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
'''
checks out a makefile for a given model from the yamls
i think!
'''

import os
import subprocess
import logging
import sys
import click
import fre.yamltools.combine_yamls as cy
from .gfdlfremake import varsfre, yamlfre, checkout, targetfre

def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
# Define variables
yml = yamlfile
name = yamlfile.split(".")[0]
run = execute
jobs = str(jobs)
pcheck = no_parallel_checkout

if pcheck:
pc = ""
else:
pc = " &"

if verbose:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.ERROR)

src_dir="src"
checkout_script_name = "checkout.sh"
baremetal_run = False # This is needed if there are no bare metal runs

## Split and store the platforms and targets in a list
plist = platform
tlist = target

# Combine model, compile, and platform yamls
# Default behavior - combine yamls / rewrite combined yaml
comb = cy.init_compile_yaml(yml,platform,target)
full_combined = cy.get_combined_compileyaml(comb)

## Get the variables in the model yaml
fre_vars = varsfre.frevars(full_combined)

## Open the yaml file, validate the yaml, and parse as fremake_yaml
model_yaml = yamlfre.freyaml(full_combined,fre_vars)
fremake_yaml = model_yaml.getCompileYaml()

## Error checking the targets
for target_name in tlist:
target = targetfre.fretarget(target_name)

## Loop through the platforms specified on the command line
## If the platform is a baremetal platform, write the checkout script and run it once
## This should be done separately and serially because bare metal platforms should all be using
## the same source code.
for platform_name in plist:
if model_yaml.platforms.hasPlatform(platform_name):
pass
else:
raise ValueError (platform_name + " does not exist in platforms.yaml")
( compiler, modules, modules_init, fc, cc, model_root,
iscontainer, mk_template, container_build, container_run,
RUNenv ) = model_yaml.platforms.getPlatformFromName(platform_name)

# ceate the source directory for the platform
if not iscontainer:
src_dir = model_root + "/" + fremake_yaml["experiment"] + "/src"
# if the source directory does not exist, it is created
if not os.path.exists(src_dir):
os.system("mkdir -p " + src_dir)
# if the checkout script does not exist, it is created
if not os.path.exists(src_dir+"/checkout.sh"):
fre_checkout = checkout.checkout("checkout.sh",src_dir)
fre_checkout.writeCheckout(model_yaml.compile.getCompileYaml(),jobs,pc)
fre_checkout.finish(pc)
# Make checkout script executable
os.chmod(src_dir+"/checkout.sh", 0o744)
print("\nCheckout script created in "+ src_dir + "/checkout.sh \n")

# Run the checkout script
if run:
fre_checkout.run()
else:
sys.exit()
else:
print("\nCheckout script PREVIOUSLY created in "+ src_dir + "/checkout.sh \n")
if run:
try:
subprocess.run(args=[src_dir+"/checkout.sh"], check=True)
except:
print("\nThere was an error with the checkout script "+src_dir+"/checkout.sh.",
"\nTry removing test folder: " + model_root +"\n")
raise
else:
sys.exit()

else:
image="ecpe4s/noaa-intel-prototype:2023.09.25"
bld_dir = model_root + "/" + fremake_yaml["experiment"] + "/exec"
tmp_dir = "tmp/"+platform_name
fre_checkout = checkout.checkoutForContainer("checkout.sh", src_dir, tmp_dir)
fre_checkout.writeCheckout(model_yaml.compile.getCompileYaml(),jobs,pc)
fre_checkout.finish(pc)
print("\nCheckout script created at " + tmp_dir + "/checkout.sh" + "\n")

@click.command()
def _checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
'''
Decorator for calling checkout_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose)

if __name__ == "__main__":
checkout_create()
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2a49f1d

Please sign in to comment.