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 21 commits into
base: main
Choose a base branch
from
Open

Checkout edits #249

wants to merge 21 commits into from

Conversation

kiihne-noaa
Copy link
Contributor

Describe your changes

Added logic to fre pp Checkout to account for branch changes

Issue ticket number and link (if applicable)

issue 174

@ceblanton
Copy link
Collaborator

ceblanton commented Nov 5, 2024

There are 4 logical pathways that we want for fre pp checkout.

It's cheating a little to do this, but git helpfully conflates branches and tags. So everywhere we use branch or tag, we should try to use "branch/tag" or "branch or tag".

  1. If --branch is not specified, and ~/cylc-src/NAME doesn't exist, then:

Determine the default tag, with fre --version.

Checkout that with git clone -b $tag

  1. If --branch is specified, and ~/cylc-src/NAME doesn't exist, then:

fre pp clone --branch=shield https://github.com/NOAA-GFDL/fre-workflows

Check out the requested branch/tag with git clone -b $user_request

  1. If --branch is not specified, and ~/cylc-src/NAME exists, then:

Determine the default tag, with fre --version

Determine the branch and tag of ~/cylc-src/NAME. If either match, then OK. If none match, then give an error with the mismatch.

You can get the branch of ~/cylc-src/NAME with git branch and the tag with git describe. e.g.

git clone https://github.com/NOAA-GFDL/fre-workflows -b 2024.01 my-workflows
Cloning into 'my-workflows'...
remote: Enumerating objects: 5680, done.
remote: Counting objects: 100% (450/450), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 5680 (delta 391), reused 410 (delta 365), pack-reused 5230 (from 1)
Receiving objects: 100% (5680/5680), 1.26 MiB | 5.88 MiB/s, done.
Resolving deltas: 100% (3136/3136), done.
Note: switching to '3d75b570fc39ad25f20dfbf450ed875ed754968d'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

Updating files: 100% (178/178), done.

(fre-test) c2b:~%>cd my-workflows
(fre-test) c2b:~/my-workflows%>git describe
2024.01
  1. If --branch is specified, and ~/cylc-src/NAME exists, then:

Verify that either the branch (git branch) or tag (git describe)

in ~/cylc-src/NAME matches the user request. If not, give the mismatch error.

@ceblanton
Copy link
Collaborator

I pip-installed your branch to give it a try on the 4 logical pathways, and it failed with a IndexError. Do you see this on your end?

(fre-test) c2b:~%>fre pp checkout -e myexp -p myplat -t mytar   
Traceback (most recent call last):
  File "/nbhome/fms/conda/envs/fre-test/bin/fre", line 10, in <module>
    sys.exit(fre())
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/c2b/.local/lib/python3.9/site-packages/fre/pp/frepp.py", line 125, in checkout
    context.forward(checkoutTemplate)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 804, in forward
    return __self.invoke(__cmd, *args, **kwargs)
  File "/nbhome/fms/conda/envs/fre-test/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/c2b/.local/lib/python3.9/site-packages/fre/pp/checkoutScript.py", line 89, in checkoutTemplate
    return _checkoutTemplate(experiment, platform, target, branch)
  File "/home/c2b/.local/lib/python3.9/site-packages/fre/pp/checkoutScript.py", line 39, in _checkoutTemplate
    local_branch_name = branch_names.stdout.split()[1]
IndexError: list index out of range

@@ -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...

@singhd789 singhd789 requested review from singhd789 and removed request for singhd789 November 5, 2024 18:21
fre/pp/checkoutScript.py Outdated Show resolved Hide resolved
@ilaflott
Copy link
Member

ilaflott commented Nov 8, 2024

you'll wanna peek at the click argument default values as well

if os.path.isdir(name): #scenario 4
os.chdir(name)
name_path_tag=subprocess.run(["git","describe","--tags"],capture_output=True, text=True).stdout
name_path_branch=subprocess.run(["git","branch"],capture_output=True, text=True).stdout.split()[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried about the split()[1] here.. is it safe and will it always be the second member?

git branch gives a lot of output. e.g.

(docs) c2b:~/git/fre-cli%>git branch  
  204-improve-fre-cmor-run-functionality
  CMORPytestUpdates
  catalog-merge
  checkout_edits
* docs
  main
  update-docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I experimented locally, I always saw it give * branch_name as the first entry. But if its different on different places, I can generalize so it splits at *, and then splits the original way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am implementing changes to generalize this. When working locally, I only ever saw * current_branch' as the top item. But for other scenarios, new push should fix that.

sys.exit(stop_report)
return 1
# branch and version parameters
default_tag = subprocess.run(["fre","--version"],capture_output=True, text=True).stdout.split()[2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tag retrieved from fre --version has a one digit month but the fre-workflows (and fre-cli) tags are two-digit month. So this

c2b:~%>fre --version
fre-cli | 2024.1

needs to be expanded to 2024.01 to be used as a tag for fre-workflows.

@@ -20,7 +20,7 @@

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

def _checkoutTemplate(experiment, platform, target):
def _checkoutTemplate(experiment, platform, target, branch='empty'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks fine to me (as a not-quite python person), but it might be more pythonic to set the default to be None. (We can always improve it later)

def _checkoutTemplate(experiment, platform, target, branch=None):

sys.exit(stop_report)
return 1
else: #scenario 1
subprocess.run(f'git checkout tags/{default_tags}')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You want a git clone here instead, just like the one above.

git clone --branch={default_tag} https://github.com/NOAA-GFDL/fre-cli.git

@@ -36,11 +36,12 @@ def _checkoutTemplate(experiment, platform, target, branch='empty'):

# branch and version parameters
default_tag = subprocess.run(["fre","--version"],capture_output=True, text=True).stdout.split()[2]
if branch != 'empty':
if branch == None:
Copy link
Member

Choose a reason for hiding this comment

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

nit: branch is None instead of branch == None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants