Skip to content
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

feat: Displays a warning when a plugin from the tools-version list does not exist #1033

Merged
merged 7 commits into from Oct 1, 2021

Conversation

threkk
Copy link
Contributor

@threkk threkk commented Aug 29, 2021

Summary

When calling the install command, asdf tries to look for versions for all the plugins available and installs them. With this change, it will attempt to find versions for all the installed plugins and plugins defined in the .tool-versions.

Other Information

Fixes #574

@threkk threkk requested a review from a team as a code owner August 29, 2021 13:02
@threkk threkk changed the title feat: Displays a warning when the plugin from the tools-version does not exist feat: Displays a warning when a plugin from the tools-version list does not exist Aug 29, 2021
@jthegedus
Copy link
Contributor

If multiple plugins are not present on the system, will this error for the first it finds in the list, with a rerun required to then error on the next missing plugin? Assuming that is true, is there a way we could log/warn of all missing plugins as opposed to the first not found?

@threkk
Copy link
Contributor Author

threkk commented Sep 4, 2021

I have rewritten the plugin installation. This approach preserves the original installation and at the same time it will report plugin's not available. It will also not stop in case there is a missing plugin.

@jthegedus
Copy link
Contributor

Great, thanks for the update. Can you write test cases to cover these scenarios to prevent regressions?

@threkk
Copy link
Contributor Author

threkk commented Sep 6, 2021

Sure! I will try to find time this week(end) and come back with an update :)

@Stratus3D
Copy link
Member

I have rewritten the plugin installation. This approach preserves the original installation and at the same time it will report plugin's not available. It will also not stop in case there is a missing plugin.

I think we should stop installing when a missing plugin is encountered. Some projects define plugins in the order they must be installed in, because certain plugins depend on others. Proceeding to install subsequent versions after a plugin is not found could cause problems.

