Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout edits #249

Merged
merged 59 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e063d85
checkout updated for issue #174
Oct 2, 2024
6e701aa
Update checkoutScript.py
kiihne-noaa Oct 9, 2024
b9c9d01
Update checkoutScript.py
kiihne-noaa Oct 10, 2024
582592f
added exit if local branch is not branch request
kiihne-noaa Oct 25, 2024
a2f536f
fixed bracket
kiihne-noaa Oct 28, 2024
6919bd0
Merge branch 'main' into checkout_edits
Oct 31, 2024
3a7f378
tags version
Oct 31, 2024
0ac0322
Update __init__.py with version
kiihne-noaa Oct 31, 2024
8a67e19
added version checker #174
kiihne-noaa Oct 31, 2024
438492c
Merge branch 'precompute-workflow.247' of github.com:NOAA-GFDL/fre-cl…
Nov 4, 2024
64d5cc8
git fixes
Nov 6, 2024
f1756d8
wrapper logic reworked #174
Nov 8, 2024
f161cd7
Update checkoutScript.py
kiihne-noaa Nov 8, 2024
1c0a531
varous small improvemnets to address comments
kiihne-noaa Nov 8, 2024
f91514c
Update checkoutScript.py
kiihne-noaa Nov 8, 2024
fe1078d
reviewing checkoutScript.py
kiihne-noaa Nov 13, 2024
a6d6a82
syntax change
kiihne-noaa Nov 13, 2024
a34f559
removed outdated aspects
kiihne-noaa Nov 13, 2024
19a7e2a
testing
Nov 13, 2024
8f8d17f
spelling change
kiihne-noaa Nov 13, 2024
e658eb7
Update checkoutScript.py
kiihne-noaa Nov 13, 2024
96f79ef
Update checkoutScript.py
kiihne-noaa Nov 14, 2024
744c3a5
documentation and version changes
kiihne-noaa Nov 14, 2024
0de08a8
order change
kiihne-noaa Nov 14, 2024
108a123
sanity check of recursive
kiihne-noaa Nov 14, 2024
fe5fc2c
more print statements
Nov 14, 2024
2d28f49
Update frepp.py so branch does not default to main
kiihne-noaa Nov 15, 2024
3eee452
Update checkoutScript.py documentation
kiihne-noaa Nov 15, 2024
ec650ba
attempt to change default away from main
Nov 15, 2024
211d9a1
Safer method of specifying None as default
Nov 26, 2024
558429f
The evils of changing directory- you must go back at least
Nov 26, 2024
bda67b2
Improve error message clarity (sort of)
Nov 26, 2024
822900b
Print 2024.1 as 2024.01 when called as fre --version
Nov 26, 2024
7492c80
Comment out version specifying in __init__.py for now
Nov 26, 2024
0f07d19
Remove hard-coded 2024.1 to 2024.01 translation
Nov 26, 2024
3770d33
Prepend the yaml directory to the sub-yamls when combining
Nov 26, 2024
35ae479
Removed old unused bash script
Nov 26, 2024
de6c8c7
logic for fre pp install to compare configurations
Nov 26, 2024
6bbf2cd
please help me learn python exceptions
Nov 26, 2024
dde4862
fre pp wrapper to print one round of 'fre pp status' and exit
Nov 26, 2024
c2f17d3
Merge remote-tracking branch 'origin/main' into checkout_edits
Nov 26, 2024
01023ef
Align some click bindings
Nov 26, 2024
bdfa7f5
Added --time option to fre pp wrapper, and standalone fre pp trigger
Nov 26, 2024
c42687b
Somewhat improved error message
Nov 26, 2024
bb6a581
Merge branch 'main' into checkout_edits
ilaflott Nov 26, 2024
f81d60a
make create_test_conda_env.yml run on pull_request
ilaflott Nov 26, 2024
e5cce13
skip fre make test thats curently failing, fix in development.
ilaflott Nov 26, 2024
6ad3f1a
poke at for readability...
ilaflott Nov 26, 2024
e158de2
fix workflow to only run on pull_request, not BOTH a push AND a pull_…
ilaflott Nov 26, 2024
da1c041
import pytest to actually skip the test...
ilaflott Nov 26, 2024
cf02067
add try/except for dir creation.
ilaflott Nov 26, 2024
4a314c6
tweak fre pp checkout test
ilaflott Nov 26, 2024
b2ff4a5
toc_tree depth now 2
ilaflott Nov 26, 2024
16b5e65
snake case changes and reference tweaks elsewhere as needed
ilaflott Nov 26, 2024
5528378
pylint things, clean up of checkout_script functioning, fix fre versi…
ilaflott Nov 26, 2024
57780a4
fix fre versioning reference, remove version input to click version o…
ilaflott Nov 26, 2024
4b43e0c
pylint feedback
ilaflott Nov 26, 2024
cc8f830
switch target/time flags in wrapper calls to be consistent with other…
ilaflott Nov 26, 2024
7fe174e
put the -t/-T convention back to what it was for bronx
ilaflott Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
on: [pull_request]

