Skip to content

Commit

Permalink
[create-pull-request] automated change
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastyBlacksmith authored Aug 17, 2023
1 parent f201cc7 commit 61f6efc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 99 deletions.
97 changes: 1 addition & 96 deletions episodes/04_Using_the_package_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,102 +76,7 @@ To create a new environment she uses the `activate` function of the package mana


````output
Activating project at `~/projects/julia-trebuchet/output/carpentries/projects/trebuchet`
````

In this environment she adds the `Trebuchet` package from its
open source code [repository on GitHub](https://github.com/FluxML/Trebuchet.jl) by typing

```julia
(trebuchet) pkg> add Trebuchet
```

Melissa quickly recognizes that far more packages are being installed than just
`Trebuchet`.
These are the dependencies of `Trebuchet`.
From the output

```output
[...]
Updating `[...]/projects/trebuchet/Project.toml`
[98b73d46] + Trebuchet v0.2.1
Updating `[...]/projects/trebuchet/Manifest.toml`
[1520ce14] + AbstractTrees v0.3.3
[79e6a3ab] + Adapt v1.1.0
[...]
```

she sees that two files were created: `Project.toml` and `Manifest.toml`.

The project file `Project.toml` only contains the packages needed for her
project, while the manifest file `Manifest.toml` records the direct and
indirect dependencies as well as their current version, thus providing a fully
reproducible record of the code that is actually executed.
"That is really handy when I want to share my work with the others," thinks
Melissa.

After the installation finished she can check the packages present in her
environment.

```julia
(trebuchet) pkg> status
```


````output
Status `~/projects/julia-trebuchet/output/carpentries/projects/trebuchet/Project.toml`
[f6369f11] ForwardDiff v0.10.35
[295af30f] Revise v3.5.3
[98b73d46] Trebuchet v0.2.2
````

Melissa can get back to the global environment using `activate` without any parameters.

:::::: callout

## Why use GitHub?

Melissa could have added the GitHub version of Trebuchet.jl by typing

```julia
(trebuchet) pkg> add Trebuchet#master
```

In this case the JuliaHub version is the same as the GitHub version,
so Melissa does not need to specify the installation.

If you know a package is stable, go ahead and install the default version registered on JuliaHub.
Otherwise, it’s good to check how different that version is from the current state of the software project.
Click through the link under “Repository” on the JuliaHub package page.

::::::

## Using and importing packages

Now that Melissa added the package to her environment, she needs to load it.
Julia provides two keywords for loading packages: `using` and `import`.

The difference is that `import` brings only the name of the package into the
namespace and then all functions in that package need the name in front
(prefixed).
But packages can define a list of function names to export, which means the
functions should be brought into the user's namespace when he loads the package
with `using`.
This makes working at the REPL more convenient.

### Name conflicts

It may happen that name conflicts arise.
For example Melissa defined a structure named `Trebuchet`, but the package she
added to the environment is also named `Trebuchet`.
Now she would get an error if she tried to `import`/`using` it directly.
One solution is to assign a nickname or alias to the package upon `import`
using the keyword *`as`*:

````julia
import Trebuchet as Trebuchets
Activating project at `~/projects/trebuchet`
````

:::::: keypoints
Expand Down
2 changes: 1 addition & 1 deletion episodes/05_Write_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Pkg.instantiate()
````

````output
Activating project at `~/projects/julia-trebuchet/output/carpentries/projects/trebuchet`
Activating project at `~/projects/trebuchet`
````

Expand Down
2 changes: 1 addition & 1 deletion episodes/06_Control_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Pkg.instantiate()
````

````output
Activating project at `~/projects/julia-trebuchet/output/carpentries/projects/trebuchet`
Activating project at `~/projects/trebuchet`
````

Expand Down
2 changes: 1 addition & 1 deletion episodes/09_Adding_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end
````

````output
Test.DefaultTestSet("Test arithmetic equalities", Any[], 1, false, false, true, 1.691580564130388e9, 1.691580564159508e9, false)
Test.DefaultTestSet("Test arithmetic equalities", Any[], 1, false, false, true, 1.69228090489711e9, 1.69228090493599e9, false)
````

With this Melissa can run her test using the pkg mode of the REPL:
Expand Down

0 comments on commit 61f6efc

Please sign in to comment.