Skip to content

Commit

Permalink
Merge pull request #231 from NOAA-GFDL/230.fix-click-decorators
Browse files Browse the repository at this point in the history
 230.Add decorator functions to pass click options correctly
  • Loading branch information
ilaflott authored Oct 31, 2024
2 parents ba3f07c + 7032e24 commit 16612d5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
14 changes: 10 additions & 4 deletions fre/make/createCheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import logging
import sys
import click
from .gfdlfremake import varsfre, yamlfre, checkout, targetfre
import fre.yamltools.combine_yamls as cy
from .gfdlfremake import varsfre, yamlfre, checkout, targetfre

@click.command()
def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
# Define variables
yml = yamlfile
Expand Down Expand Up @@ -65,7 +64,7 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
RUNenv ) = modelYaml.platforms.getPlatformFromName(platformName)

## Create the source directory for the platform
if iscontainer == False:
if iscontainer is False:
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
# if the source directory does not exist, it is created
if not os.path.exists(srcDir):
Expand All @@ -80,7 +79,7 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
print("\nCheckout script created in "+ srcDir + "/checkout.sh \n")

# Run the checkout script
if run == True:
if run is True:
freCheckout.run()
else:
sys.exit()
Expand All @@ -105,6 +104,13 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
freCheckout.finish(pc)
print("\nCheckout script created at " + tmpDir + "/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()
16 changes: 10 additions & 6 deletions fre/make/createCompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .gfdlfremake import varsfre, yamlfre, targetfre, buildBaremetal
import fre.yamltools.combine_yamls as cy

@click.command()
def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
# Define variables
yml = yamlfile
Expand Down Expand Up @@ -60,10 +59,10 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
raise ValueError (platformName + " does not exist in " + modelYaml.combined.get("compile").get("platformYaml"))

(compiler,modules,modulesInit,fc,cc,modelRoot,iscontainer,mkTemplate,containerBuild,ContainerRun,RUNenv)=modelYaml.platforms.getPlatformFromName(platformName)
## Make the bldDir based on the modelRoot, the platform, and the target
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == False:
if iscontainer is False:
baremetalRun = True
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/" + platformName + "-" + target.gettargetName() + "/exec"
os.system("mkdir -p " + bldDir)
Expand All @@ -82,14 +81,19 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
fremakeBuildList.append(fremakeBuild)
click.echo("\nCompile script created at " + bldDir + "/compile.sh" + "\n")
if run:
#print("ITS GONNA RUN")
if baremetalRun:
pool = Pool(processes=nparallel) # Create a multiprocessing Pool
pool.map(buildBaremetal.fremake_parallel,fremakeBuildList) # process data_inputs iterable with pool
# else:
# fremakeBuild.run()
else:
sys.exit()

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

if __name__ == "__main__":
compile_create()
11 changes: 9 additions & 2 deletions fre/make/createDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .gfdlfremake import varsfre, targetfre, yamlfre, buildDocker
import fre.yamltools.combine_yamls as cy

@click.command()
def dockerfile_create(yamlfile,platform,target,execute):
srcDir="src"
checkoutScriptName = "checkout.sh"
Expand Down Expand Up @@ -52,7 +51,7 @@ def dockerfile_create(yamlfile,platform,target,execute):
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == True:
if iscontainer is True:
image="ecpe4s/noaa-intel-prototype:2023.09.25"
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/exec"
tmpDir = "tmp/"+platformName
Expand All @@ -78,5 +77,13 @@ def dockerfile_create(yamlfile,platform,target,execute):
else:
sys.exit()

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

if __name__ == "__main__":
dockerfile_create()
11 changes: 9 additions & 2 deletions fre/make/createMakefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .gfdlfremake import makefilefre, varsfre, targetfre, yamlfre
import fre.yamltools.combine_yamls as cy

@click.command()
def makefile_create(yamlfile,platform,target):
srcDir="src"
checkoutScriptName = "checkout.sh"
Expand Down Expand Up @@ -46,7 +45,7 @@ def makefile_create(yamlfile,platform,target):
## Make the bldDir based on the modelRoot, the platform, and the target
srcDir = modelRoot + "/" + fremakeYaml["experiment"] + "/src"
## Check for type of build
if iscontainer == False:
if iscontainer is False:
baremetalRun = True
bldDir = modelRoot + "/" + fremakeYaml["experiment"] + "/" + platformName + "-" + targetObject.gettargetName() + "/exec"
os.system("mkdir -p " + bldDir)
Expand Down Expand Up @@ -78,5 +77,13 @@ def makefile_create(yamlfile,platform,target):
freMakefile.writeMakefile()
click.echo("\nMakefile created at " + bldDir + "/Makefile" + "\n")

@click.command()
def _makefile_create(yamlfile,platform,target):
'''
Decorator for calling makefile_create - allows the decorated version
of the function to be separate from the undecorated version
'''
return makefile_create(yamlfile,platform,target)

if __name__ == "__main__":
makefile_create()
21 changes: 10 additions & 11 deletions fre/make/fremake.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click
from .createCheckout import checkout_create
from .createCompile import compile_create
from .createDocker import dockerfile_create
from .createMakefile import makefile_create
from .runFremake import fremake_run
from fre.make import createCheckout
from fre.make import createMakefile
from fre.make import createCompile
from fre.make import createDocker
from fre.make import runFremake

yamlfile_opt_help = """Experiment yaml compile FILE
"""
Expand Down Expand Up @@ -73,7 +73,7 @@ def make_cli():
@click.pass_context
def run_fremake(context, yamlfile, platform, target, parallel, jobs, no_parallel_checkout, verbose):
""" - Perform all fremake functions to run checkout and compile model"""
context.forward(fremake_run)
context.forward(runfremake._fremake_run)

####
@make_cli.command()
Expand Down Expand Up @@ -114,7 +114,7 @@ def run_fremake(context, yamlfile, platform, target, parallel, jobs, no_parallel
@click.pass_context
def create_checkout(context,yamlfile,platform,target,no_parallel_checkout,jobs,execute,verbose):
""" - Write the checkout script """
context.forward(checkout_create)
context.forward(createCheckout._checkout_create)

#####
@make_cli.command
Expand All @@ -136,7 +136,7 @@ def create_checkout(context,yamlfile,platform,target,no_parallel_checkout,jobs,e
@click.pass_context
def create_makefile(context,yamlfile,platform,target):
""" - Write the makefile """
context.forward(makefile_create)
context.forward(createMakefile._makefile_create)

#####

Expand Down Expand Up @@ -178,7 +178,7 @@ def create_makefile(context,yamlfile,platform,target):
@click.pass_context
def create_compile(context,yamlfile,platform,target,jobs,parallel,execute,verbose):
""" - Write the compile script """
context.forward(compile_create)
context.forward(createCompile._compile_create)

@make_cli.command
@click.option("-y",
Expand All @@ -202,8 +202,7 @@ def create_compile(context,yamlfile,platform,target,jobs,parallel,execute,verbos
@click.pass_context
def create_dockerfile(context,yamlfile,platform,target,execute):
""" - Write the dockerfile """
context.forward(dockerfile_create)

context.forward(createDocker._dockerfile_create)

if __name__ == "__main__":
make_cli()
12 changes: 8 additions & 4 deletions fre/make/runFremake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import logging
from multiprocessing.dummy import Pool
from pathlib import Path

import click

import fre.yamltools.combine_yamls as cy
from .gfdlfremake import (
targetfre, varsfre, yamlfre, checkout,
makefilefre, buildDocker, buildBaremetal )

@click.command()
def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose):
def _fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose):
''' run fremake via click'''
yml = yamlfile
name = yamlfile.split(".")[0]
Expand Down Expand Up @@ -202,6 +199,13 @@ def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verb
# process data_inputs iterable with pool
pool.map(buildBaremetal.fremake_parallel,fremakeBuildList)

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

if __name__ == "__main__":
fremake_run()

0 comments on commit 16612d5

Please sign in to comment.