Zulip Chat Archive

Stream: general

Topic: Correct way to add package


Ioannis Konstantoulas (Oct 01 2023 at 07:59):

Say I have created a non-math project with lake new project. Then I want to add Std as a dependency to project. What is the correct way to do it? import Std does not automatically install Std in the project directory, so I am assuming either

  1. I have to invoke a lake command, or

  2. to manually create a lake_packages folder, clone Std in there, and somehow pin the downloaded version to the project?

Of course, I would hope for (1).

Rémy Degenne (Oct 01 2023 at 08:05):

You need to edit the lakefile.lean file of your project to add

require std from git
  "https://github.com/leanprover/std4"

as explained here: https://github.com/leanprover/lake#adding-dependencies

Damiano Testa (Oct 01 2023 at 08:05):

Mathlib has several lines like

require std from git "https://github.com/leanprover/std4" @ "main"

in its lakefile.lean. Does adding the above works?

Rémy Degenne (Oct 01 2023 at 08:07):

I don't know if the @ "main" is required, but if mathlib uses it you probably should as well?

Damiano Testa (Oct 01 2023 at 08:08):

I think that someone recently said that the default branch with git is master and lake does weird things if main is the "main" branch, like in Std. But I am not really sure...

Damiano Testa (Oct 01 2023 at 08:09):

Here is the link to the comment: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Updating.20using.20lake.20again/near/393881597

Ioannis Konstantoulas (Oct 01 2023 at 08:11):

The above fails with

`/home/admin/.elan/toolchains/leanprover--lean4---nightly/bin/lake print-paths Init` failed:

stderr:
error: missing manifest; use `lake update` to generate one
Invalid Lake configuration.  Please restart the server after fixing the Lake configuration file.

Performing lake update gave me the warning:

warning: mwe_bare: package 'std' was required as 'std4'

I wonder what happens if Std is updated in github; do I keep getting the new versions?

Rémy Degenne (Oct 01 2023 at 08:12):

It looks like the correct name is std, not std4 as I incorrectly wrote in the code above (which I just edited to fix that)

Rémy Degenne (Oct 01 2023 at 08:16):

You don't get new versions automatically. To update your dependencies you need to run lake update.

Rémy Degenne (Oct 01 2023 at 08:17):

But be warned that if you run lake update and the lean version used by std got ahead of the lean version you have in your lean-toolchain file, it will break everything

Mario Carneiro (Oct 01 2023 at 08:29):

I recommend you always use the @ branch part in a require. The current lake behavior is subtly wrong and you don't want to have to think about that

Kevin Buzzard (Oct 01 2023 at 08:31):

This makes the updating process much harder though because then my students have to manually edit the lake file yet again to update the dependency

Mario Carneiro (Oct 01 2023 at 08:32):

what do you mean?

Ioannis Konstantoulas (Oct 01 2023 at 08:32):

Rémy Degenne said:

But be warned that if you run lake update and the lean version used by std got ahead of the lean version you have in your lean-toolchain file, it will break everything

Can we roll back updates?

Mario Carneiro (Oct 01 2023 at 08:32):

git...

Kevin Buzzard (Oct 01 2023 at 08:33):

If my students have a specific commit mentioned in a config file then they have to manually update the commit. If they just have "master" then they don't

Rémy Degenne (Oct 01 2023 at 08:33):

I put all my projects on github and if I manage to break really everything, I just delete the folder and clone again

Mario Carneiro (Oct 01 2023 at 08:33):

the only permanent thing that lake update changes is lake-manifest.json. If you restore that and run lake build again you should be back to square one

Mario Carneiro (Oct 01 2023 at 08:34):

Kevin Buzzard said:

If my students have a specific commit mentioned in a config file then they have to manually update the commit. If they just have "master" then they don't

I don't mean you should put a specific commit there, but you should put a branch name

Mario Carneiro (Oct 01 2023 at 08:34):

don't just leave it default

Mario Carneiro (Oct 01 2023 at 08:35):

because the default is master which does not match what github thinks the default is


Last updated: Dec 20 2023 at 11:08 UTC