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

add indication of DAML_SDK_VERSION for daml version #7385

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

garyverhaegen-da
Copy link
Contributor

Fixes #7381.

$ alias daml=~/.daml/sdk/0.0.0/daml/daml
$ daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=invalid daml version
daml: Invalid value for environment variable DAML_SDK_VERSION.
  context: Determining SDK version and path.
  details: Invalid SDK version  "invalid": Failed reading: takeWhile1

$ DAML_SDK_VERSION=1.4.4 daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.4.4                                    (selected by env var DAML_SDK_VERSION, not installed)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=1.4.0 daml version
DAML SDK versions:
  0.0.0
  1.4.0                                    (selected by env var DAML_SDK_VERSION)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=1.5.0-snapshot.20200902.5118.0.2b3cf1b3 daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (selected by env var DAML_SDK_VERSION, default SDK version for new projects)
$

CHANGELOG_BEGIN
CHANGELOG_END

Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

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

Excellent idea. Thank you.

Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Nice thank you!
I’m slightly confused about the PR title. Is this only referring to daml-head as that one sets the environment variable? Once you’ve created a project with daml-head new, it will just pick up the version from daml.yaml so this shouldn’t change much.

@garyverhaegen-da garyverhaegen-da changed the title add indication of DAML_SDK_HEAD for daml version add indication of DAML_SDK_VERSION for daml version Sep 14, 2020
Fixes #7381.

```
$ alias daml=~/.daml/sdk/0.0.0/daml/daml
$ daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=invalid daml version
daml: Invalid value for environment variable DAML_SDK_VERSION.
  context: Determining SDK version and path.
  details: Invalid SDK version  "invalid": Failed reading: takeWhile1

$ DAML_SDK_VERSION=1.4.4 daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.4.4                                    (selected by env var DAML_SDK_VERSION, not installed)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=1.4.0 daml version
DAML SDK versions:
  0.0.0
  1.4.0                                    (selected by env var DAML_SDK_VERSION)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)
$ DAML_SDK_VERSION=1.5.0-snapshot.20200902.5118.0.2b3cf1b3 daml version
DAML SDK versions:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (selected by env var DAML_SDK_VERSION, default SDK version for new projects)
$
```

CHANGELOG_BEGIN
CHANGELOG_END
@garyverhaegen-da garyverhaegen-da force-pushed the show-env-version-in-daml-version branch from 16c7abf to 0d79df6 Compare September 14, 2020 09:00
@garyverhaegen-da
Copy link
Contributor Author

Nice thank you!
I’m slightly confused about the PR title. Is this only referring to daml-head as that one sets the environment variable? Once you’ve created a project with daml-head new, it will just pick up the version from daml.yaml so this shouldn’t change much.

Updated title: it was meant to be the env var, so DAML_SDK_VERSION.

daml-head sets the env var before calling daml, so I believe it ignores daml.yaml for that. It does bring this issue though:

$ daml-head version
DAML SDK versions:
  0.0.0                                    (selected by env var DAML_SDK_VERSION)
  1.4.0                                    (project SDK version from daml.yaml)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3

As a user, this does not leave me with a clear answer as to which version I'm using. Any suggestion on how to deal with that?

@bame-da
Copy link
Contributor

bame-da commented Sep 14, 2020

I'd always just show one indicator:

Inside a project:

DAML SDK versions:
  0.0.0
  1.4.0                                    (project SDK version from daml.yaml)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3

Outside a project without an env variable:

DAML SDK versions:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3  (default SDK version for new projects)

Outside a project with an env variable:

DAML SDK versions:
  0.0.0                                    (selected by env var DAML_SDK_VERSION)
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3

@cocreature
Copy link
Contributor

I think your last point should probably be Inside a project with env var. Personally I find it useful to see the version in the daml.yaml even if I have an env var. Maybe we can add overridden by env var to the version in the daml.yaml or overrides version in daml.yaml to the env var.

@garyverhaegen-da
Copy link
Contributor Author

Perhaps a star like git branch? Or a more detailed output, like:

DAML SDK versions installed:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3
SDK version selected:
* 0.0.0 (env var SDK_DAML_VERSION)
  1.4.0 (/full/path/to/daml.yaml)
  1.5.0 (default)

@cocreature
Copy link
Contributor

I like the star!

Copy link
Contributor

@sofiafaro-da sofiafaro-da left a comment

Choose a reason for hiding this comment

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

Regarding the PR: Nice addition! I like it.

Regarding the star: It looks nice but it's vague, and might lead people to be confused about how SDK versions work. Personally I would add a second "overrides daml.yaml" clause in cases where the environment variable is given, there is a project path, and the project sdk version doesn't match the env var version, like:

$ daml-head version
DAML SDK versions:
  0.0.0                                    (selected by env var DAML_SDK_VERSION, overrides daml.yaml)
  1.4.0                                    (project SDK version from daml.yaml)
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3

@garyverhaegen-da
Copy link
Contributor Author

I don't really like this approach as it seems messy both in implementation and for the user. They have to read all the way to the end of the line to find out that it overrides, and there is nothing on the 1.4 line that indicates it's not actually selected.

The more I think about it the less I believe we can get something clear without having a separate section. If you don't like the star, how about:

DAML SDK versions installed:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3
SDK version selected:
  using 0.0.0 from env var SDK_DAML_VERSION
  ignoring 1.4.0 from /full/path/to/daml.yaml
  ignoring 1.5.0 (default)

Without the env var set that would become:

DAML SDK versions installed:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3
SDK version selected:
  ignoring env var SDK_DAML_VERSION (unset)
  using 1.4.0 from /full/path/to/daml.yaml
  ignoring 1.5.0 (default)

and without a project:

DAML SDK versions installed:
  0.0.0
  1.4.0
  1.5.0-snapshot.20200811.4959.0.bbc2fe56
  1.5.0-snapshot.20200818.5027.0.1b33d374
  1.5.0-snapshot.20200902.5118.0.2b3cf1b3
SDK version selected:
  ignoring env var SDK_DAML_VERSION (unset)
  ignoring daml.yaml (not found)
  using 1.5.0 (default)

In addition to being extra clear, this also makes the various ways to set the version used discoverable.

@bame-da
Copy link
Contributor

bame-da commented Sep 14, 2020

@cocreature I did mean "Outside a project with an env variable:". I thought daml.yaml would take precedence over environment variable. My rationale for thinking that is:

  • Global Default (latest installed) is lowest specificity
  • Global override (env var) is higher specificity
  • Local override (daml.yaml) is highest specificity

I can see how the specificity could be interpreted in the opposite direction if we consider the env var a command override DAML_SDK_VERSION=0.0.0; daml ... or a terminal session override. The reason I stumbled into this in the first place was that I had set the SDK version using an export statement and then had unexpected behaviour.

@cocreature
Copy link
Contributor

The env var takes precedence over the project version atm and we do have users relying on that, e.g., they pull in finlib and want to compile it in the current version so rather than trying to patch the file, they set the env var. This behavior is also explicitly documented with exactly this usecase.

@sofiafaro-da
Copy link
Contributor

@garyverhaegen-da Could you finish merging this PR and open an issue for making the "SDK version selection process" clearer for users in daml version, as you just suggested? It feels like a promising approach but also a bit different from this PR, and more involved. This PR is already a step in the right direction.

@garyverhaegen-da garyverhaegen-da merged commit d966178 into master Sep 14, 2020
@garyverhaegen-da garyverhaegen-da deleted the show-env-version-in-daml-version branch September 14, 2020 17:31
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.

daml version doesn't show correct default SDK Version
5 participants