CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/lean/global-packages.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Initialize the ~/.lean directory if it doesn't already exist.
8
9
Right now we "install", i.e., make a pointer to a global copy
10
of mathlib if there is one.
11
12
We might install more later.
13
14
NOTE: Rob Lewis suggested this and also tested installing other things
15
later (e.g., a new mathlib) and says it works: "Okay, I think you're
16
safe with this setup. Run leanpkg install /ext/... in/below ~.
17
If someone creates a Lean project anywhere in ~, the new leanpkg.path
18
seems to override the global install. This happens whether or not
19
mathlib is added to the project with leanpkg add. The global install
20
is unavailable in the project as soon as the project is created."
21
22
See https://github.com/sagemathinc/cocalc/issues/4393.
23
*/
24
25
import { executeCode } from "@cocalc/backend/execute-code";
26
27
export async function init_global_packages(): Promise<void> {
28
const command = `[ ! -d "${process.env.HOME}/.lean" ] && [ -d /ext/lean/lean/mathlib ] && leanpkg install /ext/lean/lean/mathlib`;
29
// err_on_exit = false because nonzero exit code whenever we don't run the install, which is fine.
30
await executeCode({ command, bash: true, err_on_exit: false });
31
}
32
33