Skip to content

Commit 560e829

Browse files
authored
use non Pkg for workflow (#30194)
1 parent 2bbb5fc commit 560e829

File tree

1 file changed

+45
-61
lines changed

1 file changed

+45
-61
lines changed

doc/src/manual/workflow-tips.md

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,59 @@ As already elaborated in [The Julia REPL](@ref), Julia's REPL provides rich func
88
that facilitates an efficient interactive workflow. Here are some tips that might further enhance
99
your experience at the command line.
1010

11-
## Command-line-based basic editor/REPL workflow
11+
### A basic editor/REPL workflow
1212

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

16-
* **Generate a new project**
17-
18-
```
19-
$ julia -e 'using Pkg;Pkg.generate("Tmp")'
20-
Generating project Tmp:
21-
Tmp/Project.toml
22-
Tmp/src/Tmp.jl
23-
$ ls -R Tmp
24-
Tmp:
25-
Project.toml src
26-
27-
Tmp/src:
28-
Tmp.jl
29-
$ cat -n Tmp/src/Tmp.jl
30-
1 module Tmp
31-
2
32-
3 greet() = print("Hello World!")
33-
4
34-
5 end # module
35-
```
36-
37-
* **Create a test folder**
38-
```
39-
$ mkdir Tmp/test
40-
```
41-
* **Put your test code in `test/runtests.jl` file.**
16+
* **Put code under development in a temporary module.** Create a file, say `Tmp.jl`, and include
17+
within it
4218

19+
```julia
20+
module Tmp
21+
export say_hello
22+
23+
say_hello() = println("Hello!")
24+
25+
# your other definitions here
26+
27+
end
4328
```
44-
$ cat -n Tmp/test/runtests.jl
45-
1 using Tmp
46-
2 Tmp.greet()
29+
* **Put your test code in another file.** Create another file, say `tst.jl`, which looks like
30+
31+
```julia
32+
include("Tmp.jl")
33+
import .Tmp
34+
# using .Tmp # we can use `using` to bring the exported symbols in `Tmp` into our namespace
35+
36+
Tmp.say_hello()
37+
# say_hello()
38+
39+
# your other test code here
4740
```
4841

49-
* **Run test**
50-
```
51-
$ julia -e 'using Pkg;Pkg.activate("Tmp");Pkg.test()'
52-
Updating registry at `~/.julia/registries/General`
53-
Updating git-repo `https://github.com/JuliaRegistries/General.git`
54-
Resolving package versions...
55-
Updating `~/Tmp/Project.toml`
56-
[no changes]
57-
Testing Tmp
58-
Resolving package versions...
59-
Hello World! Testing Tmp tests passed
60-
```
61-
* **Lather. Rinse. Repeat.** Explore ideas at the `julia` command prompt. Save good ideas in `Tmp.jl` and test with `runtests.jl`.
62-
63-
## Simplify initialization
64-
65-
To simplify restarting the REPL, put project-specific initialization code in a file, say `_init.jl`,
66-
which you can run on startup by issuing the command:
67-
68-
```
69-
julia -L _init.jl
70-
```
71-
72-
If you further add the following to your `~/.julia/config/startup.jl` file
73-
74-
```julia
75-
isfile("_init.jl") && include(joinpath(pwd(), "_init.jl"))
76-
```
77-
78-
then calling `julia` from that directory will run the initialization code without the additional
79-
command line argument.
42+
and includes tests for the contents of `Tmp`.
43+
Alternatively, you can wrap the contents of your test file in a module, as
44+
45+
```julia
46+
module Tst
47+
include("Tmp.jl")
48+
import .Tmp
49+
#using .Tmp
50+
51+
Tmp.say_hello()
52+
# say_hello()
53+
54+
# your other test code here
55+
end
56+
```
57+
58+
The advantage is that your testing code is now contained in a module and does not use the global scope in `Main` for
59+
definitions, which is a bit more tidy.
60+
61+
* `include` the `tst.jl` file in the Julia REPL with `include("tst.jl")`.
62+
63+
* **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.
8064

8165
## Browser-based workflow
8266

0 commit comments

Comments
 (0)