Skip to content

Commit ec71272

Browse files
committed
Set __name__ to __repl__ when setting up #540
1 parent 84a1ba6 commit ec71272

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

fnl/conjure/client/python/stdio.fnl

+18-13
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,23 @@
199199
(display-repl-status :stopped)
200200
(a.assoc (state) :repl nil))))
201201

202-
; By default, there is no way for us to tell the difference between
203-
; normal stdout log messages and the result of the expression we evaluated.
204-
; This is because if an expression results in the literal value None, the python
205-
; interpreter will not print out anything.
206-
; Replacing this hook ensures that the last line in the output after
207-
; sending a command is the result of the command.
208-
; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook
209-
(def update-python-displayhook
210-
(str.join "\n" ["import sys"
211-
"def format_output(val):"
212-
" print(repr(val))"
213-
"sys.displayhook = format_output\n"]))
202+
(def initialise-repl-code
203+
;; By default, there is no way for us to tell the difference between
204+
;; normal stdout log messages and the result of the expression we evaluated.
205+
;; This is because if an expression results in the literal value None, the python
206+
;; interpreter will not print out anything.
207+
;; Replacing this hook ensures that the last line in the output after
208+
;; sending a command is the result of the command.
209+
;; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook
210+
211+
;; We also set the `__name__` to something else so `__main__` blocks aren't executed.
212+
(str.join
213+
"\n"
214+
["import sys"
215+
"def conjure_format_output(val):"
216+
" print(repr(val))"
217+
"sys.displayhook = conjure_format_output\n"
218+
"__name__ = '__repl__'"]))
214219

215220
(defn start []
216221
(if (state :repl)
@@ -238,7 +243,7 @@
238243
(with-repl-or-warn
239244
(fn [repl]
240245
(repl.send
241-
(prep-code update-python-displayhook)
246+
(prep-code initialise-repl-code)
242247
(fn [msgs] nil)
243248
nil)))))
244249

lua/conjure/client/python/stdio.lua

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)