flox / flox

Developer environments you can take with you
https://flox.dev
GNU General Public License v2.0
2.58k stars 61 forks source link

Install package@X.Y defaults to package@X.Y.Z when available #1968

Open dcarley opened 2 months ago

dcarley commented 2 months ago

Describe the bug:

Unable to install a package at version X.Y when a version is also available at X.Y.Z

This a catalog-server bug, rather than a CLI parsing bug, but I've filed it here for visibility. Minimal reproduction:

% http POST https://api.flox.dev/api/v1/catalog/resolve 'accept: application/json' 'content-type: application/json' <<< '{"items":[{"descriptors":[{"attr_path":"hello","install_id":"hello","systems":["aarch64-darwin"],"version":"2.12"}],"name":"toplevel"}]}'

Steps to reproduce:

  1. flox install hello@2.12
  2. flox list

The same can be reproduced with zsh which also publishes X.Y and X.Y.Z:

% flox show hello
hello - A program that produces a familiar, friendly greeting
    hello@2.12.1
    hello@2.12
    hello@2.10

% flox show zsh  
zsh - The Z shell
    zsh@5.9
    zsh@5.8.1
    zsh@5.8

Result:

hello: hello (2.12.1)

Expected:

hello: hello (2.12)

Flox Version (run flox --version if possible): 1.2.3 @ de6557d1

uname -a output: N/A

billlevine commented 2 months ago

I'm not sure this is a clear cut bug. In semver, if you want any version where major is 5, then you can say @5 and it will match any 5.x and I think that is correct behavior? If you truly want 5.0, you can say @5.0 or @5.0.0 and get it.

So in that sense I'm not 100% confident we really want @5.8 to only ever match 5.8.0. I think allowing it to match 5.8.0, 5.8.1, 5.8.4, etc is correct, with the preference towards the latest revision based on the resolution. In the above if you truly wanted the third option for zsh you could specify @5.8.0 and get it.

IMO all this is correct. The only thing that is off a bit to me is that in my head at least, you could take and of the line items from flox show and install them as displayed and get exactly that. But that doesn't track well with semver, so I'm not sure how to reconcile that, aside from documentation?

dcarley commented 2 months ago

The behaviour does match our docs for version but like you say it doesn't jive well with being able to take the results of flox show and I hadn't thought to look at the docs when I encountered it. What was most surprising for me was that it proceeded silently with a different version than I "specified" so maybe it would be appropriate to warn either a) when X.Y is resolved differently to X.Y.0 , or b) when any wildcard is resolved to true semver?

ghudgins commented 2 months ago

needs design - can we resolve exact matches and fall back to semver?

mkenigs commented 2 months ago

I think it might be more consistent with some other tools to instead require = if you want an exact version. And if we're concerned about copy paste from flox show, we could print

% flox show hello
hello - A program that produces a familiar, friendly greeting
    hello@=2.12.1
    hello@=2.12
    hello@=2.10
billlevine commented 2 months ago

I like that solution. I think it's both consistent with other tooling and also guides users to the syntax to get what they would likely expect if they didn't know any better. And if the do know better, all the options are available to them. Side note that I don't think this is working as expected today. This will need to be addressed as well as part of this. Unsure if this is a catalog server or request issue, however it's probably the catalog.

bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@2.12
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.12.1)
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox uninstall hello
🗑️  'hello' uninstalled from environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@=2.12
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.12.1)
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox edit
⚠️  No changes made to environment.
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox uninstall hello
🗑️  'hello' uninstalled from environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@==2.12
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.12.1)
bill@Bill-FloxDev:~/prj/testing/foo5 $ flox uninstall hello
🗑️  'hello' uninstalled from environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@2.10
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.10)
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@=2.12
⚠️  Package with id 'hello' already installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox uninstall hello
🗑️  'hello' uninstalled from environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox install hello@=2.12
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox edit
⚠️  No changes made to environment.
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.12.1)
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox uninstall hello && flox install hello@2.12.0
🗑️  'hello' uninstalled from environment 'foo5'
✅ 'hello' installed to environment 'foo5'
bill@Bill-FloxDev:~/prj/testing/foo5 
$ flox list
hello: hello (2.12)
ghudgins commented 2 months ago

I like that solution @mkenigs!