Skip to content

Commit 1af011a

Browse files
johnnychen94stillyslalomIanButterworthKristofferC
authored
doc: introduce temporary environment and shared environment (#2987)
Co-authored-by: Alex Ames <[email protected]> Co-authored-by: Ian Butterworth <[email protected]> Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent f00bf50 commit 1af011a

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

docs/src/environments.md

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following discusses Pkg's interaction with environments. For more on the rol
44

55
## Creating your own projects
66

7-
So far we have added packages to the default project at `~/.julia/environments/v1.0`. It is however easy to create other, independent, projects.
7+
So far we have added packages to the default project at `~/.julia/environments/v1.6`. It is however easy to create other, independent, projects.
88
It should be pointed out that when two projects use the same package at the same version, the content of this package is not duplicated.
99
In order to create a new project, create a directory for it and then activate that directory to make it the "active project", which package operations manipulate:
1010

@@ -15,32 +15,33 @@ julia> cd("MyProject")
1515
/Users/kristoffer/MyProject
1616
1717
# we can now use "." instead of a longer relative or full path:
18-
(v1.0) pkg> activate .
18+
(@v1.6) pkg> activate .
19+
Activating new environment at `/Users/kristoffer/MyProject/Project.toml`
1920
2021
(MyProject) pkg> st
21-
Status `Project.toml`
22+
Status `/Users/kristoffer/MyProject/Project.toml` (empty project)
2223
```
2324

2425
Note that the REPL prompt changed when the new project is activated. Since this is a newly created project, the status command shows that it contains no packages, and in fact, it has no project or manifest file until we add a package to it:
2526

2627
```julia-repl
2728
julia> readdir()
28-
0-element Array{String,1}
29+
String[]
2930
3031
(MyProject) pkg> add Example
31-
Updating registry at `~/.julia/registries/General`
32-
Updating git-repo `https://github.com/JuliaRegistries/General.git`
33-
Resolving package versions...
34-
Updating `Project.toml`
35-
[7876af07] + Example v0.5.1
36-
Updating `Manifest.toml`
37-
[7876af07] + Example v0.5.1
38-
[8dfed614] + Test
32+
Installing known registries into `~/.julia`
33+
Added registry `General` to `~/.julia/registries/General`
34+
Resolving package versions...
35+
Installed Example ─ v0.5.3
36+
Updating `/Users/kristoffer/MyProject/Project.toml`
37+
[7876af07] + Example v0.5.3
38+
Updating `~/Users/kristoffer/MyProject/Manifest.toml`
39+
[7876af07] + Example v0.5.3
3940
Precompiling project...
4041
1 dependency successfully precompiled in 2 seconds
4142
4243
julia> readdir()
43-
2-element Array{String,1}:
44+
2-element Vector{String}:
4445
"Manifest.toml"
4546
"Project.toml"
4647
@@ -49,18 +50,15 @@ julia> print(read("Project.toml", String))
4950
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
5051
5152
julia> print(read("Manifest.toml", String))
53+
# This file is machine-generated - editing it directly is not advised
54+
5255
[[Example]]
53-
deps = ["Test"]
54-
git-tree-sha1 = "8eb7b4d4ca487caade9ba3e85932e28ce6d6e1f8"
56+
git-tree-sha1 = "46e44e869b4d90b96bd8ed1fdcf32244fddfb6cc"
5557
uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
56-
version = "0.5.1"
57-
58-
[[Test]]
59-
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
58+
version = "0.5.3"
6059
```
6160

62-
This new environment is completely separate from the one we used earlier.
63-
61+
This new environment is completely separate from the one we used earlier. See [`Project.toml` and `Manifest.toml`](@ref Project-and-Manifest) for a more detailed explanation.
6462

6563
## Project Precompilation
6664

@@ -92,9 +90,16 @@ Precompiling project...
9290
Simply clone their project using e.g. `git clone`, `cd` to the project directory and call
9391

9492
```julia-repl
95-
(v1.0) pkg> activate .
93+
shell> git clone https://github.com/JuliaLang/Example.jl.git
94+
Cloning into 'Example.jl'...
95+
...
9696
97-
(SomeProject) pkg> instantiate
97+
(@v1.6) pkg> activate Example.jl
98+
Activating project at `~/Example.jl`
99+
100+
(Example) pkg> instantiate
101+
No Changes to `~/Example.jl/Project.toml`
102+
No Changes to `~/Example.jl/Manifest.toml`
98103
```
99104

100105
If the project contains a manifest, this will install the packages in the same state that is given by that manifest.
@@ -107,3 +112,26 @@ Otherwise, it will resolve the latest versions of the dependencies compatible wi
107112
```bash
108113
$ julia --project=. myscript.jl
109114
```
115+
116+
117+
## Temporary environments
118+
119+
Temporary environments make it easy to start an environment from a blank slate to test a package or set of
120+
packages, and have Pkg automatically delete the environment when you're done.
121+
For instance, when writing a bug report, you may want to test your minimal reproducible
122+
example in a 'clean' environment to ensure it's actually reproducible as written. You might
123+
also want a scratch space to try out a new package, or a sandbox to resolve version conflicts
124+
between several incompatible packages.
125+
126+
```julia-repl
127+
(@v1.6) pkg> activate --temp # requires Julia 1.5 or later
128+
Activating new environment at `/var/folders/34/km3mmt5930gc4pzq1d08jvjw0000gn/T/jl_a31egx/Project.toml`
129+
130+
(jl_a31egx) pkg> add Example
131+
Updating registry at `~/.julia/registries/General`
132+
Resolving package versions...
133+
Updating `/private/var/folders/34/km3mmt5930gc4pzq1d08jvjw0000gn/T/jl_a31egx/Project.toml`
134+
[7876af07] + Example v0.5.3
135+
Updating `/private/var/folders/34/km3mmt5930gc4pzq1d08jvjw0000gn/T/jl_a31egx/Manifest.toml`
136+
[7876af07] + Example v0.5.3
137+
```

0 commit comments

Comments
 (0)