• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37610

03 Sep 2023 03:55PM UTC coverage: 86.433% (-0.8%) from 87.218%
#37610

push

local

web-flow
Standardize the entry-point for Julia execution (#50974)

This is a bit of a straw-man proposal (though I think mergable if people
agree) to standardize the execution entrypoint for Julia scripts. I
think there's at least four different ways that people might run a
script:

- As `julia main.jl`
- As a PkgCompiler sysimage, then calling the main entry point
- As a PkgCompiler "app", with the magic `julia_main` function
- As a StaticCompiler product with an explicit entrypoint specified on
the API.

The main problem I have with all of these variants is that they're all
different and it's kind of a pain to move between them. Here I propose
that we standardize on `Main.main(ARGS)` as the entrypoint for all
scripts. Downstream from that proposal, this PR then makes the following
changes:

1. If a system image has an existing `Main.main`, that is the entry
point for `julia -Jsysimage.so`.
2. If not, and the sysimage has a REPL, we call REPL.main (we could
handle this by defaulting `Main.main` to a weak import of `REPL.main`,
but for the purpose of this PR, it's an explicit fallback. That said, I
do want to emhpasize the direction of moving the REPL to be "just
another app".
3. If the REPL code is called and passed a script file, the REPL
executes any newly defined Main.main after loading the script file. As a
result, `julia` behaves the same as if we had generated a new system
image after loading `main.jl` and then running julia with that system
image.

The further downstream implication of this is that I'd like to get rid
of the distinction between PkgCompiler apps and system images. An app is
simply a system image with a `Main.main` function defined (note that
currently PkgCompiler uses `julia_main` instead).

---------

Co-authored-by: Martijn Visser <mgvisser@gmail.com>

25 of 25 new or added lines in 2 files covered. (100.0%)

73492 of 85028 relevant lines covered (86.43%)

13617619.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.86
/stdlib/Markdown/src/render/plain.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
plain(x) = sprint(plain, x)
×
4

5
function plain(io::IO, content::Vector)
384✔
6
    isempty(content) && return
384✔
7
    for md in content[1:end-1]
702✔
8
        plain(io, md)
223✔
9
        println(io)
223✔
10
    end
289✔
11
    plain(io, content[end])
384✔
12
end
13

14
plain(io::IO, md::MD) = plain(io, md.content)
364✔
15

16
function plain(io::IO, header::Header{l}) where l
85✔
17
    print(io, "#"^l*" ")
85✔
18
    plaininline(io, header.text)
85✔
19
    println(io)
85✔
20
end
21

22
function plain(io::IO, code::Code)
85✔
23
    # If the code includes a fenced block this will break parsing,
24
    # so it must be enclosed by a longer ````-sequence.
25
    n = mapreduce(m -> length(m.match), max, eachmatch(r"^`+"m, code.code); init=2) + 1
85✔
26
    println(io, "`" ^ n, code.language)
85✔
27
    println(io, code.code)
85✔
28
    println(io, "`" ^ n)
85✔
29
end
30

31
function plain(io::IO, p::Paragraph)
247✔
32
    plaininline(io, p.content)
247✔
33
    println(io)
247✔
34
end
35

36
function plain(io::IO, list::List)
6✔
37
    for (i, item) in enumerate(list.items)
12✔
38
        print(io, isordered(list) ? "$(i + list.ordered - 1). " : "  * ")
20✔
39
        lines = split(rstrip(sprint(plain, item)), "\n")
20✔
40
        for (n, line) in enumerate(lines)
40✔
41
            print(io, (n == 1 || isempty(line)) ? "" : "    ", line)
20✔
42
            n < length(lines) && println(io)
20✔
43
        end
20✔
44
        println(io)
20✔
45
    end
20✔
46
end
47

48
function plain(io::IO, q::BlockQuote)
×
49
    s = sprint(plain, q.content)
×
50
    for line in split(rstrip(s), "\n")
×
51
        println(io, isempty(line) ? ">" : "> ", line)
×
52
    end
×
53
    println(io)
×
54
end
55

56
function plain(io::IO, f::Footnote)
×
57
    print(io, "[^", f.id, "]:")
×
58
    s = sprint(plain, f.text)
×
59
    lines = split(rstrip(s), "\n")
×
60
    # Single line footnotes are printed on the same line as their label
61
    # rather than taking up an additional line.
62
    if length(lines) == 1
×
63
        println(io, " ", lines[1])
×
64
    else
65
        println(io)
×
66
        for line in lines
×
67
            println(io, isempty(line) ? "" : "    ", line)
×
68
        end
×
69
        println(io)
×
70
    end
71
end
72

73
function plain(io::IO, md::Admonition)
×
74
    s = sprint(plain, md.content)
×
75
    title = md.title == uppercasefirst(md.category) ? "" : " \"$(md.title)\""
×
76
    println(io, "!!! ", md.category, title)
×
77
    for line in split(rstrip(s), "\n")
×
78
        println(io, isempty(line) ? "" : "    ", line)
×
79
    end
×
80
    println(io)
×
81
end
82

83
function plain(io::IO, md::HorizontalRule)
×
84
    println(io, "-" ^ 3)
×
85
end
86

87
function plain(io::IO, l::LaTeX)
×
88
    println(io, '$', '$')
×
89
    println(io, l.formula)
×
90
    println(io, '$', '$')
×
91
end
92

93
function plain(io::IO, md)
×
94
    show(io,  MIME"text/plain"(), md)
×
95
    println(io)
×
96
end
97

98
# Inline elements
99

100
plaininline(x) = sprint(plaininline, x)
171✔
101

102
function plaininline(io::IO, md...)
58✔
103
    for el in md
58✔
104
        plaininline(io, el)
274✔
105
    end
264✔
106
end
107

108
plaininline(io::IO, md::Vector) = !isempty(md) && plaininline(io, md...)
343✔
109

110
plaininline(io::IO, f::Footnote) = print(io, "[^", f.id, "]")
×
111

112
plaininline(io::IO, link::Link) = plaininline(io, "[", link.text, "](", link.url, ")")
11✔
113

114
plaininline(io::IO, md::Image) = plaininline(io, "![", md.alt, "](", md.url, ")")
×
115

116
plaininline(io::IO, s::AbstractString) = print(io, s)
600✔
117

118
plaininline(io::IO, md::Bold) = plaininline(io, "**", md.text, "**")
×
119

120
plaininline(io::IO, md::Italic) = plaininline(io, "*", md.text, "*")
×
121

122
function plaininline(io::IO, md::Code)
109✔
123
    if occursin("`", md.code)
109✔
124
        n = maximum(length(m.match) for m in eachmatch(r"(`+)", md.code))
×
125
        s = "`"^((iseven(n) ? 1 : 2) + n)
×
126
        print(io, s, Base.startswith(md.code, "`") ? " " : "")
×
127
        print(io, md.code, endswith(md.code, "`") ? " " : "", s)
×
128
    else
129
        print(io, "`", md.code, "`")
109✔
130
    end
131
end
132

133
plaininline(io::IO, br::LineBreak) = println(io)
×
134

135
plaininline(io::IO, x) = show(io, MIME"text/plain"(), x)
×
136

137
# show
138

139
Base.show(io::IO, md::MD) = plain(io, md)
26✔
140
Base.show(io::IO, ::MIME"text/markdown", md::MD) = plain(io, md)
162✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc