You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/writing.md
+75-33Lines changed: 75 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,7 @@ This is made much easier by IDE integration, and here are the relevant [VSCode c
140
140
141
141
When keeping the same REPL open for a long time, it's common to end up with a "polluted" workspace where the definitions of certain variables or functions have been overwritten in unexpected ways.
142
142
This, along with other events like `struct` redefinitions, might force you to restart your REPL now and again.
143
-
One way to help with workspace tidiness is to take advantage of the [module system](#Packages) to separate the reusable parts of your code from the one-off parts that are only relevant for a certain script.
143
+
One way to help with workspace tidiness is to take advantage of the [module system](#local_packages) to separate the reusable parts of your code from the one-off parts that are only relevant for a certain script.
144
144
145
145
## Notebooks
146
146
@@ -179,46 +179,97 @@ julia> using Pluto
179
179
julia> Pluto.run()
180
180
```
181
181
182
-
## Packages
182
+
## Environments
183
183
184
-
> TLDR: Pkg.jl lets you `activate` independent, reproducible environments to `add` and `remove` project-specific (versions of) packages.
184
+
> TLDR: Julia projects are made with `] activate`, and their details are stored in the `Project.toml` and `Manifest.toml`.
185
185
186
-
Pkg.jl and the Pkg mode built in to the [REPL](#REPL) let you install packages and manage environments.
186
+
Pkg.jl and the [Pkg mode](#package-mode) built in to the [REPL](#repl) let you install packages and manage environments.
187
187
A "package" is a structured way of reusing code between projects and the active "environment" is responsible for determining which versions of packages to load.
188
-
When working on a project, you can create a new environment or switch to an existing one by running
189
188
189
+
Pkg.jl can be used from the REPL, as seen before:
190
190
```]
191
-
activate MyProject
191
+
activate MyPackage
192
192
```
193
+
or directly called in Julia mode as a package with the same commands:
193
194
194
-
or, from the command line, running `julia` with the [startup flag](#Configuration)`--project MyProject`.
195
-
After this, packages you install will be listed in the `Project.toml` file, which gives an overview of the project, as well as its low-level `Manifest.toml` cousin, which contains a detailed snapshot of packages and their dependencies.
196
-
Sharing a project between computers is as simple as sending a folder containing your code as well as the `Project.toml` and `Manifest.toml`.
197
-
With these files, the user can run `instantiate` in package mode and Julia can perfectly recreate the state of packages in the local environment.
195
+
```>
196
+
using Pkg
197
+
Pkg.activate("MyPackage")
198
+
```
199
+
200
+
The `activate` command used above can be used to activate an existing project or create a new one and then activate it.
198
201
199
-
To add packages you can use the `add` command followed by any number of packages:
202
+
You can also run `julia` from the command line with the [startup flag](#configuration)`--project MyProject` (which is what the [VSCode plugin](#environments_in_vscode) does).
203
+
After this, packages you install will be listed in the `Project.toml` and `Manifest.toml` files.
200
204
205
+
The `Project.toml` contains information both about the project e.g name, uuid, authors, and its dependencies.
206
+
Its dependency-related content is visible with `]status` or just `]st`
201
207
```]
202
208
add Term OhMyREPL
209
+
st
203
210
```
204
211
205
-
If you haven't `activate`d a local project, these packages will be installed in the "global environment" whose name in Pkg mode's prompt is `@v1.X`[^1], corresponding to the version of Julia currently active.
206
-
Packages installed globally are available no matter which local environment is active due to what's referred to as "environment stacking".
212
+
As dependencies often have their own dependencies, potential version conflicts must be resolved for an environment to be usable.
213
+
The resolution is done automatically on package installation with `]add `, environment instantiation with `]instantiate`, and with the `]resolve` command.
214
+
The output of this resolution is stored in the `Manifest.toml`.
215
+
<!-- , whose contents can be nicely visualised using [PkgDependency.jl](https://github.com/peng1999/PkgDependency.jl) -->
216
+
217
+
<!-- ```julia-repl
218
+
julia> using PkgDependency
219
+
julia> PkgDependency.tree("CSV")
220
+
CSV v0.10.4
221
+
━━━━━━━━━━━━━
222
+
│
223
+
├── InlineStrings v1.1.4
224
+
│ └── Parsers v2.3.2
225
+
├── PooledArrays v1.4.2
226
+
│ └── DataAPI v1.10.0
227
+
├── WeakRefStrings v1.4.2
228
+
│ ├── DataAPI v1.10.0 (*)
229
+
│ ├── InlineStrings v1.1.4 (*)
230
+
│ └── Parsers v2.3.2 (*)
231
+
├── CodecZlib v0.7.0
232
+
│ └── TranscodingStreams v0.9.8
233
+
├── Tables v1.7.0
234
+
│ ├── DataAPI v1.10.0 (*)
235
+
│ ├── OrderedCollections v1.4.1
236
+
│ ├── IteratorInterfaceExtensions v1.0.0
237
+
│ ├── DataValueInterfaces v1.0.0
238
+
│ └── TableTraits v1.0.1
239
+
│ └── IteratorInterfaceExtensions v1.0.0 (*)
240
+
├── FilePathsBase v0.9.19
241
+
│ └── Compat v4.2.0
242
+
├── Parsers v2.3.2 (*)
243
+
└── SentinelArrays v1.3.13
244
+
``` -->
245
+
246
+
Sharing a project between computers is as simple as sending a folder containing your code as well as the `Project.toml` and `Manifest.toml`.
247
+
With these files, the user can run `]instantiate` and Julia will perfectly[^1] recreate the state of packages in the local environment.
248
+
249
+
If you haven't `activate`d a local project, packages that you `add` will be installed in the "global environment" called `@v1.X`[^2] after the active version of Julia.
250
+
Packages installed globally are available no matter which local environment is active because of "environment stacking":
207
251
208
252
When calling `using Package`, Julia determines what to load by going down the stack defined by `Base.LOAD_PATH`:
209
253
210
-
```julia-repl
211
-
julia> Base.LOAD_PATH
254
+
```>
255
+
Base.LOAD_PATH
212
256
```
213
257
214
-
The search begins at the local environment `@`, then the global environment `@v1.X`, and finally the standard library `@stdlib` that comes pre-installed with Julia.
215
-
The two most important implications of this are firstly that development tools can be installed globally and [loaded on startup](#Configuration) to be available to use, and secondly that packages in the standard library can be updated or fixed independently of the version of Julia you are using.
258
+
The search begins at the local environment `@`, then the global environment `@v#.#`, and finally the standard library `@stdlib` that comes pre-installed with Julia.
259
+
The two most important implications of this are firstly that development tools can be installed globally and [loaded on startup](#configuration) to be available to use, and secondly that packages in the standard library can be updated or fixed independently of the version of Julia you are using.
216
260
217
-
[^1]: The `@` before the name means that the environment is ["shared"], which means you can `activate` shared environments with the `--shared` flag and it is located in `~/.julia/environments`. Notably it does _not_ imply that it is part of the environment stack.
261
+
[^1]: Unless the `develop` command is used, which causes the project's dependencies to be stateful.
262
+
[^2]: The `@` before the name means that the environment is ["shared"], which means you can `activate` shared environments with the `--shared` flag and it is located in `~/.julia/environments`. Notably it does _not_ imply that it is part of the environment stack.
*[environments in VSCode](https://www.julia-vscode.org/docs/stable/userguide/env/)
246
-
* Local packages
247
-
248
285
## Configuration
249
286
250
287
Julia accepts [startup flags](https://docs.julialang.org/en/v1/manual/command-line-interface/#command-line-interface) to handle settings such as the number of threads available.
@@ -295,3 +332,8 @@ More generally, the startup file allows you to define your own favorite helper f
0 commit comments