jobs:
build-linux:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Welcome to ``fre-cli``'s documentation!
.. the entry in the toc must be the .rst filename.
what shows in the webpage is the first header or title
.. toctree::
:maxdepth: 1
:maxdepth: 2
:caption: Contents:

what-is-fre
Expand Down
10 changes: 10 additions & 0 deletions fre/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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
5 changes: 2 additions & 3 deletions fre/fre.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
fg='cyan')
)


@click.version_option(
package_name = "fre-cli",
message = click.style("%(package)s | %(version)s",
fg = (155,255,172) )
package_name = "fre-cli"
)

def fre():
Expand Down
7 changes: 6 additions & 1 deletion fre/make/tests/compilation/test_fre_make_run_fremake.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
''' test "fre make run-fremake" calls '''

import os
from fre.make import runFremake
from pathlib import Path

import pytest

from fre.make import runFremake


# command options
YAMLFILE = "fre/make/tests/null_example/null_model.yaml"
PLATFORM = [ "ci.gnu" ]
Expand All @@ -14,6 +18,7 @@
# get HOME dir to check output
HOME_DIR = os.environ["HOME"]

@pytest.mark.skip(reason='failing: fix in development, see PR 275')
def test_fre_make_run_fremake_null_model_serial_compile():
''' run fre make with run-fremake subcommand and build the null model experiment with gnu'''
runFremake.fremake_run(YAMLFILE, PLATFORM, TARGET, False, 1, False, False)
Expand Down
74 changes: 0 additions & 74 deletions fre/pp/checkoutScript.py

This file was deleted.

98 changes: 98 additions & 0 deletions fre/pp/checkout_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'''
Description: Checkout script which accounts for 4 different scenarios:
1. branch not given, folder does not exist,
2. branch given, folder does not exist,
3. branch not given, folder exists,
4. branch given and folder exists
'''
import os
import sys
import subprocess

import click

import fre

FRE_WORKFLOWS_URL = 'https://github.com/NOAA-GFDL/fre-workflows.git'

def checkout_template(experiment = None, platform = None, target = None, branch = None):
"""
Checkout the workflow template files from the repo
"""
## Chdir back to here before we exit this routine
go_back_here = os.getcwd()

# branch and version parameters
default_tag = fre.__version__
print(f'(checkout_script) default_tag is {default_tag}')


# check args + set the name of the directory
if None in [experiment, platform, target]:
raise ValueError( 'one of these are None: experiment / platform / target = \n'
f'{experiment} / {platform} / {target}' )
name = f"{experiment}__{platform}__{target}"

# Create the directory if it doesn't exist
directory = os.path.expanduser("~/cylc-src")
try:
os.makedirs(directory, exist_ok = True)
except Exception as exc:
raise OSError(
'(checkoutScript) directory {directory} wasnt able to be created. exit!') from exc

print(f'(checkout_script) branch is {branch}')
checkout_exists = os.path.isdir(f'{directory}/{name}')
git_clone_branch_arg = branch if branch is not None else default_tag
if branch is not None:
print('(checkout_script) WARNING using default_tag as branch argument for git clone!')


if not checkout_exists: # scenarios 1+2, checkout doesn't exist, branch specified (or not)
clone_output = subprocess.run( ['git', 'clone','--recursive',
f'--branch={git_clone_branch_arg}',
FRE_WORKFLOWS_URL, f'{directory}/{name}'],
capture_output = True, text = True, check = True)
print(f'(checkout_script) output git clone command: {clone_output}')

else: # the repo checkout does exist, scenarios 3 and 4.
os.chdir(f'{directory}/{name}')

name_path_tag_subproc_out = subprocess.run(["git","describe","--tags"],
capture_output = True,
text = True, check = True).stdout
if branch is not None:
name_path_tag = name_path_tag_subproc_out.split('*')
name_path_branch = subprocess.run(["git","branch"],
capture_output = True,
text = True, check = True).stdout.split()[0]
if all( [ default_tag not in name_path_tag,
name_path_branch != branch ] ):
sys.exit(
f"Tag and branch of prexisting directory {directory}/{name} does not match "
"fre --version or branch requested" )
else:
name_path_tag = name_path_tag_subproc_out.split()[0]
if not default_tag in name_path_tag:
sys.exit(
f"Tag of prexisting directory {directory}/{name} does not match fre --version")

# make sure we are back where we should be
if os.getcwd() != go_back_here:
os.chdir(go_back_here)

return 0

#############################################

@click.command()
def _checkout_template(experiment, platform, target, branch = None):
'''
Wrapper script for calling checkout_template - allows the decorated version
of the function to be separate from the undecorated version
'''
return checkout_template(experiment, platform, target, branch)


