Skip to content

Commit a842283

Browse files
Format code base with runic and set up runic CI (#4320)
1 parent 48d5577 commit a842283

File tree

99 files changed

+7656
-6840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+7656
-6840
lines changed

.github/workflows/check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Code checks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["master"]
7+
8+
jobs:
9+
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
15+
env:
16+
# Skip runic-pre-commit since we use runic-action below instead
17+
SKIP: runic
18+
19+
runic:
20+
name: "Runic"
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: julia-actions/setup-julia@v2
25+
with:
26+
version: '1.11'
27+
- uses: julia-actions/cache@v2
28+
- uses: fredrikekre/runic-action@v1
29+
with:
30+
version: "1.4" # Keep version in sync with .pre-commit-config.yaml

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-case-conflict
7+
# - id: check-toml # we have tomls with invalid syntax for tests
8+
- id: check-yaml
9+
- id: end-of-file-fixer
10+
- id: mixed-line-ending
11+
- id: trailing-whitespace
12+
- repo: 'https://github.com/fredrikekre/runic-pre-commit'
13+
rev: v2.0.1
14+
hooks:
15+
- id: runic
16+
additional_dependencies:
17+
- '[email protected]' # Keep version in sync with .github/workflows/Check.yml

contrib/list_missing_pkg_tags.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const PKG_REPO_URL = "https://github.com/JuliaLang/Pkg.jl.git"
77
const PKG_REPO_DIR = "Pkg.jl"
88

99
function checkout_or_update_repo(url, dir)
10-
if isdir(dir)
10+
return if isdir(dir)
1111
println("Updating existing repository: $dir")
1212
repo = LibGit2.GitRepo(dir)
1313
LibGit2.fetch(repo)
@@ -33,7 +33,7 @@ function extract_pkg_sha1(text::AbstractString)
3333
end
3434

3535
function get_commit_hash_for_pkg_version(repo, tag)
36-
try
36+
return try
3737
tag_ref = LibGit2.GitReference(repo, "refs/tags/" * tag)
3838
LibGit2.checkout!(repo, string(LibGit2.GitHash(LibGit2.peel(tag_ref))))
3939
version_file = joinpath(JULIA_REPO_DIR, PKG_VERSION_PATH)
@@ -78,7 +78,7 @@ cd(tempdir) do
7878
missing_versions = filter(v -> v pkg_tags, collect(keys(version_commit_map)))
7979

8080
# Sort versions numerically
81-
sort!(missing_versions, by=VersionNumber)
81+
sort!(missing_versions, by = VersionNumber)
8282

8383
# Generate `git tag` commands
8484
println("\nGit tag commands for missing Pkg.jl versions:")

docs/NEWS-update.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ s = read(NEWS, String)
77

88
m = match(r"\[#[0-9]+\]:", s)
99
if m !== nothing
10-
s = s[1:m.offset-1]
10+
s = s[1:(m.offset - 1)]
1111
end
1212

1313
footnote(n) = "[#$n]: https://github.com/JuliaLang/Pkg.jl/issues/$n"
14-
N = map(m -> parse(Int,m.captures[1]), eachmatch(r"\[#([0-9]+)\]", s))
14+
N = map(m -> parse(Int, m.captures[1]), eachmatch(r"\[#([0-9]+)\]", s))
1515
foots = join(map(footnote, sort!(unique(N))), "\n")
1616

1717
open(NEWS, "w") do f

docs/generate.jl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,42 @@
44

55
function generate(io, command)
66
cmd_nospace = replace(command, " " => "-")
7-
println(io, """
8-
```@raw html
9-
<article class="docstring">
10-
<header>
11-
<a class="docstring-binding" id="repl-$(cmd_nospace)" href="#repl-$(cmd_nospace)">
12-
<code>$(command)</code>
13-
</a>
14-
15-
<span class="docstring-category">REPL command</span>
16-
</header>
17-
<section>
18-
```
19-
```@eval
20-
using Pkg
21-
Dict(Pkg.REPLMode.canonical_names())["$(command)"].help
22-
```
23-
```@raw html
24-
</section>
25-
</article>
26-
```
27-
""")
7+
return println(
8+
io, """
9+
```@raw html
10+
<article class="docstring">
11+
<header>
12+
<a class="docstring-binding" id="repl-$(cmd_nospace)" href="#repl-$(cmd_nospace)">
13+
<code>$(command)</code>
14+
</a>
15+
16+
<span class="docstring-category">REPL command</span>
17+
</header>
18+
<section>
19+
```
20+
```@eval
21+
using Pkg
22+
Dict(Pkg.REPLMode.canonical_names())["$(command)"].help
23+
```
24+
```@raw html
25+
</section>
26+
</article>
27+
```
28+
"""
29+
)
2830
end
2931
function generate()
3032
io = IOBuffer()
31-
println(io, """
33+
println(
34+
io, """
3235
# [**11.** REPL Mode Reference](@id REPL-Mode-Reference)
3336
3437
This section describes available commands in the Pkg REPL.
3538
The Pkg REPL mode is mostly meant for interactive use,
3639
and for non-interactive use it is recommended to use the
3740
functional API, see [API Reference](@ref API-Reference).
38-
""")
41+
"""
42+
)
3943
# list commands
4044
println(io, "## `package` commands")
4145
foreach(command -> generate(io, command), ["add", "build", "compat", "develop", "free", "generate", "pin", "remove", "test", "update"])

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if "pdf" in ARGS
1717
end
1818

1919
# setup for doctesting
20-
DocMeta.setdocmeta!(Pkg.BinaryPlatforms, :DocTestSetup, :(using Base.BinaryPlatforms); recursive=true)
20+
DocMeta.setdocmeta!(Pkg.BinaryPlatforms, :DocTestSetup, :(using Base.BinaryPlatforms); recursive = true)
2121

2222
# Run doctests first and disable them in makedocs
2323
Documenter.doctest(joinpath(@__DIR__, "src"), [Pkg])

docs/src/creating-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ may fit your package better.
627627
* The package name should begin with a capital letter and word separation is shown with upper camel case
628628
* Packages that provide the functionality of a project from another language should use the Julia convention
629629
* Packages that [provide pre-built libraries and executables](https://docs.binarybuilder.org/stable/jll/) can keep their original name, but should get `_jll`as a suffix. For example `pandoc_jll` wraps pandoc. However, note that the generation and release of most JLL packages is handled by the [Yggdrasil](https://github.com/JuliaPackaging/Yggdrasil) system.
630-
630+
631631
10. For the complete list of rules for automatic merging into the General registry, see [these guidelines](https://juliaregistries.github.io/RegistryCI.jl/stable/guidelines/).
632632

633633

docs/src/protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The protocols also aim to address some of the limitations that existed prior to
1313

1414
## Protocols & Services
1515

16-
1. **Pkg Protocol:** what Julia Pkg Clients speak to Pkg Servers. The Pkg Server serves all resources that Pkg Clients need to install and use registered packages, including registry data, packages and artifacts. It is designed to be easily horizontally scalable and not to have any hard operational requirements: if service is slow, just start more servers; if a Pkg Server crashes, forget it and boot up a new one.
16+
1. **Pkg Protocol:** what Julia Pkg Clients speak to Pkg Servers. The Pkg Server serves all resources that Pkg Clients need to install and use registered packages, including registry data, packages and artifacts. It is designed to be easily horizontally scalable and not to have any hard operational requirements: if service is slow, just start more servers; if a Pkg Server crashes, forget it and boot up a new one.
1717
2. **Storage Protocol:** what Pkg Servers speak to get resources from Storage Services. Julia clients do not interact with Storage services directly and multiple independent Storage Services can symmetrically (all are treated equally) provide their service to a given Pkg Server. Since Pkg Servers cache what they serve to Clients and handle convenient content presentation, Storage Services can expose a much simpler protocol: all they do is serve up complete versions of registries, packages and artifacts, while guaranteeing persistence and completeness. Persistence means: once a version of a resource has been served, that version can be served forever. Completeness means: if the service serves a registry, it can serve all package versions referenced by that registry; if it serves a package version, it can serve all artifacts used by that package.
1818

1919
Both protocols work over HTTPS, using only GET and HEAD requests. As is normal for HTTP, HEAD requests are used to get information about a resource, including whether it would be served, without actually downloading it. As described in what follows, the Pkg Protocol is client-to-server and may be unauthenticated, use basic auth, or OpenID; the Storage Protocol is server-to-server only and uses mutual authentication with TLS certificates.

ext/REPLExt/REPLExt.jl

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ include("compat.jl")
3030

3131
struct PkgCompletionProvider <: LineEdit.CompletionProvider end
3232

33-
function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool=false)
33+
function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool = false)
3434
partial = REPL.beforecursor(s.input_buffer)
3535
full = LineEdit.input_string(s)
3636
ret, range, should_complete = completions(full, lastindex(partial); hint)
@@ -120,16 +120,18 @@ function on_done(s, buf, ok, repl)
120120
do_cmds(repl, input)
121121
REPL.prepare_next(repl)
122122
REPL.reset_state(s)
123-
s.current_mode.sticky || REPL.transition(s, main)
123+
return s.current_mode.sticky || REPL.transition(s, main)
124124
end
125125

126126
# Set up the repl Pkg REPLMode
127127
function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt)
128-
pkg_mode = LineEdit.Prompt(promptf;
128+
pkg_mode = LineEdit.Prompt(
129+
promptf;
129130
prompt_prefix = repl.options.hascolor ? Base.text_colors[:blue] : "",
130131
prompt_suffix = "",
131132
complete = PkgCompletionProvider(),
132-
sticky = true)
133+
sticky = true
134+
)
133135

