Skip to content

Commit c8df2e7

Browse files
committed
Refactor
1 parent 64be410 commit c8df2e7

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

pysrc/juliacall/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def args_from_config(config):
147147
CONFIG['opt_handle_signals'] = choice('handle_signals', ['yes', 'no'])[0]
148148
CONFIG['opt_startup_file'] = choice('startup_file', ['yes', 'no'])[0]
149149
CONFIG['opt_heap_size_hint'] = option('heap_size_hint')[0]
150+
CONFIG['opt_banner'] = choice('banner', ['yes', 'no', 'short'])[0]
150151

151152
# Stop if we already initialised
152153
if CONFIG['inited']:

pysrc/juliacall/__main__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
print("Experimental JuliaCall REPL requires PYTHON_JULIACALL_HANDLE_SIGNALS=yes")
55
exit(1)
66

7-
from juliacall import Main
7+
from juliacall import Main, Base
88

9-
Main.seval(f"""\
10-
Base.is_interactive = true
9+
Base.is_interactive = True
1110

12-
include(\"{os.path.join(os.path.dirname(__file__), 'banner.jl')}\")
13-
banner()
11+
Main.include(os.path.join(os.path.dirname(__file__), 'banner.jl'))
12+
Main.__PythonCall_banner()
1413

15-
if VERSION > v"v1.11.0-alpha1"
16-
Base.run_main_repl(true, false, :no, true, true)
17-
else # interactive, quiet, banner, history_file, color_set
18-
Base.run_main_repl(true, false, false, true, true)
19-
end
20-
""")
14+
if Main.seval(r'VERSION > v"v1.11.0-alpha1"'):
15+
no_banner_opt = Base.Symbol("no")
16+
else:
17+
no_banner_opt = False
18+
19+
Base.run_main_repl(True, False, no_banner_opt, True, True)

pysrc/juliacall/banner.jl

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
# https://github.com/JuliaLang/julia/blob/fae0d0ad3e5d9804533435fe81f4eaac819895af/stdlib/REPL/src/REPL.jl#L1727C1-L1795C4
22

3-
function banner(io::IO = stdout; short = false)
4-
if Base.GIT_VERSION_INFO.tagged_commit
5-
commit_string = Base.TAGGED_RELEASE_BANNER
6-
elseif isempty(Base.GIT_VERSION_INFO.commit)
7-
commit_string = ""
8-
else
9-
days = Int(floor((ccall(:jl_clock_now, Float64, ()) - Base.GIT_VERSION_INFO.fork_master_timestamp) / (60 * 60 * 24)))
10-
days = max(0, days)
11-
unit = days == 1 ? "day" : "days"
12-
distance = Base.GIT_VERSION_INFO.fork_master_distance
13-
commit = Base.GIT_VERSION_INFO.commit_short
3+
function __PythonCall_banner(io::IO = stdout)
4+
banner_opt = begin
5+
opts = Base.JLOptions()
6+
b = opts.banner
7+
auto = b == -1
8+
b == 0 || (auto && !interactiveinput) ? :no :
9+
b == 1 || (auto && interactiveinput) ? :yes :
10+
:short # b == 2
11+
end
1412

15-
if distance == 0
16-
commit_string = "Commit $(commit) ($(days) $(unit) old master)"
17-
else
18-
branch = Base.GIT_VERSION_INFO.branch
19-
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
20-
end
13+
if banner_opt == :no
14+
return
2115
end
2216

23-
commit_date = isempty(Base.GIT_VERSION_INFO.date_string) ? "" : " ($(split(Base.GIT_VERSION_INFO.date_string)[1]))"
17+
short = banner_opt == :short
2418

2519
if get(io, :color, false)::Bool
2620
c = Base.text_colors
@@ -34,8 +28,8 @@ function banner(io::IO = stdout; short = false)
3428

3529
if short
3630
print(io,"""
37-
$(d3)o$(tx) | Version $(VERSION)PythonCall: $(PythonCall.VERSION)
38-
$(d2)o$(tx) $(d4)o$(tx) | $(commit_string)
31+
$(d3)o$(tx) | Julia $(VERSION)
32+
$(d2)o$(tx) $(d4)o$(tx) $(c[:bold] * jc)o$(tx) | PythonCall $(PythonCall.VERSION)
3933
""")
4034
else
4135
print(io,""" $(d3)_$(tx)
@@ -52,8 +46,8 @@ function banner(io::IO = stdout; short = false)
5246
else
5347
if short
5448
print(io,"""
55-
o | Version $(VERSION)PythonCall: $(PythonCall.VERSION)
56-
o o | $(commit_string)
49+
o | Julia $(VERSION)
50+
o o o | PythonCall $(PythonCall.VERSION)
5751
""")
5852
else
5953
print(io,"""
@@ -68,4 +62,4 @@ function banner(io::IO = stdout; short = false)
6862
""")
6963
end
7064
end
71-
end
65+
end

0 commit comments

Comments
 (0)