Skip to content

Commit d022947

Browse files
Merge pull request #47 from modernjuliaworkflows/jmms-editing
Restructure package section
2 parents 9c248af + 4230228 commit d022947

File tree

2 files changed

+78
-34
lines changed

2 files changed

+78
-34
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ __site/
33
node_modules/
44
package-lock.json
55
.vscode
6-
Manifest.toml
6+
Manifest.toml
7+
8+
MyPackage/

pages/writing.md

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ This is made much easier by IDE integration, and here are the relevant [VSCode c
140140

141141
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.
142142
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.
144144

145145
## Notebooks
146146

@@ -179,46 +179,97 @@ julia> using Pluto
179179
julia> Pluto.run()
180180
```
181181

182-
## Packages
182+
## Environments
183183

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`.
185185
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.
187187
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
189188

189+
Pkg.jl can be used from the REPL, as seen before:
190190
```]
191-
activate MyProject
191+
activate MyPackage
192192
```
193+
or directly called in Julia mode as a package with the same commands:
193194

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.
198201

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.
200204

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`
201207
```]
202208
add Term OhMyREPL
209+
st
203210
```
204211

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":
207251

208252
When calling `using Package`, Julia determines what to load by going down the stack defined by `Base.LOAD_PATH`:
209253

210-
```julia-repl
211-
julia> Base.LOAD_PATH
254+
```>
255+
Base.LOAD_PATH
212256
```
213257

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.
216260

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.
218263

219264
["shared"]: https://pkgdocs.julialang.org/v1/environments/#Shared-environments
220265

221-
### Local packages
266+
### Environments in VSCode
267+
268+
In VSCode, if your directory contains a `Project.toml`, you will be prompted whether you want to make this the default environment.
269+
With this option set, anytime you [open a REPL](#running-code) the environment will already be the local one.
270+
<!-- How about other IDEs? -->
271+
272+
## Local packages
222273

223274
Local packages are a smart way of reusing code between projects.
224275
You could load common code directly with `include("path/to/file.jl")`, but a local package allows you to benefit from package niceties:
@@ -231,20 +282,6 @@ You could load common code directly with `include("path/to/file.jl")`, but a loc
231282
<!-- TODO: Creating, editing, and loading a new local package in a different project. -->
232283
<!-- TODO: LocalRegistry? -->
233284

234-
### Environments in VSCode
235-
236-
In VSCode, if your directory contains a `Project.toml`, you will be prompted whether you want to make this the default environment.
237-
With this option set, anytime you [open a REPL](#running-code) the environment will already be the local one.
238-
239-
<!-- How about other IDEs? -->
240-
241-
* [Pkg.jl](https://github.com/JuliaLang/Pkg.jl)
242-
* [Revise.jl](https://github.com/timholy/Revise.jl)
243-
* stacking environments
244-
* [PkgDependency.jl](https://github.com/peng1999/PkgDependency.jl)
245-
* [environments in VSCode](https://www.julia-vscode.org/docs/stable/userguide/env/)
246-
* Local packages
247-
248285
## Configuration
249286

250287
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
295332
* [cheatsheet](https://cheatsheet.juliadocs.org/)
296333
* [help](https://julialang.org/about/help/)
297334
* [community](https://julialang.org/community/)
335+
336+
```julia
337+
#hideall
338+
run(`rm -fr MyPackage`)
339+
```

0 commit comments

Comments
 (0)