-
Notifications
You must be signed in to change notification settings - Fork 192
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
Make module/subworkflow names case insensitive #2869
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files☔ View full report in Codecov by Sentry. |
nf_core/__main__.py
Outdated
@@ -818,7 +818,7 @@ def modules_install(ctx, tool, dir, prompt, force, sha): | |||
ctx.obj["modules_repo_branch"], | |||
ctx.obj["modules_repo_no_pull"], | |||
) | |||
exit_status = module_install.install(tool) | |||
exit_status = module_install.install(tool.lower()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd never heard of this one! Good to know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though in this case, I don't think it matters - module names must already be simple alphanumeric, I don't think that you could get this far with ß or anything 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is new to me as well, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than adding .lower()
every time that tool
is referenced, I think that it'd be simpler to just do the following right at the start of def modules_install
?
tool = tool.lower()
Then it only needs to be called once.
I've incorporated both of your suggestions! Added a small comment to each call to make it more explicit what is happening too. I also renamed one of the subworkflow function arguments from To deal with the
or just add |
My guidelines:
|
The modules/subworkflow commands tend to allow the user to supply a module/subworkflow name OR provide nothing and get prompted with a dialogue. So it's entirely expected that In this case I wonder if it is better to actually use a callback in the parameter declaration to avoid faffing with the case when a user supplies no option? e.g.
NB: That code is a prototype YMMV |
Turns out that So I actually think perhaps a custom
|
I'm currently also mapping out the different functions that can ever receive a module/subworkflow name. Seems like it's possible to do the conversion there, after any other verifications and after the user selection prompt code for when no name is supplied. If that doesn't work out, the click approach looks promising! Will report back later! |
Oh nice, might just be a case of checking all the |
Actually, on first glance your initial suggestion seems to work just fine @awgymer:
If a component is provided by the user, it is converted to lowercase. If not, the value remains None and all downstream user choice prompts should still fire as expected. Slight caveat here 1. I'll try converting things to this format tomorrow and report back. Footnotes
|
Yes, your callback works here as you are catching the |
846196a
to
7ff4f55
Compare
There we go. This seems like a far better solution. See details in the commit message: 78b2a77 (I rebased locally to clean things up). Thanks for the input everyone, I've added you all as co-authors, but you might need to verify them. Some remaining questions:
|
You should be able to run Ruff locally, see the problem and fix it. I'll take a look now... |
I am running ruff via the VSCode extension, that's why I was so confused :o |
Seems like the branch was out of sync with |
I thought I had run a |
GitHub usually gives you a button at the bottom of the MR to update the branch to be in sync (assuming it won't create conflicts) 😄 |
Updated the changelog (squashed into previous commit); ruff and rebase are no longer acting up this time around either :) |
Uses a click callback function to normalize the name of a module/subworkflow that is provided by the user on the CLI, so that names written in uppercase still resolve to the expected lowercase name. In case no argument is provided, the callback function simply returns None, and thus the current behaviour of a user being asked to select a component via an interactive prompt is maintained. The .casefold() method is used in favour of .lower() for slightly more robust case normalization. See: https://stackoverflow.com/questions/45745661/lower-vs-casefold-in-string-matching-and-converting-to-lowercase The callback is applied to all occurrences of "tool/module/subworkflow" arguments, except those in the the "create" functions, because these already contain an internal check that prompts to user to adhere to the lowercase naming convention. Updates to CHANGELOG.md. Co-authored-by: Adam Talbot <adam.talbot@seqera.io> Co-authored-by: Phil Ewels <phil.ewels@seqera.io> Co-authored-by: Arthur Gymer <24782660+awgymer@users.noreply.github.com>
The subworkflow info command referred to the subworkflow name as "tool" in its list of arguments. It has been renamed to "subworkflow" to align with the other subworkflow commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
PR checklist
CHANGELOG.md
is updateddocs
is updatedQuick attempt at a fix for #2759.
EDIT: New approach is summarized in the main commit message body. Original PR history preserved below:
I went for the naive approach and simply converted all occurrences of tool/subworkflow names to lowercase, whenever they were being used as an input to a function.
A cleaner solution might be to use a decorator for this, but I couldn't find an option for click (token normalization only appears to work on choices or options, not arguments).
Alternatively, a check could be implemented inside the various functions of the ComponentCommand class, but I must admit I felt a bit lost trying to understand the overall structure of how these are currently implementend. I couldn't identify a uniform approach to verify input options used by the various components:
ComponentInstall
class contains acollect_and_verify_name()
function where the input can be standardized.ComponentUpdate
uses a different approach thanComponentPatch
, which itself has aremove
function that differs fromModuleRemove
.synced_repo
, which does not reuse theComponentInstall
class?If my current fix is "good enough", I will update the changelog and look at tests, but if another approach is preferred, I'll need some help from someone who's more familiar with the code base.