Skip to content

Commit

Permalink
use non Pkg for workflow (#30194)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Dec 11, 2018
1 parent 2bbb5fc commit 560e829
Showing 1 changed file with 45 additions and 61 deletions.
106 changes: 45 additions & 61 deletions doc/src/manual/workflow-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,59 @@ As already elaborated in [The Julia REPL](@ref), Julia's REPL provides rich func
that facilitates an efficient interactive workflow. Here are some tips that might further enhance
your experience at the command line.

## Command-line-based basic editor/REPL workflow
### A basic editor/REPL workflow

The most basic Julia workflows involve using a text editor in conjunction with the `julia` command
line. A common pattern includes the following elements:

* **Generate a new project**

```
$ julia -e 'using Pkg;Pkg.generate("Tmp")'
Generating project Tmp:
Tmp/Project.toml
Tmp/src/Tmp.jl
$ ls -R Tmp
Tmp:
Project.toml src
Tmp/src:
Tmp.jl
$ cat -n Tmp/src/Tmp.jl
1 module Tmp
2
3 greet() = print("Hello World!")
4
5 end # module
```

* **Create a test folder**
```
$ mkdir Tmp/test
```
* **Put your test code in `test/runtests.jl` file.**
* **Put code under development in a temporary module.** Create a file, say `Tmp.jl`, and include
within it

```julia
module Tmp
export say_hello

say_hello() = println("Hello!")

# your other definitions here

end
```
$ cat -n Tmp/test/runtests.jl
1 using Tmp
2 Tmp.greet()
* **Put your test code in another file.** Create another file, say `tst.jl`, which looks like

```julia
include("Tmp.jl")
import .Tmp
# using .Tmp # we can use `using` to bring the exported symbols in `Tmp` into our namespace
Tmp.say_hello()
# say_hello()
# your other test code here
```

* **Run test**
```
$ julia -e 'using Pkg;Pkg.activate("Tmp");Pkg.test()'
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Updating `~/Tmp/Project.toml`
[no changes]
Testing Tmp
Resolving package versions...
Hello World! Testing Tmp tests passed
```
* **Lather. Rinse. Repeat.** Explore ideas at the `julia` command prompt. Save good ideas in `Tmp.jl` and test with `runtests.jl`.

## Simplify initialization

To simplify restarting the REPL, put project-specific initialization code in a file, say `_init.jl`,
which you can run on startup by issuing the command:

```
julia -L _init.jl
```

If you further add the following to your `~/.julia/config/startup.jl` file

```julia
isfile("_init.jl") && include(joinpath(pwd(), "_init.jl"))
```

then calling `julia` from that directory will run the initialization code without the additional
command line argument.
and includes tests for the contents of `Tmp`.
Alternatively, you can wrap the contents of your test file in a module, as

```julia
module Tst
include("Tmp.jl")
import .Tmp
#using .Tmp
Tmp.say_hello()
# say_hello()
# your other test code here
end
```

The advantage is that your testing code is now contained in a module and does not use the global scope in `Main` for
definitions, which is a bit more tidy.

* `include` the `tst.jl` file in the Julia REPL with `include("tst.jl")`.

* **Lather. Rinse. Repeat.** Explore ideas at the `julia` command prompt. Save good ideas in `tst.jl`. To execute `tst.jl` after it has been changed, just `include` it again.

## Browser-based workflow

Expand Down

0 comments on commit 560e829

Please sign in to comment.