if __name__ == '__main__':
checkout_template()
1 change: 0 additions & 1 deletion fre/pp/configure_script_xml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
'''
Primary Usage: fre-bronx-to-canopy -x XML -e EXP -p PLATFORM -t TARGET

Expand Down
1 change: 0 additions & 1 deletion fre/pp/configure_script_yaml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
"""
Script creates rose-apps and rose-suite
files for the workflow from the pp yaml.
Expand Down
74 changes: 46 additions & 28 deletions fre/pp/frepp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
''' fre pp '''

import click
from .checkoutScript import _checkoutTemplate
from .configure_script_yaml import _yamlInfo
from .configure_script_xml import convert
from .validate import _validate_subtool
from .install import install_subtool
from .run import pp_run_subtool
from .status import status_subtool
from .wrapper import runFre2pp

from fre.pp import checkout_script
from fre.pp import configure_script_yaml
from fre.pp import configure_script_xml
#from fre.pp import validate
from fre.pp import install
from fre.pp import run
from fre.pp import trigger
from fre.pp import status
from fre.pp import wrapper

@click.group(help=click.style(" - access fre pp subcommands", fg=(57,139,210)))
def pp_cli():
Expand All @@ -30,7 +32,7 @@ def pp_cli():
def status(context, experiment, platform, target):
# pylint: disable=unused-argument
""" - Report status of PP configuration"""
context.forward(status_subtool)
context.forward(status.status_subtool)

# fre pp run
@pp_cli.command()
Expand All @@ -47,7 +49,7 @@ def status(context, experiment, platform, target):
def run(context, experiment, platform, target):
# pylint: disable=unused-argument
""" - Run PP configuration"""
context.forward(pp_run_subtool)
context.forward(run.pp_run_subtool)

# fre pp validate
@pp_cli.command()
Expand Down Expand Up @@ -81,7 +83,7 @@ def validate(context, experiment, platform, target):
def install(context, experiment, platform, target):
# pylint: disable=unused-argument
""" - Install PP configuration"""
context.forward(install_subtool)
context.forward(install.install_subtool)

@pp_cli.command()
@click.option("-y", "--yamlfile", type=str,
Expand All @@ -100,7 +102,7 @@ def install(context, experiment, platform, target):
def configure_yaml(context,yamlfile,experiment,platform,target):
# pylint: disable=unused-argument
""" - Execute fre pp configure """
context.forward(_yamlInfo)
context.forward(configure_script_yaml._yamlInfo)

@pp_cli.command()
@click.option("-e", "--experiment", type=str,
Expand All @@ -113,16 +115,13 @@ def configure_yaml(context,yamlfile,experiment,platform,target):
help="Target name",
required=True)
@click.option("-b", "--branch",
show_default=True,
default="main", type=str,
help="Name of fre2/workflows/postproc branch to clone; " \
"defaults to 'main'. Not intended for production use, " \
"but needed for branch testing." )
required=False,
help="fre-workflows branch/tag to clone; default is $(fre --version)")
@click.pass_context
def checkout(context, experiment, platform, target, branch='main'):
def checkout(context, experiment, platform, target, branch=None):
# pylint: disable=unused-argument
""" - Execute fre pp checkout """
context.forward(_checkoutTemplate)
context.forward(checkout_script._checkout_template)

@pp_cli.command()
@click.option('-x', '--xml',
Expand Down Expand Up @@ -180,7 +179,7 @@ def configure_xml(context, xml, platform, target, experiment, do_analysis, histo
ppdir, do_refinediag, pp_start, pp_stop, validate, verbose, quiet, dual):
# pylint: disable=unused-argument
""" - Converts a Bronx XML to a Canopy rose-suite.conf """
context.forward(convert)
context.forward(configure_script_xml.convert)

#fre pp wrapper
@pp_cli.command()
Expand All @@ -190,23 +189,42 @@ def configure_xml(context, xml, platform, target, experiment, do_analysis, histo
@click.option("-p", "--platform", type=str,
help="Platform name",
required=True)
@click.option("-t", "--target", type=str,
@click.option("-T", "--target", type=str,
help="Target name",
required=True)
@click.option("-c", "--config-file", type=str,
help="Path to a configuration file in either XML or YAML",
required=True)
@click.option("-t", "--time",
required=False,
help="Time whose history files are ready")
@click.option("-b", "--branch",
show_default=True,
default="main", type=str,
help="Name of fre2/workflows/postproc branch to clone; " \
"defaults to 'main'. Not intended for production use, " \
"but needed for branch testing." )
required=False,
help="fre-workflows branch/tag to clone; default is $(fre --version)")
@click.pass_context
def wrapper(context, experiment, platform, target, config_file, branch='main'):
def wrapper(context, experiment, platform, target, config_file, time=None, branch=None):
# pylint: disable=unused-argument
""" - Execute fre pp steps in order """
context.forward(runFre2pp)
context.forward(wrapper.runFre2pp)

@pp_cli.command()
@click.option("-e", "--experiment", type=str,
help="Experiment name",
required=True)
@click.option("-p", "--platform", type=str,
help="Platform name",
required=True)
@click.option("-T", "--target", type=str,
help="Target name",
required=True)
@click.option("-t", "--time",
required=True,
help="Time whose history files are ready")
@click.pass_context
def trigger(context, experiment, platform, target, time):
# pylint: disable=unused-argument
""" - Start postprocessing for a particular time """
context.forward(trigger._trigger)

if __name__ == "__main__":
''' entry point for click to fre pp commands '''
Expand Down
Loading