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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions fre/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '2024.01'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used? I think it makes sense to store the version here instead of setup.py, but want to avoid duplication.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the idea is to check the fre-cli version below with a pythonic approach, but i'm wondering if this idea is actually dead-on-arrival the more i think about it...

20 changes: 18 additions & 2 deletions fre/pp/checkoutScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
# Description:

import os
import sys
import subprocess
from subprocess import PIPE
from subprocess import STDOUT
import re
import click
from fre import fre
from click.testing import CliRunner


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

package_dir = os.path.dirname(os.path.abspath(__file__))

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

def _checkoutTemplate(experiment, platform, target, branch='main'):
def _checkoutTemplate(experiment, platform, target):
"""
Checkout the workflow template files from the repo
"""
Expand All @@ -30,6 +34,15 @@ def _checkoutTemplate(experiment, platform, target, branch='main'):
# Set the name of the directory
name = f"{experiment}__{platform}__{target}"

# Get name of local branch and check branch rquest
branch_names = subprocess.run(["git","branch"],capture_output=True, text=True)
local_branch_name = branch_names.stdout.split()[1]
if branch != 'main':
if branch != local_branch_name:
stop_report = ("Error in branch: local branch does not match branch input")
sys.exit(stop_report)
return 1

# Clone the repository with depth=1; check for errors
click.echo("cloning experiment into directory " + directory + "/" + name)
clonecmd = (
Expand All @@ -38,6 +51,9 @@ def _checkoutTemplate(experiment, platform, target, branch='main'):
preexist_error = f"fatal: destination path '{name}' exists and is not an empty directory."
click.echo(clonecmd)
cloneproc = subprocess.run(clonecmd, shell=True, check=False, stdout=PIPE, stderr=STDOUT)

if branch == 'main':
subprocess.run('git checkout tags/2024.01')
if not cloneproc.returncode == 0:
if re.search(preexist_error.encode('ASCII'),cloneproc.stdout) is not None:
argstring = f" -e {experiment} -p {platform} -t {target}"
Expand All @@ -51,7 +67,7 @@ def _checkoutTemplate(experiment, platform, target, branch='main'):
f"\t cylc stop {name}\n"
f"\t cylc clean {name}\n"
f"\t rm -r ~/cylc-src/{name}" )
click.echo(stop_report)
sys.exit(stop_report)
return 1
else:
#if not identified, just print the error
Expand Down