-
-
Notifications
You must be signed in to change notification settings - Fork 243
feat: add check-update subcommand
#2463
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
base: master
Are you sure you want to change the base?
Conversation
sisp
left a comment
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.
Thanks for contributing this feature to Copier, @natescherer! 🙇
I've left a couple of inline comments.
| check_update_output_as_json = cli.Flag( | ||
| ["--check-update-output-as-json"], | ||
| help="Output a JSON object to stdout containing information about if an update is needed", | ||
| ) |
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.
How about renaming this flag to --output-format with two allowed values plain and json similar to, e.g., Ruff's corresponding flag?
--output-format <OUTPUT_FORMAT>
Output serialization format for violations. The default serialization
format is "full" [env: RUFF_OUTPUT_FORMAT=] [possible values:
concise, full, json, json-lines, junit, grouped, github, gitlab,
pylint, rdjson, azure, sarif]
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.
Works for me, is an updated help message like this acceptable?
Output format, either 'plain' (the default) or 'json'. This flag is only supported by the 'check-update' subcommand.
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.
For the CLI flag, the context is clear, so the second sentence isn't needed. But it makes sense to keep it for the Worker class attribute. One day, I'll try to split this class, so we won't have attributes that are only meaningful for some operations. 🤞
| "update_available": self.template.version | ||
| > self.subproject.template.version, |
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 might be a bit more legible with surrounding parentheses:
| "update_available": self.template.version | |
| > self.subproject.template.version, | |
| "update_available": ( | |
| self.template.version > self.subproject.template.version | |
| ), |
| "Parent template update available. " | ||
| f"\nCurrent version is {self.subproject.template.version}, " |
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 think "template" suffices, parent template sounds like the parent of a template in a hierarchy. Or perhaps even "New template version available"? WDYT?
- I'd move the line break to the first line for better legibility.
| "Parent template update available. " | |
| f"\nCurrent version is {self.subproject.template.version}, " | |
| "New template version available.\n" | |
| f"Current version is {self.subproject.template.version}, " |
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.
Good point, I agree with the terminology change. I have been making a series of hierarchical templates myself and got my wires crossed I think.
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.
Since this is a new test file for an entirely new feature, can we reduce the test cases code to a minimum?
- Avoid Git bundles.
- Avoid custom
_envopssettings. - Minimize test file content (
README.txt.jinja). - Keep commit messages simple, e.g.
git("commit", "-m", "v1").
It might make sense to factor out the test template to a fixture, similar to, e.g., this:
copier/tests/test_answersfile_templating.py
Lines 13 to 30 in d3dd580
| @pytest.fixture(scope="module") | |
| def template_path(tmp_path_factory: pytest.TempPathFactory) -> str: | |
| root = tmp_path_factory.mktemp("template") | |
| build_file_tree( | |
| { | |
| root / "{{ _copier_conf.answers_file }}.jinja": """\ | |
| # Changes here will be overwritten by Copier | |
| {{ _copier_answers|to_nice_yaml }} | |
| """, | |
| root / "copier.yml": """\ | |
| _answers_file: ".copier-answers-{{ module_name }}.yml" | |
| module_name: | |
| type: str | |
| """, | |
| } | |
| ) | |
| return str(root) |
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.
Sure, I can simplify it. I just grabbed an existing test more or less at random, I agree it is a little over complex.
|
@sisp While I'm working on those changes, would appreciate your thoughts on the two questions I raised at the bottom of the PR, thanks. 🙏 |
sisp
left a comment
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.
Regarding the exit code: I think exiting with 0 when there's no update (i.e., the project is up-to-date) and with non-zero otherwise seems reasonable. At least Cruft follows a similar approach. The specific non-zero exit code is another question. Cruft exits with 1 when there is an update, but 1 is already used for, e.g., precondition errors like a missing old template reference. Exit code 2 is used for indicating unsafe templates without explicit user trust, but this error can only occur for copy and update operations but never when checking for an update. I think it's fine to use the same exit code for different errors by different subcommands.
[...] but if I was designing this from scratch, I wouldn't consider an update being available an error in the classic sense
What exactly do you mean by "in the classic sense"?
Regarding documentation: How about adding a section on our "Updating a project" page, similar to Cruft's corresponding section?
| check_update_output_as_json = cli.Flag( | ||
| ["--check-update-output-as-json"], | ||
| help="Output a JSON object to stdout containing information about if an update is needed", | ||
| ) |
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.
For the CLI flag, the context is clear, so the second sentence isn't needed. But it makes sense to keep it for the Worker class attribute. One day, I'll try to split this class, so we won't have attributes that are only meaningful for some operations. 🤞
|
Sounds good re: the documentation. As far as what I mean by "in the classic sense" this is probably my SRE brain talking, but I tend to see any application ending with a non-zero status code as indicating that there is some failure in execution, but there's no failure/error/issue when the sub command checks and sees there is an update; the update checking process worked just fine. Hopefully that makes sense? |
Hello! This is my attempt to complete the work that was done in #1031. (Should close #1020, as well.)
What's Changed
Here's what I've changed versus the previous PR, by type:
Outstanding changes requested in discussions on old PR
check-update52was discussed in the previous PR but I changed it based on Ambiguous exit code 2 #1328Necessary Updates
Other Changes
--check-update-output-as-jsonflag for integrating with CI/scripts/etcQuestions/To-Do
I have a few questions for the maintainers:
--check-update-output-as-jsonprovides a hook for scripts to detect if there is an update, from the discussions I saw before that seemed to be the overall intention of the exit codedocs/checking_for_updates.md?Thanks for making such an awesome tool! Please let me know if there are changes you'd like me to make.