Skip to content

Commit 698e16e

Browse files
committed
Refactor
1 parent f79928d commit 698e16e

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ dev = [
2626

2727
[tool.hatch.build.targets.wheel]
2828
packages = ["pysrc/juliacall"]
29+
30+
[project.scripts]
31+
pyjulia = "juliacall.repl:run_repl"

pysrc/juliacall/__main__.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
1-
import os
2-
os.environ.setdefault("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")
3-
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS") != "yes":
4-
print("Experimental JuliaCall REPL requires PYTHON_JULIACALL_HANDLE_SIGNALS=yes")
5-
exit(1)
1+
from juliacall.repl import run_repl
62

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-
16-
from juliacall import Main, Base
17-
18-
Base.is_interactive = True
19-
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))
23-
24-
if Main.seval(r'VERSION > v"v1.11.0-alpha1"'):
25-
no_banner_opt = Base.Symbol("no")
26-
else:
27-
no_banner_opt = False
28-
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-
)
3+
if __name__ == '__main__':
4+
run_repl()

pysrc/juliacall/repl.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
def run_repl():
2+
import os
3+
os.environ.setdefault("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")
4+
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS") != "yes":
5+
print("Experimental JuliaCall REPL requires PYTHON_JULIACALL_HANDLE_SIGNALS=yes")
6+
exit(1)
7+
8+
import argparse
9+
from pathlib import Path
10+
parser = argparse.ArgumentParser("JuliaCall REPL (experimental)")
11+
parser.add_argument('--banner', choices=['yes', 'no', 'short'], default='yes', help='Enable or disable startup banner')
12+
parser.add_argument('--quiet', '-q', action='store_true', help='Quiet startup: no banner, suppress REPL warnings')
13+
parser.add_argument('--history-file', choices=['yes', 'no'], default='yes', help='Load or save history')
14+
parser.add_argument('--preamble', type=Path, help='Code to be included before the REPL starts')
15+
args = parser.parse_args()
16+
17+
from juliacall import Main, Base
18+
19+
Base.is_interactive = True
20+
21+
if not args.quiet:
22+
Main.include(os.path.join(os.path.dirname(__file__), 'banner.jl'))
23+
Main.__PythonCall_banner(Base.Symbol(args.banner))
24+
25+
if Main.seval(r'VERSION > v"v1.11.0-alpha1"'):
26+
no_banner_opt = Base.Symbol("no")
27+
else:
28+
no_banner_opt = False
29+
30+
if args.preamble:
31+
Main.include(str(args.preamble.resolve()))
32+
33+
Base.run_main_repl(
34+
Base.is_interactive,
35+
args.quiet,
36+
no_banner_opt,
37+
args.history_file == 'yes',
38+
True
39+
)
40+
41+
if __name__ == '__main__':
42+
run_repl()

0 commit comments

Comments
 (0)