Skip to content

Commit 6631df6

Browse files
committed
Clean up imports
1 parent 846d823 commit 6631df6

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

pysrc/juliacall/__main__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
import argparse
2+
3+
from juliacall import Main
4+
from juliacall.repl import run_repl, add_repl_args
5+
6+
17
if __name__ == '__main__':
2-
import argparse
38
parser = argparse.ArgumentParser("JuliaCall REPL (experimental)")
49
parser.add_argument('-e', '--eval', type=str, default=None, help='Evaluate <expr>. If specified, all other arguments are ignored.')
510
parser.add_argument('-E', '--print', type=str, default=None, help='Evaluate <expr> and display the result. If specified, all other arguments are ignored.')
611

7-
from juliacall.repl import add_repl_args
812
add_repl_args(parser)
913

1014
args = parser.parse_args()
1115
assert not (args.eval is not None and args.print is not None), "Cannot specify both -e/--eval and -E/--print"
1216

1317
if args.eval is not None:
14-
from juliacall import Main
1518
Main.seval(args.eval)
1619
elif args.print is not None:
17-
from juliacall import Main
1820
result = Main.seval(args.print)
1921
Main.display(result)
2022
else:
21-
from juliacall.repl import run_repl
2223
run_repl(
2324
banner=args.banner,
2425
quiet=args.quiet,

pysrc/juliacall/init.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import json
2+
import juliapkg
3+
import sys
4+
15
if __name__ == '__main__':
2-
import juliacall as _ # calls init() which calls juliapkg.executable() which lazily downloads julia
6+
# invoking python -m juliacall.init automatically imports juliacall which
7+
# calls init() which calls juliapkg.executable() which lazily downloads julia
38

4-
import sys
59
if "--debug" in sys.argv:
6-
import juliapkg, json
710
state = juliapkg.state.STATE
811
state["version"] = str(state["version"])
912
print(json.dumps(state, indent=2))

pysrc/juliacall/repl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import argparse
2+
import os
3+
from pathlib import Path
4+
5+
from juliacall import Main, Base
6+
17
def run_repl(banner='yes', quiet=False, history_file='yes', preamble=None):
2-
import os
38
os.environ.setdefault("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")
49
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS") != "yes":
510
print("Experimental JuliaCall REPL requires PYTHON_JULIACALL_HANDLE_SIGNALS=yes")
611
exit(1)
712

8-
from juliacall import Main, Base
9-
1013
Base.is_interactive = True
1114

1215
if not quiet:
@@ -30,16 +33,13 @@ def run_repl(banner='yes', quiet=False, history_file='yes', preamble=None):
3033
)
3134

3235
def add_repl_args(parser):
33-
from pathlib import Path
3436
parser.add_argument('--banner', choices=['yes', 'no', 'short'], default='yes', help='Enable or disable startup banner')
3537
parser.add_argument('--quiet', '-q', action='store_true', help='Quiet startup: no banner, suppress REPL warnings')
3638
parser.add_argument('--history-file', choices=['yes', 'no'], default='yes', help='Load or save history')
3739
parser.add_argument('--preamble', type=Path, help='Code to be included before the REPL starts')
3840

3941
if __name__ == '__main__':
40-
import argparse
4142
parser = argparse.ArgumentParser("JuliaCall REPL (experimental)")
42-
from juliacall.repl import add_repl_args
4343
add_repl_args(parser)
4444
args = parser.parse_args()
4545
run_repl(args.banner, args.quiet, args.history_file, args.preamble)

0 commit comments

Comments
 (0)