Skip to content

Commit

Permalink
Set __name__ to __repl__ when setting up #540
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Dec 3, 2023
1 parent 84a1ba6 commit ec71272
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
31 changes: 18 additions & 13 deletions fnl/conjure/client/python/stdio.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,23 @@
(display-repl-status :stopped)
(a.assoc (state) :repl nil))))

; By default, there is no way for us to tell the difference between
; normal stdout log messages and the result of the expression we evaluated.
; This is because if an expression results in the literal value None, the python
; interpreter will not print out anything.
; Replacing this hook ensures that the last line in the output after
; sending a command is the result of the command.
; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook
(def update-python-displayhook
(str.join "\n" ["import sys"
"def format_output(val):"
" print(repr(val))"
"sys.displayhook = format_output\n"]))
(def initialise-repl-code
;; By default, there is no way for us to tell the difference between
;; normal stdout log messages and the result of the expression we evaluated.
;; This is because if an expression results in the literal value None, the python
;; interpreter will not print out anything.
;; Replacing this hook ensures that the last line in the output after
;; sending a command is the result of the command.
;; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook

;; We also set the `__name__` to something else so `__main__` blocks aren't executed.
(str.join
"\n"
["import sys"
"def conjure_format_output(val):"
" print(repr(val))"
"sys.displayhook = conjure_format_output\n"
"__name__ = '__repl__'"]))

(defn start []
(if (state :repl)
Expand Down Expand Up @@ -238,7 +243,7 @@
(with-repl-or-warn
(fn [repl]
(repl.send
(prep-code update-python-displayhook)
(prep-code initialise-repl-code)
(fn [msgs] nil)
nil)))))

Expand Down
6 changes: 3 additions & 3 deletions lua/conjure/client/python/stdio.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec71272

Please sign in to comment.