Skip to content

Commit

Permalink
Merge branch 'main' of github.com:NOAA-GFDL/fre-cli into 221.force-ch…
Browse files Browse the repository at this point in the history
…eckout-and-compile

-also fix decorator function in `run_fremake.py`
  • Loading branch information
singhd789 committed Oct 31, 2024
2 parents 0cdf4b0 + 16612d5 commit 751d3a2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
15 changes: 11 additions & 4 deletions fre/make/createCheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import sys
import shutil
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,force_checkout):
# Define variables
yml = yamlfile
Expand Down Expand Up @@ -66,7 +65,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 @@ -81,7 +80,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 Down Expand Up @@ -129,5 +128,13 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
else:
print("\nCheckout script PREVIOUSLY created in "+ 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()
13 changes: 10 additions & 3 deletions fre/make/createCompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
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,force_compile):
def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose):
# Define variables
yml = yamlfile
name = yamlfile.split(".")[0]
Expand Down Expand Up @@ -63,7 +62,7 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose,force_
## 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 Down Expand Up @@ -109,5 +108,13 @@ def compile_create(yamlfile,platform,target,jobs,parallel,execute,verbose,force_
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()
20 changes: 10 additions & 10 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"""
experiment_opt_help = """Name of experiment"""
Expand Down Expand Up @@ -86,7 +86,7 @@ def make_cli():
@click.pass_context
def run_fremake(context, yamlfile, platform, target, parallel, jobs, no_parallel_checkout, verbose, force_checkout, force_compile):
""" - 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 @@ -131,7 +131,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,force_checkout):
""" - Write the checkout script """
context.forward(checkout_create)
context.forward(createCheckout._checkout_create)

#####
@make_cli.command
Expand All @@ -153,7 +153,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 @@ -199,7 +199,7 @@ def create_makefile(context,yamlfile,platform,target):
@click.pass_context
def create_compile(context,yamlfile,platform,target,jobs,parallel,execute,verbose,force_compile):
""" - Write the compile script """
context.forward(compile_create)
context.forward(createCompile._compile_create)

@make_cli.command
@click.option("-y",
Expand All @@ -223,7 +223,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,force_checkout,foce_compile):
def fremake_run(yamlfile,platform,target,parallel,jobs,no_parallel_checkout,verbose,force_checkout,force_compile):
''' 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 751d3a2

Please sign in to comment.