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

Monochrome logs is option in functions rather than global parameter #101

Merged
merged 13 commits into from
Oct 10, 2023

Conversation

adamrtalbot
Copy link
Collaborator

This changes monochrome logs to being an option in paramsSummaryLog(), paramsSummaryMap() and paramsHelp().

This makes the structure more flexible for pipeline developers who can now use params.monochrome_logs or handle it with their own tooling.

Fixes #99

Rather than reading it from global params.monochrome_logs, monochrome_logs is an argument supplied to the function. This means a pipeline developer can configure it more precisely.
@adamrtalbot
Copy link
Collaborator Author

@nvnieuwk a possible option here would be to default it to params.monochrome_logs, false if params.monochrome_logs does not exist? Equivalent to:

def monochrome =  params.monochrome_logs != null ? false : params.monochrome_logs

This would make it backwards compatible, but also make it complicated for developers (unexpected behaviour).

@nvnieuwk
Copy link
Collaborator

I'm all for backwards compatibility! Thanks for the contribution

Copy link
Collaborator

@nvnieuwk nvnieuwk left a comment

Choose a reason for hiding this comment

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

I like this but my main concern is now that we have two positional arguments to the function. This means you have to specify the schema if you want to specify the monochrome_logs argument too.

You can have a look at the .fromSamplesheet() factory for an example on how to handle this:


(which uses the same method as core nextflow functions with optional arguments)

@adamrtalbot
Copy link
Collaborator Author

I like this but my main concern is now that we have two positional arguments to the function. This means you have to specify the schema if you want to specify the monochrome_logs argument too.

You can have a look at the .fromSamplesheet() factory for an example on how to handle this:

(which uses the same method as core nextflow functions with optional arguments)

Thanks, not sure I understand which bit I'm supposed to be looking at though? Should I add the arguments as the Map options?

@nvnieuwk
Copy link
Collaborator

nvnieuwk commented Oct 2, 2023

Yes and some code that looks if the option is supplied like here:

def String schemaFilename = options?.containsKey('parameters_schema') ? options.parameters_schema as String : 'nextflow_schema.json'
def Boolean skipDuplicateCheck = options?.containsKey('skip_duplicate_check') ? options.skip_duplicate_check as Boolean : params.validationSkipDuplicateCheck ? params.validationSkipDuplicateCheck as Boolean : false

@adamrtalbot
Copy link
Collaborator Author

adamrtalbot commented Oct 2, 2023

I've done it now but I'm not sure it's reading from the optional args correctly, can you check for me?

[edit] hold on, git faff...

@adamrtalbot
Copy link
Collaborator Author

OK I've pushed the changes but it doesn't work because of positional args stuff. Don't really have any more time to look at it I'm afraid.

@adamrtalbot
Copy link
Collaborator Author

Oh! I seem to have fixed it. Need to update docs.

Copy link
Collaborator

@nvnieuwk nvnieuwk left a comment

Choose a reason for hiding this comment

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

Thank you I will look at it in detail when I got some more time, it does look very good at first glance though!

Copy link
Collaborator

@mirpedrol mirpedrol left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!
My only comment is that if this is now a parameter from the plugin, we should refactor to monochromeLogs to follow the Nextflow convention.

edit: could we refactor the argument name in the options map, but allow both parameters params.monochrome_logs and params.monochromeLogs when retrieving the global parameter? The nf-core template is using params.monochrome_logs in other functions, such as creating the logo or formating emails. But other non-nf-core pipelines will use params.monochromeLogs as nextflow params are in camelCase

@adamrtalbot
Copy link
Collaborator Author

I agree. So

LGTM, thank you! My only comment is that if this is now a parameter from the plugin, we should refactor to monochromeLogs to follow the Nextflow convention.

edit: could we refactor the argument name in the options map, but allow both parameters params.monochrome_logs and params.monochromeLogs when retrieving the global parameter? The nf-core template is using params.monochrome_logs in other functions, such as creating the logo or formating emails. But other non-nf-core pipelines will use params.monochromeLogs as nextflow params are in camelCase

Do you want it in this PR or a separate one?

@mirpedrol
Copy link
Collaborator

Do you want it in this PR or a separate one?

Can be added to this PR :) Should be a small enough change

@adamrtalbot
Copy link
Collaborator Author

If someone sets monochrome_logs and monochromeLogs differently, which one should take precedence?

@adamrtalbot
Copy link
Collaborator Author

Current priority:

  1. Function argument
  2. params.monochrome_logs
  3. params.monochromeLogs
def Boolean useMonochromeLogs = options?.containsKey('monochrome_logs') ? options.monochrome_logs as Boolean : 
    params.monochrome_logs ? params.monochrome_logs as Boolean :     
    params.monochromeLogs  ? params.monochromeLogs as Boolean :
    false

@mirpedrol
Copy link
Collaborator

sounds good!

Copy link
Collaborator

@nvnieuwk nvnieuwk left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @adamrtalbot

@adamrtalbot
Copy link
Collaborator Author

I don't have permission to merge but this is good to go from my end 👍

@adamrtalbot
Copy link
Collaborator Author

Oh, unless you want me to extend the tests. I haven't looked too deeply into that yet.

@nvnieuwk
Copy link
Collaborator

nvnieuwk commented Oct 9, 2023

Oh yes more tests won't hurt anybody 💯

@mirpedrol mirpedrol merged commit 24df409 into nextflow-io:master Oct 10, 2023
3 checks passed
@adamrtalbot adamrtalbot deleted the monochrome_logs_is_option branch October 13, 2023 09:22
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.

Move params.monochrome_logs to local scope
3 participants