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

Warn when file() matches a collection of files #5507

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bentsherman
Copy link
Member

Looking at the standard library functions with an eye towards static type checking, the only problematic function is file() which can return a single file or list of files based on the glob pattern.

Rather than introduce some new function, I think we can transition file() to be properly typed:

  1. for now, warn if file() matches a collection of files
  2. in the future, change the return type of file() to Path and raise an error if the glob pattern matches zero or multiple files

Note that the glob pattern is still useful for file() when you know it will match only one file but you don't want to spell it out. Raising an error when this assumption is wrong seems like the right approach to me, but of course we should keep it as a warning just for now.

Not sure whether you want to add a test for the warning, but you can see it in action here:

// assumes there are no *.foo files in the launch directory
println file('*.foo')
println file('*.nf')
println files('*.foo')
println files('*.nf')

@bentsherman bentsherman requested a review from a team as a code owner November 14, 2024 15:46
Copy link

netlify bot commented Nov 14, 2024

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit 091b140
🔍 Latest deploy log https://app.netlify.com/sites/nextflow-docs-staging/deploys/673f3d9fbb44930008092d2c
😎 Deploy Preview https://deploy-preview-5507--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bentsherman bentsherman added this to the 25.04.0 milestone Nov 14, 2024
@christopher-hakkaart
Copy link
Contributor

Is it appropriate to document files() should be used only for a collection of files at the same time?

@bentsherman
Copy link
Member Author

Agreed, better to describe files() on its own terms

@christopher-hakkaart
Copy link
Contributor

I've added a minor suggestion. Otherwise, the docs look good.

Co-authored-by: Christopher Hakkaart <[email protected]>
Signed-off-by: Ben Sherman <[email protected]>
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.

2 participants