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

DM-30373: Add butler collection-chain command line #533

Merged
merged 7 commits into from Jun 12, 2021
Merged

Conversation

timj
Copy link
Member

@timj timj commented Jun 9, 2021

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@timj timj force-pushed the tickets/DM-30373 branch 5 times, most recently from b9c93db to 801088d Compare June 10, 2021 17:03
@timj timj requested a review from TallJimbo June 10, 2021 17:24
Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

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

Looks good. If you're up for a little more work, a --remove X option that just does

children = list(registry.getCollectionChain(parent))
children.remove(X)
registry.setCollectionChain(parent, children)

and a --pop that does

children = registry.getCollectionChain(parent)[1:]
registry.setCollectionChain(parent, children)

would be super useful, too.

@timj
Copy link
Member Author

timj commented Jun 10, 2021

@TallJimbo I've added this but you should take a look before I merge.

Did you mean --pop to remove the first entry in the chain? This goes against the python list.pop() which removes the final entry.

Rather than add a --remove X option I added a --mode option. Doing this allowed X to be the CHILDREN that he subcommand was already having to handle and meant that I could have an extend mode as well as a remove mode.

@repo_argument(required=True)
@click.argument("parent", required=True, nargs=1)
@click.argument("children", required=False, nargs=-1)
@click.option("--pop", is_flag=True, default=False,
Copy link
Member Author

Choose a reason for hiding this comment

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

@TallJimbo Could also do this as --mode=pop and let CHILDREN be given as integer indexes into the chain (so as to match list.pop) -- defaulting to pop off the end.

Copy link
Member

Choose a reason for hiding this comment

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

(see other thread - I think the difference here is that I don't think popping off the end is a good default)

Copy link
Member Author

Choose a reason for hiding this comment

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

In Perl you shift to move things off the front of the list and pop to remove things from the end. I do worry that calling this pop goes against the default python definition of pop. Maybe something like:

$ butler collection-chain REPO --mode=pop PARENT index index index

would work where we default index to -1? (and since this is using CHILDREN allow multiple indices).

Copy link
Member

Choose a reason for hiding this comment

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

How about --mode=pop --side=front, or --mode=popfront?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just implemented the --mode=pop defaulting to element 0 and allowing --mode=pop -1 to remove from the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

The main problem actually is that -1 is an option so you have to do -- -1 to make it work. From what you say that's not going to be a common problem and the positive integer always works as desired.

help="Update mode: "
"'redefine': Create new chain or redefine existing chain with the supplied CHILDREN. "
"'remove': Modify existing chain to remove the supplied CHILDREN. "
"'extend': Modify existing chain to extend it with the supplied CHILDREN.")
Copy link
Member Author

Choose a reason for hiding this comment

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

Would --mode=prepend be useful?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and more useful than extend, I think. We may represent these things as Sequences in Python, but conceptually we (pipetask in particular) really treat them as LIFO stacks, where all of the mutations happen at the front (yeah, maybe I should have implemented them as reversed-lists in Python, but I figured ordering the container according to the search order is more important).

So I really did mean for --pop to act on the front, and I really only care that we provide ways to act on the front in general, but I could easily believe that also providing ways to act on the end is the best way to make it clear what all of the actions actually do.

timj added 7 commits June 11, 2021 22:06
Everything crashes in `butler --help` if one of the local
commands fails to load but it's better to report everything whilst
complaining rather than being impenetrable.
Click will call _get_command multiple times for `butler --help`
and if something is going wrong with the imports this will result
in a cascade of import warnings. Work around that by caching the
imports the first time around and only warning once.
This allows chained collections to be modified.
Pop is now a mode that allows integer indices to specify the
elements to pop.

Add extend option.

Also now prints the current contents of the chain on completion.
@timj timj merged commit 966b234 into master Jun 12, 2021
@timj timj deleted the tickets/DM-30373 branch June 12, 2021 06:03
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.

None yet

2 participants