-
Notifications
You must be signed in to change notification settings - Fork 191
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
run prettier on test yml file after creation #2078
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #2078 +/- ##
==========================================
+ Coverage 67.98% 68.01% +0.02%
==========================================
Files 43 43
Lines 5597 5605 +8
==========================================
+ Hits 3805 3812 +7
- Misses 1792 1793 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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 is now a disconnect of what is shown in the CLI output and what is written to the yaml-file&prettified
What if we read it from the yaml file and then print that?
It introduces additional steps, but is ultimately necessary to get the desired consistency. It is a question though how to go about that exactly - because it needs a temporary file that can be formatted with pre-commit which requires a git repo, but then again we don't want to pollute a git repo with a file we don't want to keep. So there will need to be a viable temporary file procedure. Can't put much more time into this today - code contributions are more than welcome. |
FWIW by the way, the underlying issue isn't actually an issue anymore. Example output of
|
The goal of this whole exercise would also be to make the custom yaml dumper simpler or remove it entirely. |
I try to go step by step - it's normally faster in the end, safer to do and doesn't produce giant PRs. |
The way I like to think about this adventure is that it will result in a better separation of concerns. The the yaml dumper dumps and the formatter formats. |
I think a belt-and-braces approach of having both working is better to be honest. with tempfile.NamedTemporaryFile(mode='w+') as fh:
yaml.dump(self.tests, fh, Dumper=nf_core.utils.custom_yaml_dumper(), width=10000000)
run_prettier_on_file(fh.name)
prettified_yml = fh.read()
if self.test_yml_output_path == "-":
console = rich.console.Console()
console.print("\n", Syntax(yaml_str, "yaml"), "\n")
else:
try:
log.info(f"Writing to '{self.test_yml_output_path}'")
with open(self.test_yml_output_path, "w") as fh:
fh.write(prettified_yml)
except FileNotFoundError as e:
raise UserWarning(f"Could not create test.yml file: '{e}'") |
@awgymer If you'd like you can push the code snippet to this PR branch yourself. (I think nf-core contributors have the necessary permissions to directly push to my branches.) |
Ok that appears to be passing the tests. Does somebody want to test it in the wild? |
Somehow the |
I'm confused by what you mean? How do you know it's empty if the (I assume final) file is written? |
Both the console output is just an empty line and when I step into it with ipdb, I see that |
@mashehu Good catch! We're missing a |
Co-authored-by: Fabian Egli <fabianegli@users.noreply.github.com>
I think this is good to go now. Who should review/approve as we have all contirbuted code now 😂 |
@ewels ? 😅 |
Nitpick: Can we not just pass stdin to the prettier CLI and avoid messing around with temporary files? |
I did think this at first. But I am fairly certain when I tested it |
pre-commit intentionally hides the CLI of the hooks. It is a central part of the philosophy of having reproducible hooks. This means there is no reasonable way to add CLI flags and hence we have to submit files to the pre-commit hook. |
It is a bit of a detour, but it is one that is easily understood and the complications don't snowball or stretch into other parts of the code - AFAICT. |
Something that just struck me as we are hacking around pre-commit. If we are running And would we solve all this by just running |
The pre-commit hook config in tools is used in different places. The following is a list sorted in ascending distance to the invocation of
The reason for 1. is that Prettier is not pip-installable and we need a robust and convenient way to ensure it is available - pre-commit does that. The reason for 2. is convenience for the developers - faster feedback. Not everyone will actually install the pre-commit hooks in their local git repo, so we can't reasonably expect that files are actually being checked at commit time. (pre-commit installs the script on one system - everyone cloning the repo has to install it again separately in their clone of the repo.) And 3. ensures quality at the community level. With pre-commit we can guarantee consistency on all levels. This is the value proposition of using pre-commit for all of this. |
But doesn't tools - by using pre-commit - actually end up doing number 2 whether they want it or not? There is a call to That was the whole reason we need to now enforce that repos are git repos? And actually I think this may now be broken if any of the commands using prettier are passed a directory other than |
We might want to change that install subcommand to install-hooks instead. To grab the capability upon install, but not force the pre-commit hooks on the devs. Or do we? pre-commit can work without the scripts being installed into the git repo to run the hooks before a commit. In general, yes, this whole pre-commit might still have a bunch of corner cases and the more use cases we can test for the better. So please, if you know a use case you think might break please write it down and/or try it out. And if possible write a test for it. |
That is my desired functionality for this: don't force git hooks on people, but use it as a way to get prettier. But I don't actually see that we run "prettier install" anywhere or am I missing something. Anyway, this PR does work for me now, so I'll give it my 👍🏻 so we can merge it. 🙂 |
…ier-on-test-yml-after-creation
I added the same code for subworkflows. It would be ideal to refactor this command with a components class as we did for the others, but I would leave like this for this PR. |
If that is the case then I think we are fine. I thought I remembered seeing it but maybe it was in an early draft of adding prettier via precommit |
NB: I meant |
Closes #1866
ToDos
PR checklist
CHANGELOG.md
is updateddocs
is updated