-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
vimPlugins: Automate git commits when updating. #83788
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
Conversation
The roadmap I envision going forward is to break out the |
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.
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
|
||
return parser.parse_args() | ||
|
||
|
||
def main() -> None: | ||
def get_nixpkgs_repo() -> git.Repo: | ||
repo = git.Repo(NIXPKGS_PATH) |
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.
We can get rid of NIXPKGS_PATH
by using git.Repo(".", search_parent_directories=True)
.
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 would think if we used ROOT
rather than .
we could avoid the assumption that the current working directory is vim-plugins
.
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 idea, that is better.
pkgs/misc/vim-plugins/update.py
Outdated
def get_nixpkgs_repo() -> git.Repo: | ||
repo = git.Repo(NIXPKGS_PATH) | ||
if repo.is_dirty(): | ||
raise Exception("Please stash your changes before updating.") |
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 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
|
||
def main() -> None: |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -263,7 +263,7 @@ Sometimes plugins require an override that must be changed when the plugin is up | |||
|
|||
To add a new plugin: | |||
|
|||
1. run `./update.py` and create a commit named "vimPlugins: Update", | |||
1. run `./update.py --commit`, |
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.
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
@@ -413,6 +416,11 @@ def generate_nix(plugins: List[Tuple[str, str, Plugin]], outfile: str): | |||
print(f"updated {outfile}") | |||
|
|||
|
|||
def commit_changes(repo: git.Repo, *files: Path): |
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 files
should be an explicit list instead.
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 knew you would and changed it in a subsequent commit.
pkgs/misc/vim-plugins/update.py
Outdated
"-a", | ||
dest="add_plugins", | ||
action="append", | ||
help="Plugin to add to vimPlugins in the form owner/repo", |
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.
It would be nice to mention that this has to be hosted on github.
pkgs/misc/vim-plugins/update.py
Outdated
rewrite_input(args.input_file, redirects) | ||
|
||
if args.commit: | ||
nixpkgs_repo.commit("Update", [args.outfile]) | ||
nixpkgs_repo.commit("vimPlugins: Update", [args.outfile]) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if redirects: | ||
update_plugins(args.input_file, args.outfile, cache) | ||
nixpkgs_repo.commit( | ||
"Update redirects", [args.outfile, args.input_file, DEPRECATED] | ||
"vimPlugins: Update redirects", |
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.
Something more explicit might be nice here, such as resolve github repository redirects
.
pkgs/misc/vim-plugins/update.py
Outdated
"vimPlugins.{name}: init at {version}".format( | ||
name=plugin.normalized_name, version=plugin.version | ||
), | ||
[args.outfile, args.input_file, OVERRIDES], |
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.
Why commit OVERRIDES
?
pkgs/misc/vim-plugins/update.py
Outdated
results = pool.map(prefetch_with_cache, plugin_names) | ||
finally: | ||
cache.store() | ||
def __call__(self) -> Dict: |
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'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
name, repo = line.split("/") | ||
try: | ||
repo, alias = repo.split(" as ") | ||
return (name, repo, alias.strip()) | ||
except ValueError: | ||
# no alias defined | ||
return (name, repo.strip(), None) | ||
return (name, repo.strip(), "") |
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.
Why did you change this?
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 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
@@ -218,16 +220,17 @@ def get_current_plugins() -> List[Plugin]: | |||
|
|||
|
|||
def prefetch_plugin( | |||
user: str, repo_name: str, alias: str, cache: "Cache" | |||
user: str, repo_name: str, alias: str, cache: "Cache" = None |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
or repo.head.commit != repo.heads.master.commit | ||
): | ||
raise Exception( | ||
"Please create a new branch based off master before running " "this tool." |
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.
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. |
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.
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
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)