vimPlugins: Automate git commits when updating.#83788
Conversation
|
The roadmap I envision going forward is to break out the |
timokau
left a comment
There was a problem hiding this comment.
Went through the commits in order and added my thoughts inline. Probably went a bit overboard with the nitpicky-ness, you don't need to agree everywhere of course.
Thanks for continuing to work on this! I'm worrying about the increasing complexity of this "little helper" a bit, but I do think the changes are worth it.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
We can get rid of NIXPKGS_PATH by using git.Repo(".", search_parent_directories=True).
There was a problem hiding this comment.
I would think if we used ROOT rather than . we could avoid the assumption that the current working directory is vim-plugins.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
This may be confusing to a git novice. How about "You have uncommitted changes. Please commit your changes or stash them before running this tool."
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
Is this type annotation necessary? Or is it common practice? I don't have much experience with mypy.
There was a problem hiding this comment.
No idea, but I didn't intentionally make this change so I'll revert it. This is my first experience with mypy and I must say it's been great and saved a lot of time.
There was a problem hiding this comment.
Similar to the discussion in #83119, I think we should just do this by default. We could keep a --no-commit flag, but I don't think its necessary.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
I think files should be an explicit list instead.
There was a problem hiding this comment.
I knew you would and changed it in a subsequent commit.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
It would be nice to mention that this has to be hosted on github.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
As a minor pet-peeve of mine, I wish we had a standard on capitalization after :. Lower-case seems more prevalent, so I would prefer that. Again, I don't feel very strongly about this though.
There was a problem hiding this comment.
Yeah, I was going with the precedent in vim.section.md but now that we're in a position to correct this I'll do so because I think nixpkg's CONTRIBUTING.md should be the global standard.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
Something more explicit might be nice here, such as resolve github repository redirects.
pkgs/misc/vim-plugins/update.py
Outdated
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
I'd prefer to give this function a name, such as updater.update(), to be more explicit (PluginUpdater doesn't seem "callable" to me).
That would be nice. I think it would be even better to save every plugin in a separate file. That way we wouldn't have to worry about merge conflicts any more (though your proposal would already help with that). One downside is that we currently get semi-regular updates "for free" whenever someone adds a plugin. But that could be done better with appropriate automation. |
I'd like to say that the review has been of very high quality which might get lost in my defensive responses to many of the review comments. :) |
49aeeb2 to
06615ab
Compare
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
I believe it had something to do with mypy but it doesn't seem necessary any more. I'll try reverting it.
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
Should this one not be catched by mypy?
| user: str, repo_name: str, alias: str, cache: "Cache" = None | |
| user: str, repo_name: str, alias: str, cache: "Optional[Cache]" = None |
There was a problem hiding this comment.
For some reason mypy doesn't seem to care whether this is done for optional arguments but I'll go and make this change.
06615ab to
9bcb49c
Compare
|
Everything else looks good to me, but this needs a rebase because of #83798 and there's the outstanding issue with the dirty/master check. |
|
I agree with you to a certain extent about the dirty/master checks and at the very least the flag should be renamed. I'm concerned that this auto-committing behavior is going to be a footgun for people who just want to add a damn package. For example I would probably run this script on whatever branch I have checked out at the time, stash the changes, and checkout a new branch to make a PR. The git experts are going to figure out what happened (eventually) and be able to I think we should be particularly conscious of this kind of user in our interface choices, not only because we'll be fielding their questions and PR's, but because vim configuration in nixos is already uniquely complicated compared to any other operating system. Would it be too much to ask those of us with advanced use cases to pass a |
53d85a8 to
b3f7df2
Compare
pkgs/misc/vim-plugins/update.py
Outdated
There was a problem hiding this comment.
black probably dis something funny here.
That's a good point I hadn't thought about. The current solution is not only inconvenient though, its also not very reliable. For example, I never use a local tracking branch for master. I just use the remote So I would still rather remove those checks. Maybe print a warning that commits were created on the current branch. If there was a mistake, there's no complicated rebasing necessary. The contributor can just repeat the changes on the appropriate branch. If you think this is necessary, you could also ask for confirmation interactively (with a flag to disable this). And the other part of the issue, the dirty tree, is not really affected by this. Is there any downside to only checking the relevant files for "dirt"?
Keep in mind that this complexity is opt-in though. Users can still use and configure vim as they do on any other distro, including plugin management. We should still try to make the experience as frictionless as possible of course. |
|
The particular scenario you describe could be worked around: try:
if not allow_dirty and (
repo.head.ref == repo.heads.master
or repo.head.commit != repo.heads.master.commit
):
raise Exception(
"Please create a new branch based off master before running this tool."
)
except AttributeError:
raise Exception(
"For advanced use cases, please pass the --allow-dirty flag."
)
They would also need to reset
My thinking is that a dirty tree is indicative of being unprepared to commit. If you checked out a fresh branch, why would the tree be dirty? My thinking here is that "indicative" is good enough. IMO, if these checks are helpful (or benign) for the vast majority of use cases, making the minority pass a flag to bypass them is acceptable. Any kind of safety device is a trade off that is somewhat annoying to "power users". |
I agree. If I did have unstaged changes, it was likely something else i was working on and not related to running the plugin update script |
How does this work around it? Or do you mean that the workaround is telling the user to use
True. Or they could use the XKCD approach: https://xkcd.com/1597/
Uncommitted changes are preserved when checking out a fresh branch. I might have some unstaged package update that I haven't gotten around to committing yet. I don't see much value in this check. Its not a very reliable indicator of "not being on the correct branch" and I do see it as being annoying often enough. Though it seems I'm outvoted on this one, and I don't feel that strongly about it as long as there's a short
There's a tradeoff here though. I think the indicator is unreliable, the benefit is small and we can expect some git competence from committers here. Resetting a branch is very basic. They'll have to find a way to do it eventually anyway. At the same time I'm pretty sure I would've unnecessarily tripped up these safety checks several times already. The other advantage is that it makes the |
If it's common then it could be more explicitly supported by the check.
Yeah, that's best avoided with 200,000+ commit projects.
Interesting. I never intentionally do this this myself but perhaps git just supports too many workflows for checks like these to have high indicative value. |
Then you'd have to worry about identifying the correct remote. There may be multiple to choose of. For example I have
Tongue-in-cheek of course.
Yes, in my opinion that is the case. |
fb7cc0d to
1583f4e
Compare
|
Ok, I'm convinced. The checks are removed. I don't see much value in checking just the committed files status as that doesn't seem like that probable of an issue to have. I can squash the review commits if desired. |
|
Great, looks good to me! Yes I think squashing would be good. Some history can (and should) be preserved, but everything that changed due to review can be squashed. For example, I think the |
1583f4e to
8fe1c56
Compare
- When redirections are detected, rather than printing instructions, update.py now creates two commits -- one with the plugin updates and another with redirected plugin names updated to their new repos. - Added a --allow-dirty flag so that one can run ./update.py --commit with a dirty nixpkgs repository, which is necessary for development. I wouldn't mind removing this before merging if it's not in our flag budget but it's necessary scaffolding for now.
- update.py's new --add argument replaces manual editing of vim-plugin-names for basic use cases.
Adding some abstraction makes main() more readable which is important since it's the main control flow of the script.
Parsing plugin lines in multiple places is hazardous and already manifested a bug!
8fe1c56 to
04f7bfe
Compare
- Use git.Repo(ROOT, search_parent_directories=True) to find nixpkgs repo. - Don't commit overrides.nix. - Remove "-a" short argument. - Remove "--commit" flag and commit by default. - Improve help/error messages. - Favor closure pattern over classes.Use a closure to wrap the update function with state rather than a callable class. - break NixpkgsRepo class into functions - Optional None-type arguments - Remove repo checks from update.py. Git is too flexible and permits too many workflows for my attempt to replace documentation with code to work. My goal would be to separate the `--add` functionality from the update functionality in the near term and then there will be no reason for this usage to create commits anyway.
04f7bfe to
0a27594
Compare
|
There's still one commit that only contains review changes. Is that intentional? If so, that's also fine by me. |
|
Yes, it was intentional because I don't know how to rebase it into the other commits in a reasonable way. |
timokau
left a comment
There was a problem hiding this comment.
If git was the issue, this might help: #82586 (comment) It would probably be a hassle though, and also kind of a shame to waste your well-written commit message.
Thank you for sticking with this and responding so well to feedback.
|
If you need a review in the future or you have reviewed a PR that is ready for merge, feel free to ping me. No guarantees of course. |
Motivation for this change
This is a followup and continuation of the work and discussion in #83119. Highlights:
Things done
sandboxinnix.confon non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"./result/bin/)nix path-info -Sbefore and after)