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

Get name for parent path to create schema_filename #2886

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

alexhermida
Copy link
Contributor

@alexhermida alexhermida commented Mar 19, 2024

Hi 👋🏽 I've came to fix an issue but didn't realise about the dev branch until PR time, I've missed that detail in CONTRIBUTORS file, so the issue was already fixed with the str cast doing the trick.

I kept the PR as I think using as_posix is generally more correct for Paths, but maybe I'm missing something for this use case. First time around here.

Also adding a test since it wasn't tested the particular error.

Feel free to drop the PR in case is not necessary.

Thanks.

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

@awgymer
Copy link
Contributor

awgymer commented Mar 20, 2024

I was not sure this should really matter too much but now I am having another realisation. This code probably isn't doing what anyone thinks it is doing. And it probably never has.

In the most common case, where you run nf-core schema build then dir defaults to . which means that schema_filename defaults to ./nextflow_schema.json. Which means Path(self.schema_filename).parent resolves to . (which is also true for the previous os.path.dirname implementation. This means that the pipeline name would be set to ..

My suspicion is that the actual intention of this code is to set the pipeline name to be the same as the name of the parent directory e.g. /path/to/my_pipeline/main.nf would result in the pipeline name being set to my_pipeline.

Even if this code operated on the absolute path right now (or previously) it would actually be set to /path/to/my_pipeline

@mashehu you implemented the original code I think, so do you have a take on what the intended outcome was?

@alexhermida
Copy link
Contributor Author

alexhermida commented Mar 20, 2024

I was not sure this should really matter too much but now I am having another realisation. This code probably isn't doing what anyone thinks it is doing. And it probably never has.

In the most common case, where you run nf-core schema build then dir defaults to . which means that schema_filename defaults to ./nextflow_schema.json. Which means Path(self.schema_filename).parent resolves to . (which is also true for the previous os.path.dirname implementation. This means that the pipeline name would be set to ..

My suspicion is that the actual intention of this code is to set the pipeline name to be the same as the name of the parent directory e.g. /path/to/my_pipeline/main.nf would result in the pipeline name being set to my_pipeline.

Even if this code operated on the absolute path right now (or previously) it would actually be set to /path/to/my_pipeline

@mashehu you implemented the original code I think, so do you have a take on what the intended outcome was?

Thanks for the comment @awgymer

When I came to address the issue my though was to control and raise an AssertionError as it's in other areas of the code for the schema validation.
Like you I don't know of the background to set this to the parent path but the reasoning you commented it makes sense to me. Personally, I'd prefer to validate and force to explicitly set a pipeline name but maybe that's not consistent what it's done in other parts of the codebase.
If the latter is the case I think something like

Path(self.schema_filename).parent.name).strip("'")

would do the trick.

Let see what @mashehu says. Thank you!

@mashehu
Copy link
Contributor

mashehu commented Mar 20, 2024

oooh, good catch. yes, we should probably always convert to a full path

@alexhermida alexhermida force-pushed the error-control-schema-build branch 2 times, most recently from 8d463f8 to fa461a7 Compare March 20, 2024 13:49
tests/test_schema.py Outdated Show resolved Hide resolved
@alexhermida
Copy link
Contributor Author

I've updated the tests for covering the issue.

The wc is currently hardcoded as it is being created during initialisation. I can see that string is hardcoded in a few places, maybe is worth to refactor in a following PR

self.template_dir = os.path.join(self.tmp_dir, "wf")

@awgymer
Copy link
Contributor

awgymer commented Mar 20, 2024

I think the hardcoding in this case is probably fine. We are hardcoding the input path and the expected value based on that?

Only downside I really see there is that people might wonder how we know what the expected is if they don't realise we hardcode the input path but... 🤷

@awgymer
Copy link
Contributor

awgymer commented Mar 20, 2024

@nf-core-bot fix linting

@alexhermida
Copy link
Contributor Author

I think the hardcoding in this case is probably fine. We are hardcoding the input path and the expected value based on that?

Yes, based on that initialisation. I think it's fine for now, don't think it's worth to refactor it now, it might bring new issues 😄

@alexhermida alexhermida changed the title Get path as posix for parent schema_filename to properly Get name for parent path to create schema_filename Mar 20, 2024
@alexhermida
Copy link
Contributor Author

I think those two test failing are related to the dev merge as they're currently failing in the last dev branch commit 😓

@mashehu
Copy link
Contributor

mashehu commented Mar 22, 2024

yes, sorry, two tests are currently borked. you have my permission to ignore them for now and merge 😉

@alexhermida
Copy link
Contributor Author

yes, sorry, two tests are currently borked. you have my permission to ignore them for now and merge 😉

Thanks @mashehu ! since I've merged latest dev branch commit as it looked fixed I think it needs reapproval for merging 😄

@alexhermida
Copy link
Contributor Author

branch rebased to dev for triggering tests @mashehu thanks!

@alexhermida
Copy link
Contributor Author

@mashehu I don't have permissions to merge 😄

@mashehu mashehu merged commit 8cf46f6 into nf-core:dev Apr 4, 2024
35 checks passed
@alexhermida alexhermida deleted the error-control-schema-build branch April 4, 2024 09:52
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.

4 participants