if [ -f "$tool_versions_path" ]; then
tools_file=$(strip_tool_version_comments "$tool_versions_path" | cut -d ' ' -f 1)
for plugin_name in $tools_file; do
if [[ ! "${plugins_installed[*]}" =~ $plugin_name ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same logic we use elsewhere in the codebase? I think this might cause problems if two plugins share matching prefixes. For example, ag and age are both existing plugins right now. With this logic, age could match the plugin name ag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that is the first occurrence of that comparison. I will turn it into an exact comparison.

@jthegedus
Copy link
Contributor

I think we should stop installing when a missing plugin is encountered.

Fine with me, but I would like the output to show all missing plugins, as opposed to just the first encountered missing so it is a showstopper only once.

@threkk
Copy link
Contributor Author

threkk commented Sep 7, 2021

The changes are then;

  • Fix the comparison for the plugin name (~= -. ==)
  • Exit if at least one plugin is missing.
  • Add unit tests to avoid future regresions.
    Do I forget anything?

@Stratus3D
Copy link
Member

The changes are then;

* Fix the comparison for the plugin name (`~=` -. `==`)

* Exit if at least one plugin is missing.

* Add unit tests to avoid future regresions.
  Do I forget anything?

I think that is all. Thanks again for your work on this. @jthegedus do you have anything to add?

@jthegedus
Copy link
Contributor

jthegedus commented Sep 15, 2021

Just for clarity (bolded my additions):

  • Fix the comparison for the plugin name (~= -. ==)
  • Compute list of all missing plugins.
  • Exit if at least one plugin is missing , warn with the whole list of all missing plugins.
  • Add unit tests to avoid future regresions.

Thanks for tackling our feedback @threkk

@threkk
Copy link
Contributor Author

threkk commented Sep 18, 2021

I made the changes discussed before. The tests run successfully in Ubuntu, but OSX tests look broken in general. Is this a known issue or do I need to change the code?

@Stratus3D
Copy link
Member

I made the changes discussed before. The tests run successfully in Ubuntu, but OSX tests look broken in general. Is this a known issue or do I need to change the code?

@threkk, not sure about the tests. They are passing on the latest commit of the master branch. You could try rebasing your PR branch on top of latest master, although I'm not sure that will fix it.

@Stratus3D
Copy link
Member

When I clone down your branch and run it locally (on OSX 10.15.7 (19H1323)) all but two tests pass. The two failures were:

 ✗ install_command deletes the download directory
   (in test file test/install_command.bats, line 261)
     `[ ! -d $ASDF_DIR/downloads/dummy/1.1.0 ]' failed
 ✗ asdf update --head should checkout the master branch
   (in test file test/update_command.bats, line 33)
     `[ $(git rev-parse --abbrev-ref HEAD) = "master" ]' failed
   Cloning into '/var/folders/7m/9bq62tmj60zf14d788w0lk8c0000gp/T/asdf.XXXX.4Z9epbdy/home/.asdf'...

The first test always fails for me locally (even on master) and the second only failed because I was on your branch and not the master branch when I ran the tests. So I don't see any issues here with your code. Perhaps try re-running the tests on GH or try rebasing onto latest master?

…not exist

When calling the install command, it tried to look for versions for all
the plugins available and installed them. With this change, it will attempt to
find versions for all the installed plugins and plugins defined in the
`.tool-versions`.

Fixes asdf-vm#574
This patch changes the algorithm. It preserves the original logic for
the plugin resolution, but at the same time, reports entries with plugins not
available.
- Changes the comparison to be strict rather than partial.
- Prints a list of missing plugins.
- Exists if at least one plugin is not present.
- Adds unit tests.
@threkk
Copy link
Contributor Author

threkk commented Sep 23, 2021

I rebased the branch and sadly the issues still persist on OSX. This seems to be some difference between OSX and Ubuntu. I will try to reproduce on a OSX machine to pin point the issue but I can't tell exactly when I will be able. If anyone has any idea about what can be wrong, I will appreciate the help :) I have my suspicions on grep behaving differently, but cannot prove it.

@threkk
Copy link
Contributor Author

threkk commented Sep 30, 2021

It took me some time, but finally found the problem: one of the flags was a *nix only flag and was causing the errors. Once removed, everything works as expected :)

@jthegedus
Copy link
Contributor

Thanks @threkk !! We will add grep -P to our list of banned commands/flags so we don't hit this type of issue again 🙏

Copy link
Contributor

@jthegedus jthegedus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Feel free to merge if you're happy @Stratus3D

@Stratus3D Stratus3D merged commit 9430a39 into asdf-vm:master Oct 1, 2021
threkk added a commit to threkk/asdf that referenced this pull request Oct 6, 2021
As explained in asdf-vm#1062 asdf-vm#1033, `-P` is an option that does not exist in
OSX and causes problems of compatibility.
threkk added a commit to threkk/asdf that referenced this pull request Oct 6, 2021
As explained in asdf-vm#1062 asdf-vm#1033, `-P` is an option that does not exist in
OSX and causes problems of compatibility.
@MPV
Copy link

MPV commented Nov 4, 2021

Cool stuff! Would it be possible to cut a new release including this change?

@jthegedus
Copy link
Contributor

We will release 0.9.0 once we finish items in the milestone and fix bugs introduced in head

@cmur2
Copy link

cmur2 commented Dec 11, 2021

I think we should stop installing when a missing plugin is encountered. Some projects define plugins in the order they must be installed in, because certain plugins depend on others. Proceeding to install subsequent versions after a plugin is not found could cause problems.

This change breaks my workflow as I intentionally do not install all plugins on all my machines (depending on which I need). Is there any way to disable this feature (looking at the code I guess no) or make it so it can be disabled?

@Stratus3D
Copy link
Member

@cmur2 I think you make a valid point. Specifically, how do these changes break your current workflow?

We may want to provide a flag or configuration option so that missing plugins do not cause the install command to exit with a status of 1.

@cmur2
Copy link

cmur2 commented Dec 13, 2021

@Stratus3D I use a shared dotfiles repo between several of my machines (e.g. work and private ones) to share a .tool-versions (symlinked from the dotfiles git checkout to my home directory) among those machines so updating tools is less of a hassle (once instead of once per machine).

For work I might need kubectl which I don't use privately so it's in $HOME/.tool-versions and on the work machine I've added the asdf plugin for that but not on the private machine. This e.g. saves download bandwidth and disk storage on my private machine.

I also have other tools like nodejs which I might need at work and privately so I've added the asdf plugin on both machines.

After the update to asdf-vm v0.9.0, I cannot update nodejs on my private machine anymore since asdf complains about the missing kubectl plugin and exits with 1. It'd be cool if asdf could just ignore this state (optionally).

For now I used sed -i 's/-n "$some_plugin_not_installed"/-n ""/g' "$ASDF_DIR/lib/commands/command-install.bash" after updating asdf to workaround this.

@Stratus3D
Copy link
Member

@cmur2 #1123 has been created for this. Let's continue the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Plugin Doesn't Generate a warning
5 participants