-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
pluginupdate.py: add support for adding/updating individual plugins #336137
Conversation
9c05ff4
to
65d9fa3
Compare
maintainers/scripts/pluginupdate.py
Outdated
Returns: | ||
True if we should update plugin and False if not. | ||
""" | ||
return plugin.name.replace(".", "-") in to_update |
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.
Here you can see how optimistic I was for this PR (26 lines of docs to one line of code)
maintainers/scripts/pluginupdate.py
Outdated
@@ -559,6 +657,7 @@ def run( | |||
parser = self.create_parser() | |||
args = parser.parse_args() | |||
command = args.command or "update" | |||
logging.basicConfig() |
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.
Without this line, any logging using log
variable didn't work. Also, why default log level is warning? It is not annoying on info level, should I change it too?
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.
Logging at info level is a good idea.
maintainers/scripts/pluginupdate.py
Outdated
log.debug("using plugin_line", plugin_line) | ||
log.debug("using plugin_line %s", plugin_line) | ||
pdesc = PluginDesc.load_from_string(fetch_config, plugin_line) | ||
log.debug("loaded as pdesc", pdesc) | ||
log.debug("loaded as pdesc %s", pdesc) |
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 raised an error where complained at the lack of %s
maintainers/scripts/pluginupdate.py
Outdated
current: list[Tuple[PluginDesc, Plugin]], | ||
fetched: List[Tuple[PluginDesc, Union[Exception, Plugin], Optional[Repo]]], | ||
) -> List[Tuple[PluginDesc, Union[Exception, Plugin], Optional[Repo]]]: | ||
result: Dict[str, Tuple[PluginDesc, Union[Exception, Plugin], Optional[Repo]]] = 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.
Those types are copied from check_results
func, and result of this function will be passed to it
maintainers/scripts/pluginupdate.py
Outdated
# remove plugin from index file, so we won't add it | ||
# to deprecations again | ||
for i, plugin in enumerate(plugins): | ||
if plugin.name == pdesc.name: |
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 you could see at the description of third commit, someone just forgot about deleting plugins from index for years!
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.
Time for some cleaning 🧹
maintainers/scripts/pluginupdate.py
Outdated
@@ -772,7 +875,7 @@ def rewrite_input( | |||
fieldnames = ["repo", "branch", "alias"] | |||
writer = csv.DictWriter(f, fieldnames, dialect="unix", quoting=csv.QUOTE_NONE) | |||
writer.writeheader() | |||
for plugin in sorted(plugins): | |||
for plugin in sorted(plugins, key=lambda x: x.name): |
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.
interesting fact: plugin's URI is not unique, but name is. It is because there can be multiple plugins in one repo but on different branches (e.g. different versions, see harpoon) and name is used as a key in the final result
sh = logging.StreamHandler() | ||
formatter = logging.Formatter("%(name)s:%(levelname)s: %(message)s") | ||
sh.setFormatter(formatter) | ||
log.addHandler(sh) |
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 is unnecessary with logging.basicConf
in the main file
@ofborg eval |
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.
Some initial feedback. This looks great -- thanks for your work here @PerchunPak.
What remains:
- I need to validate each URL update
- You mentioned that I have some work to do for kakoune. Could you make it more clear for me what's broken and what I ought to pay attention to?
- This deprecated.json thing is a total mess. What would cleanup look like?
Thank you!
outfile: str, | ||
config: FetchConfig, | ||
# TODO: implement support for adding/updating individual plugins | ||
to_update: Optional[List[str]], |
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.
Want to raise an error if this is non-None
so that it's not frustrating that it's not working?
maintainers/scripts/pluginupdate.py
Outdated
repo, | ||
branch.strip(), | ||
# alias is usually an empty string | ||
# I wasted ~5 hours to find out 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.
😢
Sometimes it's that way...
maintainers/scripts/pluginupdate.py
Outdated
|
||
def get_current_plugins(self, nixpkgs) -> List[Plugin]: | ||
def get_current_plugins( | ||
self, config: FetchConfig, nixpkgs: str |
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.
Mind pushing a commit that does ruff format
on this file? Getting a consistent style would be great.
maintainers/scripts/pluginupdate.py
Outdated
version = version_split[1] if len(version_split) > 1 else version_split[0] | ||
date = datetime.strptime(version, "%Y-%m-%d") | ||
|
||
pdesc = PluginDesc.load_from_string(config, attr["homePage"] + " as " + name) |
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 usually do f
strings instead of +
, but it's only as preference.
pdesc = PluginDesc.load_from_string(config, attr["homePage"] + " as " + name) | |
pdesc = PluginDesc.load_from_string(config, f'{attr["homePage"]} as {name}') |
maintainers/scripts/pluginupdate.py
Outdated
def get_update(self, input_file: str, outfile: str, config: FetchConfig): | ||
cache: Cache = Cache(self.get_current_plugins(self.nixpkgs), self.cache_file) | ||
def filter_plugins_to_update(self, plugin: PluginDesc, to_update: List[str]) -> bool: | ||
"""Function for filtering out plugins, that user doesn't want to update. |
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.
"""Function for filtering out plugins, that user doesn't want to update. | |
"""filter_plugins_to_update exists to filter out plugins that user doesn't want to update. |
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 am pretty sure this breaks the Google style I used in this docstring. Though the closest rule I could find is https://docs.astral.sh/ruff/rules/no-signature/
maintainers/scripts/pluginupdate.py
Outdated
filter_func = functools.partial(self.filter_plugins_to_update, to_update=to_update) | ||
plugins_to_update = list( | ||
filter(filter_func, current_plugin_specs) | ||
if to_update | ||
else current_plugin_specs | ||
) |
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'm big on list comprehensions instead of functools.partial
or map
/filter
calls, mostly because they seem to my eyes to read better.
What do you think about this suggestion?
filter_func = functools.partial(self.filter_plugins_to_update, to_update=to_update) | |
plugins_to_update = list( | |
filter(filter_func, current_plugin_specs) | |
if to_update | |
else current_plugin_specs | |
) | |
plugins_to_update = current_plugin_specs if len(to_update) == 0 else [ | |
description | |
for description in current_plugin_specs | |
if self.filter_plugins_to_update(description, to_update) | |
) |
maintainers/scripts/pluginupdate.py
Outdated
@@ -559,6 +657,7 @@ def run( | |||
parser = self.create_parser() | |||
args = parser.parse_args() | |||
command = args.command or "update" | |||
logging.basicConfig() |
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.
Logging at info level is a good idea.
maintainers/scripts/pluginupdate.py
Outdated
# remove plugin from index file, so we won't add it | ||
# to deprecations again | ||
for i, plugin in enumerate(plugins): | ||
if plugin.name == pdesc.name: |
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.
Time for some cleaning 🧹
maintainers/scripts/pluginupdate.py
Outdated
args.input_file, | ||
args.outfile, | ||
fetch_config, | ||
getattr(args, "update_only", None), # if script was called without arguments |
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 recommend using names for the parameters here.
args.input_file, | |
args.outfile, | |
fetch_config, | |
getattr(args, "update_only", None), # if script was called without arguments | |
input_file=args.input_file, | |
output_file=args.outfile, | |
config=fetch_config, | |
to_update=getattr(args, "update_only", None), # if script was called without arguments |
@@ -21,30 +21,40 @@ | |||
) | |||
import pluginupdate | |||
|
|||
GET_PLUGINS = f"""(with import <localpkgs> {{}}; | |||
GET_PLUGINS = f"""with import <localpkgs> {{ }}; |
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 is the broken updater?
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.
Yes, if you run
cd pkgs/applications/editors/kakoune/plugins
nix-shell update-shell.nix
python update.py
It outputs (on master and here is the same error)
error:
… <borked>
at «none»:0: (source not available)
… from call site
at «string»:1:6:
1| with import <localpkgs> { };
| ^
2| let
error: function 'anonymous lambda' called without required argument 'kakouneUtils'
at /home/perchun/dev/nixpkgs/pkgs/applications/editors/kakoune/plugins/default.nix:1:1:
1| { callPackage, config, kakouneUtils, lib }:
| ^
2|
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.
@philiptaron ^^^
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! It's on the list to go fix. I'm camping this weekend but will attend to it when back.
03d3245
to
16419ba
Compare
Pushed changes from review and formatting changes in different force pushes for simpler reviewing. I didn't push it as a new commit, as it would create a lot of conflicts if there will be other changes. Thanks for the review! |
This should be easy with Result of 3 packages built:
Which means no Vim plugins were changed/removed/added. I also quickly glanced over the diff on generated.nix after the full plugin update and didn't find any plugins that were moved/removed/added (before I created the PR there were a few bugs with sorting).
What do you mean? The file |
maintainers/scripts/pluginupdate.py
Outdated
:param expr nix expression to fetch current plugins | ||
:param nixpkgs Path towards a nixpkgs checkout | ||
''' | ||
""" |
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.
aws this changed by the black formatter ?
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 ran ruff format
which is 99.9% compatible with black (just because it was installed on my system), so whatever?
If you want to update only certain plugins, you can specify their names to `--update` flag. Note that those name must be the same as in `pkgs/applications/editors/vim/plugins/vim-plugin-names` file. | ||
|
||
```sh | ||
nix-shell -p vimPluginsUpdater --run 'vim-plugins-updater --update "nvim-treesitter" "LazyVim"' |
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.
apparently it's not --update but update:
nix run .#vimPluginsUpdater -- update nvim-treesitter LazyVim
WARNING:root:You have enabled parallel updates but haven't set a github token.
You may be hit with `HTTP Error 429: too many requests` as a consequence.Either set --proc=1 or --github-token=YOUR_TOKEN.
path is '/nix/store/rgwip825v0m4nhsvqyabf0mb2as81x0q-0b8b78f9d08dc338a146eb4cd4bcbed8dd36a783.tar.gz'
2 of 1471 were checked
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.
Fixed here, thanks!
thanks for the great work. It's a very exciting feature. I had thought of a treesitter-based solution but this seems to work as well. Not having the feature in all updaters is no problem, that's part of the design. I am a bit annoyed that you have mixed different things in the PR (logging level, formatting, sorting, new feature). Most of it I want to merge but some of it (the update filtering) I would like to test & experiment with myself more. Would it be too much to ask for the sorting fix in a separate PR ? |
16419ba
to
0c32241
Compare
Unfortunately, most of those changes are QOL and usually they fix some weird bug, that prevents from properly implementing individual updates. For example, before sorting was completely broken (it sorted by if self.alias is not None:
return self.alias
else:
return self.repo.name BUT
Ok, I will revert |
9b7f93d
to
644404a
Compare
I am reviewing (and merging with the help of GaetanLepage) all |
644404a
to
3a767d0
Compare
I fixed a lot of hidden bugs and did some small improvements here and there. The main reason this was separated from NixOS#336137 is for fixing the sorting issue. Before this commit, sorting for Vim plugins was broken, and worked by what was fetched first. This is because sorting was done by empty string (default value in CSV is not None, but empty string). This PR fixes it and also moves sorting from user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
I fixed many hidden bugs and made some small improvements. The main reason this was separated from NixOS#336137 is to fix the sorting issue. Before this commit, sorting for Vim plugins was broken and worked by what was fetched first. This is because the sorting was done by empty strings (the default value in CSV is not None but an empty string). This PR fixes it and also moves sorting from the user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
I fixed many hidden bugs and made some small improvements. The main reason this was separated from NixOS#336137 is to fix the sorting issue. Before this commit, sorting for Vim plugins was broken and worked by what was fetched first. This is because the sorting was done by empty strings (the default value in CSV is not None but an empty string). This PR fixes it and also moves sorting from the user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
Blocked by #353786, will resolve conflicts after it is merged. |
I fixed many hidden bugs and made some small improvements. The main reason this was separated from NixOS#336137 is to fix the sorting issue. Before this commit, sorting for Vim plugins was broken and worked by what was fetched first. This is because the sorting was done by empty strings (the default value in CSV is not None but an empty string). This PR fixes it and also moves sorting from the user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
I fixed many hidden bugs and made some small improvements. The main reason this was separated from NixOS#336137 is to fix the sorting issue. Before this commit, sorting for Vim plugins was broken and worked by what was fetched first. This is because the sorting was done by empty strings (the default value in CSV is not None but an empty string). This PR fixes it and also moves sorting from the user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
I fixed many hidden bugs and made some small improvements. The main reason this was separated from NixOS#336137 is to fix the sorting issue. Before this commit, sorting for Vim plugins was broken and worked by what was fetched first. This is because the sorting was done by empty strings (the default value in CSV is not None but an empty string). This PR fixes it and also moves sorting from the user to the library (from `vim/plugins/update.py` to `pluginupdate.py`) to prevent such weird issues and duplication of code.
8b8cfef
to
ecee72e
Compare
current: list[Tuple[PluginDesc, Plugin]], | ||
fetched: List[Tuple[PluginDesc, Union[Exception, Plugin], Optional[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.
current: list[Tuple[PluginDesc, Plugin]], | |
fetched: List[Tuple[PluginDesc, Union[Exception, Plugin], Optional[Repo]]], | |
current: list[tuple[PluginDesc, Plugin]], | |
fetched: list[tuple[PluginDesc, Exception | Plugin, Repo | 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.
The implementation looks good overall. Have you been able to successfully test it ?
Yep, I ran it here |
haven't tested but I feel confident that any potential problem will be solved swiftly :) |
Description of changes
This PRs adds long-awaited support for updating individual plugins to Vim and Kakoune (
LuaEditor
is a third class that usespluginupdate.py
, but they patch too much inpluginupdate
, so I leave it to someone else).As a bonus (though it was my main goal), I implemented adding an entry to
generated.nix
when adding a plugin using the script. I also implemented a whole bunch of bugfixes and I will document some things as comments here.Feel free to correct grammar, I am not a native, so will gladly accept any grammar nitpicks.
Fixes #218584.
Things done
Things tested:
generated.nix
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)CC @teto (author of #218696), @figsoda (maintainer of Vim), @philiptaron (maintainer of Kakoune)
Add a 👍 reaction to pull requests you find important.