Skip to content

Commit f79928d

Browse files
committed
Refactor config to argparse
1 parent ceae6c7 commit f79928d

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

pysrc/juliacall/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ 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]
151150

152151
# Stop if we already initialised
153152
if CONFIG['inited']:

pysrc/juliacall/__main__.py

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

7+
import argparse
8+
from pathlib import Path
9+
parser = argparse.ArgumentParser("JuliaCall REPL (experimental)")
10+
parser.add_argument('--banner', choices=['yes', 'no', 'short'], default='yes', help='Enable or disable startup banner')
11+
parser.add_argument('--quiet', '-q', action='store_true', help='Quiet startup: no banner, suppress REPL warnings')
12+
parser.add_argument('--history-file', choices=['yes', 'no'], default='yes', help='Load or save history')
13+
parser.add_argument('--preamble', type=Path, help='Code to be included before the REPL starts')
14+
args = parser.parse_args()
15+
716
from juliacall import Main, Base
817

918
Base.is_interactive = True
1019

11-
Main.include(os.path.join(os.path.dirname(__file__), 'banner.jl'))
12-
Main.__PythonCall_banner()
20+
if not args.quiet:
21+
Main.include(os.path.join(os.path.dirname(__file__), 'banner.jl'))
22+
Main.__PythonCall_banner(Base.Symbol(args.banner))
1323

1424
if Main.seval(r'VERSION > v"v1.11.0-alpha1"'):
1525
no_banner_opt = Base.Symbol("no")
1626
else:
1727
no_banner_opt = False
1828

19-
Base.run_main_repl(True, False, no_banner_opt, True, True)
29+
if args.preamble:
30+
Main.include(str(args.preamble.resolve()))
31+
32+
Base.run_main_repl(
33+
Base.is_interactive,
34+
args.quiet,
35+
no_banner_opt,
36+
args.history_file == 'yes',
37+
True
38+
)

pysrc/juliacall/banner.jl

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

3-
function __PythonCall_banner(io::IO = stdout)
4-
banner_opt = begin
5-
opts = Base.JLOptions()
6-
b = opts.banner
7-
b == -1 ? :yes :
8-
b == 0 ? :no :
9-
b == 1 ? :yes :
10-
:short # b == 2
11-
end
3+
function __PythonCall_banner(banner_opt::Symbol = :yes)
4+
io = stdout
125

136
if banner_opt == :no
147
return

0 commit comments

Comments
 (0)