Skip to content

Commit 37c58ec

Browse files
authored
Page2 for real (#62)
* Start page 2 for real * Fix highlighting * Stuff
1 parent 4956eb4 commit 37c58ec

File tree

5 files changed

+192
-19
lines changed

5 files changed

+192
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ package-lock.json
88

99
MyProject/
1010
MyPackage/
11-
MyOtherPackage/
11+
MyOtherPackage/
12+
MyAwesomePackage/

Manifest.toml

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.9.3"
44
manifest_format = "2.0"
5-
project_hash = "324c5be59c7217520d3ed414411ba27086fc91a9"
5+
project_hash = "0678b1d9e0095e72c65dc80d36b74ee7dc2c5c4f"
66

77
[[deps.ANSIColoredPrinters]]
88
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
@@ -39,6 +39,21 @@ git-tree-sha1 = "02aa26a4cf76381be7f66e020a3eddeb27b0a092"
3939
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
4040
version = "0.7.2"
4141

42+
[[deps.Compat]]
43+
deps = ["UUIDs"]
44+
git-tree-sha1 = "e460f044ca8b99be31d35fe54fc33a5c33dd8ed7"
45+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
46+
version = "4.9.0"
47+
weakdeps = ["Dates", "LinearAlgebra"]
48+
49+
[deps.Compat.extensions]
50+
CompatLinearAlgebraExt = "LinearAlgebra"
51+
52+
[[deps.CompilerSupportLibraries_jll]]
53+
deps = ["Artifacts", "Libdl"]
54+
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
55+
version = "1.0.5+0"
56+
4257
[[deps.ConcurrentUtilities]]
4358
deps = ["Serialization", "Sockets"]
4459
git-tree-sha1 = "5372dbbf8f0bdb8c700db5367132925c0771ef7e"
@@ -50,6 +65,16 @@ git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
5065
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
5166
version = "4.1.1"
5267

68+
[[deps.DataAPI]]
69+
git-tree-sha1 = "8da84edb865b0b5b0100c0666a9bc9a0b71c553c"
70+
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
71+
version = "1.15.0"
72+
73+
[[deps.DataValueInterfaces]]
74+
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
75+
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
76+
version = "1.0.0"
77+
5378
[[deps.Dates]]
5479
deps = ["Printf"]
5580
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -77,6 +102,11 @@ git-tree-sha1 = "e90caa41f5a86296e014e148ee061bd6c3edec96"
77102
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
78103
version = "0.1.9"
79104

105+
[[deps.ExprTools]]
106+
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"
107+
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
108+
version = "0.1.10"
109+
80110
[[deps.FileWatching]]
81111
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
82112

@@ -114,6 +144,11 @@ version = "1.6.4"
114144
deps = ["Markdown"]
115145
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
116146

147+
[[deps.IteratorInterfaceExtensions]]
148+
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
149+
uuid = "82899510-4779-5014-852e-03e436cf321d"
150+
version = "1.0.0"
151+
117152
[[deps.JLLWrappers]]
118153
deps = ["Artifacts", "Preferences"]
119154
git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca"
@@ -148,6 +183,10 @@ version = "1.10.2+0"
148183
[[deps.Libdl]]
149184
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
150185

186+
[[deps.LinearAlgebra]]
187+
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
188+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
189+
151190
[[deps.LiveServer]]
152191
deps = ["HTTP", "LoggingExtras", "MIMEs", "Pkg", "Sockets", "Test"]
153192
git-tree-sha1 = "24d05efe53436b22a42bf2ae459f47c48b0c2603"
@@ -183,10 +222,22 @@ deps = ["Artifacts", "Libdl"]
183222
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
184223
version = "2.28.2+0"
185224

225+
[[deps.Mocking]]
226+
deps = ["Compat", "ExprTools"]
227+
git-tree-sha1 = "4cc0c5a83933648b615c36c2b956d94fda70641e"
228+
uuid = "78c3b35d-d492-501b-9361-3d52fe80e533"
229+
version = "0.7.7"
230+
186231
[[deps.MozillaCACerts_jll]]
187232
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
188233
version = "2022.10.11"
189234

235+
[[deps.Mustache]]
236+
deps = ["Printf", "Tables"]
237+
git-tree-sha1 = "821e918c170ead5298ff84bffee41dd28929a681"
238+
uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
239+
version = "1.0.17"
240+
190241
[[deps.NetworkOptions]]
191242
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
192243
version = "1.2.0"
@@ -197,6 +248,11 @@ git-tree-sha1 = "bf1f49fd62754064bc42490a8ddc2aa3694a8e7a"
197248
uuid = "2bd173c7-0d6d-553b-b6af-13a54713934c"
198249
version = "2.0.0"
199250

251+
[[deps.OpenBLAS_jll]]
252+
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
253+
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
254+
version = "0.3.21+4"
255+
200256
[[deps.OpenSSL]]
201257
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"]
202258
git-tree-sha1 = "51901a49222b09e3743c65b8847687ae5fc78eb2"
@@ -214,11 +270,23 @@ git-tree-sha1 = "2e73fe17cac3c62ad1aebe70d44c963c3cfdc3e3"
214270
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
215271
version = "1.6.2"
216272

273+
[[deps.Parameters]]
274+
deps = ["OrderedCollections", "UnPack"]
275+
git-tree-sha1 = "34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe"
276+
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
277+
version = "0.12.3"
278+
217279
[[deps.Pkg]]
218280
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
219281
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
220282
version = "1.9.2"
221283

284+
[[deps.PkgTemplates]]
285+
deps = ["Dates", "InteractiveUtils", "LibGit2", "Mocking", "Mustache", "Parameters", "Pkg", "REPL", "UUIDs"]
286+
git-tree-sha1 = "693ad322c84159a1f1f875891115423695fc08e8"
287+
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
288+
version = "0.7.45"
289+
222290
[[deps.PrecompileTools]]
223291
deps = ["Preferences"]
224292
git-tree-sha1 = "03b4c25b43cb84cee5c90aa9b5ea0a78fd848d2f"
@@ -268,6 +336,18 @@ deps = ["Dates"]
268336
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
269337
version = "1.0.3"
270338

339+
[[deps.TableTraits]]
340+
deps = ["IteratorInterfaceExtensions"]
341+
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
342+
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
343+
version = "1.0.1"
344+
345+
[[deps.Tables]]
346+
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits", "Test"]
347+
git-tree-sha1 = "1544b926975372da01227b382066ab70e574a3ec"
348+
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
349+
version = "1.10.1"
350+
271351
[[deps.Tar]]
272352
deps = ["ArgTools", "SHA"]
273353
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
@@ -292,6 +372,11 @@ version = "1.5.0"
292372
deps = ["Random", "SHA"]
293373
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
294374

375+
[[deps.UnPack]]
376+
git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b"
377+
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
378+
version = "1.0.2"
379+
295380
[[deps.Unicode]]
296381
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
297382

@@ -308,6 +393,11 @@ deps = ["Libdl"]
308393
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
309394
version = "1.2.13+0"
310395

396+
[[deps.libblastrampoline_jll]]
397+
deps = ["Artifacts", "Libdl"]
398+
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
399+
version = "5.8.0+0"
400+
311401
[[deps.nghttp2_jll]]
312402
deps = ["Artifacts", "Libdl"]
313403
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438"
33
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
44
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
55
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
6+
PkgTemplates = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
67
Xranklin = "558449b0-171e-4e1f-900f-d076a5ddf486"

pages/sharing.md

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,116 @@
22

33
# Sharing your code
44

5+
In this post, you will learn about tools to initialize, structure and distribute Julia packages.
6+
57
\toc
68

79
## Setup
810

9-
* GitHub and GitHub actions
10-
* [PkgTemplates.jl](https://github.com/JuliaCI/PkgTemplates.jl)
11+
A vast majority of Julia packages are hosted on [GitHub](https://github.com/) (although less common, other options like [GitLab](https://gitlab.com/) are also possible).
12+
GitHub is a platform for collaborative software development, based on the version control system [Git](https://git-scm.com/).
13+
If you are unfamiliar with these technologies, check out the [GitHub documentation](https://docs.github.com/en/get-started/quickstart).
1114

12-
## Code quality
15+
The first step is therefore [creating](https://github.com/new) an empty GitHub repository.
16+
You should try to follow [package naming guidelines](https://pkgdocs.julialang.org/v1/creating-packages/#Package-naming-guidelines) and add a ".jl" extension at the end, like so: "MyAwesomePackage.jl".
17+
Do not insert any files like `README.md`, `.gitignore` or `LICENSE.md`, this will be done for you in the next step.
1318

14-
* style guides ([BlueStyle](https://github.com/invenia/BlueStyle), [SciMLStyle](https://github.com/SciML/SciMLStyle))
15-
* [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl)
16-
* [formatting in VSCode](https://www.julia-vscode.org/docs/stable/userguide/formatter/)
17-
* [Aqua.jl](https://github.com/JuliaTesting/Aqua.jl)
19+
Indeed, we can leverage [PkgTemplates.jl](https://github.com/JuliaCI/PkgTemplates.jl) to automate package creation (like `]generate` from Pkg.jl but on steroids).
20+
The following code gives you a basic file structure to start with:
21+
22+
```>pkgtemplates
23+
using PkgTemplates
24+
t = Template(dir=".", user="myusername")
25+
!isdir("MyAwesomePackage") ? t("MyAwesomePackage") : nothing
26+
```
27+
28+
Then, you simply need to push this new folder to the remote repository <https://github.com/myusername/MyAwesomePackage.jl>, and you're ready to go.
29+
The rest of this post will explain to you what each part of this folder does, and how to bend them to your will.
30+
In particular, once you're done here, you will be able to run
31+
32+
```julia-repl
33+
julia> t = Template(dir=".", user="myusername", interactive=true)
34+
```
35+
36+
and answer each interactive prompt confidently without freaking out.
1837

1938
## Testing
2039

21-
* [unit testing](https://docs.julialang.org/en/v1/stdlib/Test/)
22-
* [TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl)
23-
* [TestItemRunner.jl](https://github.com/julia-vscode/TestItemRunner.jl)
24-
* [ReTest.jl](https://github.com/JuliaTesting/ReTest.jl)
25-
* [ReferenceTests.jl](https://github.com/JuliaTesting/ReferenceTests.jl)
40+
Take a look at the folder `MyAwesomePackage`.
41+
You already know that the `src` subfolder contains your source code, but you might wonder what the `test` subfolder is for.
42+
Its purpose is [unit testing](https://docs.julialang.org/en/v1/stdlib/Test/): automatically checking that your code behaves the way you want it to.
43+
For instance, if you write your own square root function, you may want to test that it gives the correct results for positive numbers, and errors for negative numbers.
44+
These tests belong in `test/runtests.jl`, and they may look somewhat like this:
45+
46+
```>sqrt
47+
using Test
48+
49+
@test sqrt(4) ≈ 2
50+
51+
@testset "Invalid inputs" begin
52+
@test_throws DomainError sqrt(-1)
53+
@test_throws MethodError sqrt("abc")
54+
end
55+
```
56+
57+
Unit testing may seem rather naive, or even superfluous, but as your code grows more complex, it becomes easier to break something without noticing.
58+
Testing each part separately will increase the reliability of the software you write.
59+
60+
If your package requires [test-specific dependencies](https://pkgdocs.julialang.org/v1/creating-packages/#Adding-tests-to-the-package), you can use [TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl) to activate the test environment with all necessary packages.
61+
62+
We list a few advanced testing utilities:
63+
64+
* [ReferenceTests.jl](https://github.com/JuliaTesting/ReferenceTests.jl) allows you to compare function outputs with reference files
65+
* [ReTest.jl](https://github.com/JuliaTesting/ReTest.jl) lets you define tests next to the source code, and control their execution more precisely
66+
* [TestItemRunner.jl](https://github.com/julia-vscode/TestItemRunner.jl) leverages the testing interface of VSCode
67+
68+
## Style
69+
70+
To make your code easy to read, it is essential to follow a consistent set of guidelines.
71+
The official [style guide](https://docs.julialang.org/en/v1/manual/style-guide/) is very short, so most people use third party style guides like [BlueStyle](https://github.com/invenia/BlueStyle) or [SciMLStyle](https://github.com/SciML/SciMLStyle).
72+
73+
[JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) is an automated formatter for Julia files.
74+
It can help you enforce the style guide of your choice if you add a file `.JuliaFormatter.toml` at the root of your repository, containing a single line like
75+
76+
```toml
77+
style = "blue"
78+
```
79+
80+
Then, the current directory will be formatted in the BlueStyle whenever you call
81+
82+
```julia-repl
83+
julia> using JuliaFormatter
84+
85+
julia> format(".");
86+
```
87+
88+
This functionality is even [integrated with VSCode](https://www.julia-vscode.org/docs/stable/userguide/formatter/).
89+
90+
## Code quality
91+
92+
* [Aqua.jl](https://github.com/JuliaTesting/Aqua.jl)
93+
* [JET.jl](https://github.com/aviatesk/JET.jl)
2694

2795
## Documentation
2896

2997
* [docstrings](https://docs.julialang.org/en/v1/manual/documentation/)
3098
* [DocStringExtensions.jl](https://github.com/JuliaDocs/DocStringExtensions.jl)
3199
* [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl)
32100
* [LiveServer.jl](https://github.com/tlienart/LiveServer.jl)
33-
* [Replay.jl](https://github.com/rafaqz/Interfaces.jl)
101+
* [Pollen.jl](https://github.com/lorenzoh/Pollen.jl)
102+
* [Replay.jl](https://github.com/AtelierArith/Replay.jl)
103+
104+
## GitHub Actions
105+
106+
The most useful aspect of PkgTemplates.jl is that it automatically generates workflows for [GitHub Actions](https://docs.github.com/en/actions/quickstart).
107+
These are stored as YAML files in `.github/workflows`, with a slightly convoluted syntax that you don't need to fully understand.
108+
For instance, the file `CI.yml` contains instructions that execute the tests of your package for each pull request, tag or push to the `main` branch.
109+
This is done on a GitHub server and should theoretically cost you money, but your GitHub repository is public, you get an unlimited workflow budget for free.
110+
111+
The other default workflows are less relevant for new users, but we still mention them:
112+
113+
* [CompatHelper.jl](https://github.com/JuliaRegistries/CompatHelper.jl) monitors your dependencies and their versions.
114+
* [TagBot](https://github.com/JuliaRegistries/TagBot) helps you manage package releases.
34115

35116
## Literate programming
36117

@@ -43,8 +124,6 @@
43124

44125
* [semantic versioning](https://semver.org/)
45126
* [PackageCompatUI.jl](https://github.com/GunnarFarneback/PackageCompatUI.jl)
46-
* [CompatHelper.jl](https://github.com/JuliaRegistries/CompatHelper.jl)
47-
* [TagBot](https://github.com/JuliaRegistries/TagBot)
48127
* [SimpleUnPack.jl](https://github.com/devmotion/SimpleUnPack.jl)
49128

50129
## Extensions

pages/writing.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Writing your code
44

5+
In this post, you will learn about tools to create, run and debug Julia code.
6+
57
\toc
68

79
## Getting help
@@ -305,7 +307,7 @@ Assume you want to debug a function checking whether the $n$-th [Fermat number](
305307
```!fermat
306308
function fermat_prime(n)
307309
F = 2^(2^n) + 1
308-
for d in 2:isqrt(F)
310+
for d in 2:isqrt(F) # integer square root
309311
if F % d == 0
310312
return false
311313
end
@@ -369,7 +371,7 @@ In particular, note that `@debug` messages are suppressed by default.
369371
You can enable them through the `JULIA_DEBUG` environment variable if you specify the source module name, here `Main`.
370372

371373
```julia-repl
372-
ENV["JULIA_DEBUG"] = Main # enable @debug logs
374+
julia> ENV["JULIA_DEBUG"] = Main # enable @debug logs
373375
```
374376

375377
## Debugging

0 commit comments

Comments
 (0)