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

[Feature Request] Separate "restrict to version X" and "install version X" functionalities #1765

Open
DerekTBrown opened this issue Jul 3, 2024 · 2 comments

Comments

@DerekTBrown
Copy link

Is your feature request related to a problem? Please describe

User Story

  • As a user, I want to be able to enforce that all sub-folders in a given repository use Python X.X.X, but I don't want to require users to install Python X.X.X when they run asdf install in the root of the repository: I only want installation to happen when users run asdf install in a project sub-folder.
  • This feature is critical for working in multi-langauge repositories: it prevents users from having to download a huge toolchain whenever they are working on a specific project.

Describe the proposed solution

Introduce two features:

  1. noinstall
    Following a version in a .tool-versions file, a user can add noinstall:
golangci-lint 1.59.1 noinstall

This line is functionally skipped when running asdf install

  1. inherit
    In place of a version in a .tool-versions file, a user can specify inherit:
golangci-lint inherit

Since this doesn't have the noinstall flag, the parent version would be installed.

Describe similar asdf features and why they are not sufficient

asdf doesn't have this functionality today.

Describe other workarounds you've considered

  • Creating separate linters that look at .tool-versions file. This is clumsy.
@jthegedus
Copy link
Contributor

jthegedus commented Oct 7, 2024

asdf resolves tools in .tool-versions files by walking from the current working directory to the root /, using the closest definition as the requirement. Therefore, you can have .tool-versions files in the sub-directories and only require people to asdf install those when working in sub-directories.

We do this in this repo.

# .tool-versions
bats 1.8.2
shellcheck 0.9.0
shfmt 3.6.0
# docs/.tool-versions
nodejs 20.2.0

when in the repository root, asdf doesn't know about nodejs in the docs/ directory.

~/asdf $ asdf current
bats            1.8.2           ~/asdf/.tool-versions
nodejs          ______          No version is set. Run "asdf <global|shell|local> nodejs <version>"
shellcheck      0.9.0           ~/asdf/.tool-versions
shfmt           3.6.0           ~/asdf/.tool-versions

~/asdf $ cd docs

~/asdf/docs $ asdf current
bats            1.8.2           ~/asdf/.tool-versions
nodejs          20.2.0          ~/asdf/docs/.tool-versions
shellcheck      0.9.0           ~/asdf/.tool-versions
shfmt           3.6.0           ~/asdf/.tool-versions

~/asdf/docs $ cd ..

~/asdf $ asdf install
bats 1.8.2 is already installed
shellcheck 0.9.0 is already installed
shfmt 3.6.0 is already installed

# NOTE: nodejs is completely ignored since we are not in ~/asdf/docs/

Does this not do what you want?

@DerekTBrown
Copy link
Author

Does this not do what you want?

Not quite.

The purpose of the proposed feature is to make it easier to keep versions consistent (i.e. all sub .tool-versions use the same version of a given dependency) without actually enforcing that a given dependency is installed. Right now, you have to choose one or the other:

[Option 1] Specify version once in root .tool-version

✅ Makes it easy to keep versions consistent (just don't specify .tool-versions in sub-dirs).
❌ Python is installed, even in non-Python projects.

$ cat .tool-versions
python 3.12.3

$ cd ./non-python-project
$ cat .tool-versions
<empty>
$ asdf install
<installs python> 

[Option 2] Specify versions separately in sub-directory .tool-versions

✅ Python is only installed in projects which require Python in .tool-versions.
❌ Nothing keeps versions consistent. User must install linter to validate .tool-versions and perform codemods to keep versions up-to-date.

$ cat .tool-versions
<empty>

$ cd ./python-project-1
$ cat .tool-versions
python 3.12.3
$ asdf install
<installs python 3.12.3>

$ cd ../python-project-2
$ cat .tool-versions
python 3.12.7
$ asdf install
<installs python 3.12.7>

[Proposed] Specify version and installation separately

✅ Python is only installed in projects which require Python in .tool-versions.
✅ Makes it easy to keep versions consistent (.tool-versions merely need to specify inherit).

$ cat .tool-versions
python 3.12.3 noinstall

$ cd ./non-python-project
$ cat .tool-versions
<empty>
$ asdf install
<nothing installed>

$ cd ./python-project-1
$ cat .tool-versions
python inherit
$ asdf install
<installs python 3.12.3>

$ cd ../python-project-2
$ cat .tool-versions
python inherit
$ asdf install
<installs python 3.12.3>

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

No branches or pull requests

2 participants