134136
pkg_mode.repl = repl
135137
hp = main.hist
@@ -152,9 +154,9 @@ function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt)
152154

153155
repl_keymap = Dict()
154156
if shell_mode !== nothing
155-
let shell_mode=shell_mode
156-
repl_keymap[';'] = function (s,o...)
157-
if isempty(s) || position(LineEdit.buffer(s)) == 0
157+
let shell_mode = shell_mode
158+
repl_keymap[';'] = function (s, o...)
159+
return if isempty(s) || position(LineEdit.buffer(s)) == 0
158160
buf = copy(LineEdit.buffer(s))
159161
LineEdit.transition(s, shell_mode) do
160162
LineEdit.state(s, shell_mode).input_buffer = buf
@@ -167,9 +169,9 @@ function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt)
167169
end
168170
end
169171

170-
b = Dict{Any,Any}[
172+
b = Dict{Any, Any}[
171173
skeymap, repl_keymap, mk, prefix_keymap, LineEdit.history_keymap,
172-
LineEdit.default_keymap, LineEdit.escape_defaults
174+
LineEdit.default_keymap, LineEdit.escape_defaults,
173175
]
174176
pkg_mode.keymap_dict = LineEdit.keymap(b)
175177
return pkg_mode
@@ -179,9 +181,9 @@ function repl_init(repl::REPL.LineEditREPL)
179181
main_mode = repl.interface.modes[1]
180182
pkg_mode = create_mode(repl, main_mode)
181183
push!(repl.interface.modes, pkg_mode)
182-
keymap = Dict{Any,Any}(
183-
']' => function (s,args...)
184-
if isempty(s) || position(LineEdit.buffer(s)) == 0
184+
keymap = Dict{Any, Any}(
185+
']' => function (s, args...)
186+
return if isempty(s) || position(LineEdit.buffer(s)) == 0
185187
buf = copy(LineEdit.buffer(s))
186188
LineEdit.transition(s, pkg_mode) do
187189
LineEdit.state(s, pkg_mode).input_buffer = buf
@@ -208,9 +210,9 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
208210
end
209211
if isempty(ctx.registries)
210212
if !REG_WARNED[]
211-
printstyled(ctx.io, ""; color=:green)
213+
printstyled(ctx.io, ""; color = :green)
212214
printstyled(ctx.io, "Attempted to find missing packages in package registries but no registries are installed.\n")
213-
printstyled(ctx.io, ""; color=:green)
215+
printstyled(ctx.io, ""; color = :green)
214216
printstyled(ctx.io, "Use package mode to install a registry. `pkg> registry add` will install the default registries.\n\n")
215217
REG_WARNED[] = true
216218
end
@@ -230,22 +232,22 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
230232
available_pkg_list = length(available_pkgs) == 1 ? String(available_pkgs[1]) : "[$(join(available_pkgs, ", "))]"
231233
msg1 = "Package$(plural1) $(missing_pkg_list) not found, but $(plural2) named $(available_pkg_list) $(plural3) available from a registry."
232234
for line in linewrap(msg1, io = ctx.io, padding = length(""))
233-
printstyled(ctx.io, ""; color=:green)
235+
printstyled(ctx.io, ""; color = :green)
234236
println(ctx.io, line)
235237
end
236-
printstyled(ctx.io, ""; color=:green)
238+
printstyled(ctx.io, ""; color = :green)
237239
println(ctx.io, "Install package$(plural4)?")
238240
msg2 = string("add ", join(available_pkgs, ' '))
239241
for (i, line) in pairs(linewrap(msg2; io = ctx.io, padding = length(string(" | ", promptf()))))
240-
printstyled(ctx.io, ""; color=:green)
242+
printstyled(ctx.io, ""; color = :green)
241243
if i == 1
242-
printstyled(ctx.io, promptf(); color=:blue)
244+
printstyled(ctx.io, promptf(); color = :blue)
243245
else
244246
print(ctx.io, " "^length(promptf()))
245247
end
246248
println(ctx.io, line)
247249
end
248-
printstyled(ctx.io, ""; color=:green)
250+
printstyled(ctx.io, ""; color = :green)
249251
Base.prompt(stdin, ctx.io, "(y/n/o)", default = "y")
250252
catch err
251253
if err isa InterruptException # if ^C is entered
@@ -261,7 +263,7 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
261263
resp = strip(resp)
262264
lower_resp = lowercase(resp)
263265
if lower_resp in ["y", "yes"]
264-
API.add(string.(available_pkgs); allow_autoprecomp=false)
266+
API.add(string.(available_pkgs); allow_autoprecomp = false)
265267
elseif lower_resp in ["o"]
266268
editable_envs = filter(v -> v != "@stdlib", LOAD_PATH)
267269
option_list = String[]
@@ -280,16 +282,16 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
280282
push!(keybindings, only("$n"))
281283
push!(shown_envs, expanded_env)
282284
end
283-
menu = TerminalMenus.RadioMenu(option_list, keybindings=keybindings, pagesize=length(option_list))
285+
menu = TerminalMenus.RadioMenu(option_list, keybindings = keybindings, pagesize = length(option_list))
284286
default = something(
285287
# select the first non-default env by default, if possible
286288
findfirst(!=(Base.active_project()), shown_envs),
287289
1
288290
)
289291
print(ctx.io, "\e[1A\e[1G\e[0J") # go up one line, to the start, and clear it
290-
printstyled(ctx.io, ""; color=:green)
292+
printstyled(ctx.io, ""; color = :green)
291293
choice = try
292-
TerminalMenus.request("Select environment:", menu, cursor=default)
294+
TerminalMenus.request("Select environment:", menu, cursor = default)
293295
catch err
294296
if err isa InterruptException # if ^C is entered
295297
println(ctx.io)
@@ -299,7 +301,7 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
299301
end
300302
choice == -1 && return false
301303
API.activate(shown_envs[choice]) do
302-
API.add(string.(available_pkgs); allow_autoprecomp=false)
304+
API.add(string.(available_pkgs); allow_autoprecomp = false)
303305
end
304306
elseif (lower_resp in ["n"])
305307
return false
@@ -315,7 +317,6 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
315317
end
316318

317319

318-
319320
function __init__()
320321
if isdefined(Base, :active_repl)
321322
if Base.active_repl isa REPL.LineEditREPL
@@ -333,7 +334,7 @@ function __init__()
333334
end
334335
end
335336
end
336-
if !in(try_prompt_pkg_add, REPL.install_packages_hooks)
337+
return if !in(try_prompt_pkg_add, REPL.install_packages_hooks)
337338
push!(REPL.install_packages_hooks, try_prompt_pkg_add)
338339
end
339340
end

ext/REPLExt/compat.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ function _compat(ctx::Context; io = nothing)
99
compat_str = Operations.get_compat_str(ctx.env.project, "julia")
1010
push!(opt_strs, Operations.compat_line(io, "julia", nothing, compat_str, longest_dep_len, indent = ""))
1111
push!(opt_pkgs, "julia")
12-
for (dep, uuid) in sort(collect(ctx.env.project.deps); by = x->x.first)
12+
for (dep, uuid) in sort(collect(ctx.env.project.deps); by = x -> x.first)
1313
compat_str = Operations.get_compat_str(ctx.env.project, dep)
1414
push!(opt_strs, Operations.compat_line(io, dep, uuid, compat_str, longest_dep_len, indent = ""))
1515
push!(opt_pkgs, dep)
1616
end
17-
menu = TerminalMenus.RadioMenu(opt_strs, pagesize=length(opt_strs))
17+
menu = TerminalMenus.RadioMenu(opt_strs, pagesize = length(opt_strs))
1818
choice = try
1919
TerminalMenus.request(" Select an entry to edit:", menu)
2020
catch err
@@ -35,7 +35,7 @@ function _compat(ctx::Context; io = nothing)
3535
start_pos = length(prompt) + 2
3636
move_start = "\e[$(start_pos)G"
3737
clear_to_end = "\e[0J"
38-
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), stdin.handle, true)
38+
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid}, Int32), stdin.handle, true)
3939
while true
4040
print(io, move_start, clear_to_end, buffer, "\e[$(start_pos + cursor)G")
4141
inp = TerminalMenus._readkey(stdin)
@@ -65,9 +65,9 @@ function _compat(ctx::Context; io = nothing)
6565
if cursor == 1
6666
buffer = buffer[2:end]
6767
elseif cursor == length(buffer)
68-
buffer = buffer[1:end - 1]
68+
buffer = buffer[1:(end - 1)]
6969
elseif cursor > 0
70-
buffer = buffer[1:(cursor-1)] * buffer[(cursor + 1):end]
70+
buffer = buffer[1:(cursor - 1)] * buffer[(cursor + 1):end]
7171
else
7272
continue
7373
end
@@ -85,7 +85,7 @@ function _compat(ctx::Context; io = nothing)
8585
end
8686
buffer
8787
finally
88-
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), stdin.handle, false)
88+
ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid}, Int32), stdin.handle, false)
8989
end
9090
new_entry = strip(resp)
9191
compat(ctx, dep, string(new_entry))

0 commit comments

Comments
 (0)