Skip to content

Commit cff79d5

Browse files
author
Christopher Doris
committed
interactive mode
1 parent 8877892 commit cff79d5

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PythonCall"
22
uuid = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
33
authors = ["Christopher Doris <github.com/cjdoris>"]
4-
version = "0.9.6-DEV"
4+
version = "0.9.5"
55

66
[deps]
77
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
@@ -10,6 +10,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1010
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1111
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1212
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
13+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1314
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1415
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1516
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

docs/src/releasenotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Release Notes
22

33
## Unreleased
4+
* When using JuliaCall from an interactive Python session, Julia is put into interactive
5+
mode: `isinteractive()` is true, InteractiveUtils is loaded, and a nicer display is used.
46
* Python named tuples can be converted to Julia named tuples.
57
* Bug fixes.
68

pysrc/juliacall/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ def jlstr(x):
192192
ENV["JULIA_PYTHONCALL_EXE"] = {}
193193
Pkg.activate({}, io=devnull)
194194
import PythonCall
195-
# This uses some internals, but Base._start() gets the state more like Julia
196-
# is if you call the executable directly, in particular it creates workers when
197-
# the --procs argument is given.
198-
push!(Core.ARGS, {})
199-
Base._start()
200-
@eval Base PROGRAM_FILE=""
201195
catch err
202196
print(stderr, "ERROR: ")
203197
showerror(stderr, err, catch_backtrace())
@@ -208,7 +202,6 @@ def jlstr(x):
208202
jlstr(str(c.pythonapi._handle)),
209203
jlstr(sys.executable or ''),
210204
jlstr(project),
211-
jlstr(os.path.join(os.path.dirname(__file__), 'init.jl')),
212205
)
213206
res = jl_eval(script.encode('utf8'))
214207
if res is None:

src/PythonCall.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const VERSION = v"0.9.5"
44
const ROOT_DIR = dirname(@__DIR__)
55

66
using Base: @propagate_inbounds
7-
using MacroTools, Dates, Tables, Markdown, Serialization, Requires, Pkg
7+
using MacroTools, Dates, Tables, Markdown, Serialization, Requires, Pkg, REPL
88

99
include("utils.jl")
1010

src/compat/stdlib.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@ function init_stdlib()
66
pywordsize = @py(jlbool(pysysmodule.maxsize > 2^32)) ? 64 : 32
77
pywordsize == Sys.WORD_SIZE || error("Julia is $(Sys.WORD_SIZE)-bit but Python is $(pywordsize)-bit")
88

9-
if !C.CTX.is_embedded
9+
if C.CTX.is_embedded
10+
11+
# This uses some internals, but Base._start() gets the state more like Julia
12+
# is if you call the executable directly, in particular it creates workers when
13+
# the --procs argument is given.
14+
push!(Core.ARGS, joinpath(ROOT_DIR, "pysrc", "juliacall", "init.jl"))
15+
Base._start()
16+
Base.eval(:(PROGRAM_FILE = ""))
17+
18+
# if Python is interactive, ensure Julia is too
19+
if pyhasattr(pysysmodule, "ps1")
20+
Base.eval(:(is_interactive = true))
21+
REPL = Base.require(Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL"))
22+
# adapted from run_main_repl() in julia/base/client.jl
23+
Base.load_InteractiveUtils()
24+
term_env = get(ENV, "TERM", Sys.iswindows() ? "" : "dumb")
25+
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
26+
if term.term_type == "dumb"
27+
repl = REPL.BasicREPL(term)
28+
else
29+
repl = REPL.LineEditREPL(term, get(stdout, :color, false), true)
30+
repl.history_file = false
31+
end
32+
pushdisplay(REPL.REPLDisplay(repl))
33+
end
34+
35+
else
1036

1137
# set sys.argv
1238
pysysmodule.argv = pylist([""; ARGS])

0 commit comments

Comments
 (0)