-
-
Notifications
You must be signed in to change notification settings - Fork 347
flake: add diff-plugins command #3510
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
Prints the plugins added or removed when compared to a particular nixvim revision.
def list_plugins(flake: str) -> list[str]: | ||
""" | ||
Gets a list of plugins that exist in the flake. | ||
Grouped as "plugins" and "colorschemes" | ||
""" | ||
expr = """ | ||
options: | ||
builtins.listToAttrs ( | ||
map | ||
(name: { | ||
inherit name; | ||
value = builtins.attrNames options.${name}; | ||
}) | ||
[ | ||
"plugins" | ||
"colorschemes" | ||
] | ||
) | ||
""" | ||
cmd = [ | ||
"nix", | ||
"eval", | ||
f"{flake}#nixvimConfiguration.options", | ||
"--apply", | ||
expr, | ||
"--json", | ||
] | ||
out = subprocess.check_output(cmd) | ||
# Parse as json, converting the lists to sets | ||
return {k: set(v) for k, v in json.loads(out).items()} |
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.
Does it make sense to try just leveraging our list-plugins
package/script?
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 thought about it briefly, but I think it's simpler to keep them separate?
The list-plugins script is meant to print a user-readable summary of the plugins, right? While this one is meant to print a JSON diff.
Unless you have ideas for how we could do it without adding too much complexity to the list-plugins script?
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, this looks to be a pretty simple implementation. We can always refactor later since it might require some more rework for list-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.
Didn't test, but changes look good to me.
after_plugins = list_plugins(".") | ||
before_plugins = list_plugins(args.flakeref) |
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.
Could make it more robust and allow passing in 2 flakerefs if we wanted to compare between different locations, even. Then default to .
when its not provided? Just a thought for future possibility
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 had this in the previous attempts. I left it out of this one to keep things as simple as possible.
Follow-up PRs welcome 😉
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.
Ended up actually needing this in #3513 🙈
Prints the plugins added or removed when compared to a particular nixvim revision.
This is intended as a starting point for automatically generating the matrix announcements, as attempted in #2255 and #2593.
I may consider moving the python script into the
ci/
directory to make sparse-checkout easier if it ends up being used by CI workflows. Although, saying that the full checkout would be needed to compare its plugins to the other anyway...A CI workflow can use this script by supplying
github.event.before
, which foron: push
events comes from thepush
webhook event payload. Alternatively we might usegithub.event.pull_request.base.sha
frompull_request_target
, since that also gives us access to things likegithub.event.pull_request.number
(pull_request: closed
webhook event).This script can be tested locally by running
diff-plugins <some_sha>
to compare the current local nixvim to some arbitrary "before" state.