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

Support for asdf v0.16.0? #194

Open
esran opened this issue Feb 4, 2025 · 10 comments · May be fixed by #195
Open

Support for asdf v0.16.0? #194

esran opened this issue Feb 4, 2025 · 10 comments · May be fixed by #195

Comments

@esran
Copy link

esran commented Feb 4, 2025

I only just started using asdf and direnv and already there have been updates. asdf v0.16.0 is a major rewrite in Golang. It looks like it breaks direnv.

In a directory with use asdf in the .envrc:

direnv: loading ~/<path>/.envrc
direnv: using asdf
direnv: referenced version: v0.16.0

<-- snip default asdf help output -->

"Late but latest"
-- Rajinikanth does not exist
direnv: export ~PATH

It might be that the new golang version of asdf is fast enough even with shims. However, I kind of need the environment setup of direnv so I can remove shims from the PATH. This is because asdf keeps a shim for old python versions (e.g. python3.6) even when not being used. And cmake python detection gets tripped up by this as its in the PATH and executable but not actually valid.

For now I'm happy enough to keep using asdf v0.15.0 but it would be nice to be on the latest version of things.

@reneploetz
Copy link

reneploetz commented Feb 4, 2025

There are a few issues that probably need to be done for asdf 0.16.0 support:

To make it work minimally, you need to do:

  • edit $HOME/.config/direnv/lib/use_asdf.sh to call "asdf cmd direnv envrc" (= adding an additional "cmd")

To make the "asdf cmd direnv" commands work, you need to:

  • rename all commands in .asdf/plugins/direnv/lib/commands to remove the ".bash" ending (or use "asdf cmd direnv [command].bash")
  • make them executable (chmod +x)

This should make the version work for the time being, but a mid-term issue is this pull request: asdf-vm/asdf#1822
Currently, this plugin sources asdf bash functions which may be removed soonish. Therefore, this plugin needs to be rewritten to use the output of asdf directly. Or copy the functions over and hope that the disk layout never changes.

@esran
Copy link
Author

esran commented Feb 4, 2025

Nice. Those changes look like they work.

missingcharacter added a commit to missingcharacter/dot-files that referenced this issue Feb 5, 2025
to make `asdf` version `0.16.1` work with `direnv`
@gotgenes
Copy link
Contributor

gotgenes commented Feb 6, 2025

@reneploetz Very helpful; thank you!

FWIW, my commands scripts are located in $ASDF_DATA_DIR/plugins/direnv/lib/commands/.

@austinmatherne-wk
Copy link

I made the suggested changes, but I'm getting the following error:

direnv: loading ~/.envrc
direnv: using asdf
direnv: Could not find asdf utils.bash file in /opt/homebrew/Cellar/asdf/0.16.1
direnv: referenced does not exist

@reneploetz
Copy link

reneploetz commented Feb 7, 2025

As stated: This plugin currently requires files from the bash version of asdf. This means that you need to have get the source from either git or source download and point the environment variable "ASDF_DATA_DIR" to it (alternative/default: $HOME/.asdf).
Specifically, $ASDF_DATA_DIR/lib/utils.bash must exist.

It's not sufficient to just download the asdf binary and I assume that the homebrew version only installs the binary and shell completions.

@richtong
Copy link

richtong commented Feb 10, 2025

OK, I created a fork and issued a pull request that makes the bash command changes and changes the setup to use the proper new cmd syntax and it also caches the asdf library in a new directory lib-asdf because I couldn't figure out a good way to track changes there (without an entire submodule that is itself asdf which seems a bit strange).

Hard to test on different configurations but seems to work on MacOS Sequoia 15.3 and thanks to @esran for figuring out the issues, that is one tangle of bash scripts!

Also note to maintainers, I also updated the README.md because all references to asdf direnv have to change to asdf cmd direnv and also the self checks are failing because lib-asdf was never shellchecked. I didn't fix because that would further diverge this copy from the source and make it hard to update. I didn't feel like I should change any GitHub actions, but the fix is to ignore lib-asdf in the spellcheck

The other problem is that the syntax change breaks old tests as they use the older syntax. The fix there is to tag this fix as 0.16 specific but again I didn't want to break how you version. Since 0.16 is really a breaking change, they should have done 1.01 to signal it (but of course you can't really do that for software like this). And this plugin should also jump versions but again I didn't feel like this was my "job" to make the testing and version decisions.

I also made some other changes, the old asdf bash disabled set -e and -o pipe fail, but if you have these loaded then various scripts will fail. There is a one line change to lib-asdf (I tried to avoid it but couldn't think of a way to do it where it does a -n check for a variable that may not exist. I changed it to -v). Also if you are using venv, the old asdf direnv local python 3.12.7 command breaks. I fixed two problems here, first the maybe_run is broken because of the -e and -o pipe fail problems, so I turned those off when doing maybe_run.

Finally local no longer exists, so I turned it into asdf cmd direnv set python 3.12.7 but for compatibility left the asdf cmd direnv local python 3.12.7 running (man they made lots of breaking changes in 0.16.

Quick code not the proudest moment of bash hacking #195

@jfly
Copy link
Contributor

jfly commented Feb 10, 2025

@richtong, where is this PR?

@richtong richtong linked a pull request Feb 10, 2025 that will close this issue
@richtong
Copy link

Last note if someone wants to get running is to just use this branch the easy thing to do is:

cd ~/.asdf/plugins/direnv
# this is just a git clone of this repo
git remote add richtong [email protected]:richtong/asdf-direnv
git fetch --all
# now you can create your private branch
git switch -c rich-direnv
git rebase upstream richtong/rich-direnv

And you will have this branch until the next time you update. Hopefully someone will fix this at some point, but at least this works for me now.

@richtong
Copy link

OK, I think I have all the fixes, including getting the use_asdf.sh working again, it is in an outstanding pull request #195

If you really want this to work again, you can also

asdf direnv install https://github.com/richtong/asdf-direnv

And it should work. The only thing that's a pain is that use_asdf.sh is copied into your ~/.config/direnv/lib directory, so you need to fix that file, just add "cmd" to the single line there.

@richtong
Copy link

And there is a case where I changed the old asdf local to asdf set as well

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

Successfully merging a pull request may close this issue.

6 participants