Skip to content

Commit 00569d0

Browse files
committed
Python Session: drop python2 support
1 parent d279e7d commit 00569d0

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

plugins/python/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ If you have permissions for `$TEXMACS_PATH/plugins/python/progs/init-python.scm`
2929
Here is the detailed example of changing the python command:
3030

3131
``` scheme
32-
(define (python-command)
33-
(if (url-exists-in-path? "python3") "python3" "python2"))
32+
(define (python-command) "python3")
3433
```
3534

36-
By default, we prefer `python3`. To use a specific python version, just change the return value of the `(python-commond)` function.
35+
By default, we use `python3`. To use a specific python version, just change the return value of the `(python-commond)` function.
3736

3837
``` scheme
3938
(define (python-command) "/path/to/python")

plugins/python/progs/init-python.scm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
(with s (texmacs->code (stree->tree u) "SourceCode")
3232
(string-append s "\n<EOF>\n"))))
3333

34-
(define (python-command)
35-
(if (url-exists-in-path? "python3") "python3" "python2"))
34+
(define (python-command) "python3")
3635

3736
(define (python-exists?)
38-
(or (url-exists-in-path? "python3")
39-
(url-exists-in-path? "python2")))
37+
(url-exists-in-path? "python3"))
4038

4139
(define (python-launcher)
4240
(if (url-exists? "$TEXMACS_HOME_PATH/plugins/tmpy")

plugins/tmpy/session/tm_python.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# COPYRIGHT : (C) 2004 Ero Carrera, ero@dkbza.org
77
# (C) 2012 Adrian Soto
88
# (C) 2014 Miguel de Benito Delgado, mdbenito@texmacs.org
9-
# (C) 2018-2019 Darcy Shen
9+
# (C) 2018-2020 Darcy Shen
1010
#
1111
# This software falls under the GNU general public license version 3 or later.
1212
# It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
@@ -22,27 +22,30 @@
2222
sys.path.append(os.environ.get("TEXMACS_PATH") + "/plugins/")
2323

2424

25+
2526
import traceback
2627
import string
2728
from inspect import ismodule, getsource, getsourcefile
29+
from tmpy.compat import py_ver
2830
from tmpy.capture import CaptureStdout
2931
from tmpy.postscript import ps_out
3032
from tmpy.completion import parse_complete_command, complete
31-
from tmpy.compat import *
3233
from tmpy.protocol import *
3334

35+
if py_ver == 2:
36+
flush_err ("Python 2 is no longer supported, please use Python 3")
37+
exit (-1)
38+
3439
# import logging as log
3540
# log.basicConfig(filename='/tmp/tm_python.log',level=log.DEBUG)
36-
def compose_output(data):
41+
def compose_output (data):
3742
"""Do some parsing on the output according to its type.
3843
3944
Non printable characters in unicode strings are escaped
4045
and objects of type None are not printed (so that procedure calls,
4146
as opposed to function calls, don't produce any output)."""
4247

43-
if py_ver == 3: cl = str
44-
else: cl = unicode
45-
if isinstance(data, cl):
48+
if isinstance(data, str):
4649
data2 = r''
4750
for c in data:
4851
if c not in string.printable:
@@ -82,8 +85,8 @@ def compile_help (text):
8285

8386
return dict (map (lambda k_v: (k_v[0], as_scm_string (k_v[1])), out.items()))
8487

85-
__version__ = '1.14'
86-
__author__ = 'Ero Carrera, Adrian Soto, Miguel de Benito Delgado'
88+
__version__ = '3.0'
89+
__author__ = 'Ero Carrera, Adrian Soto, Miguel de Benito Delgado, Darcy Shen'
8790
my_globals = {}
8891

8992
# We insert into the session's namespace the 'ps_out' method.
@@ -96,17 +99,10 @@ def compile_help (text):
9699
A rudimentary help window is also implemented: type the name of an object
97100
with a question mark at the end to use it."""
98101

99-
if py_ver == 3:
100-
text = 'import builtins as __builtins__'
101-
else:
102-
text = 'import __builtin__ as __builtins__'
102+
text = 'import builtins as __builtins__'
103103
CaptureStdout.capture (text, my_globals, "tm_python")
104104

105-
if py_ver == 3:
106-
sys.stdout = os.fdopen (sys.stdout.fileno(), 'w')
107-
else:
108-
sys.stdout = os.fdopen (sys.stdout.fileno(), 'w', 0)
109-
105+
sys.stdout = os.fdopen (sys.stdout.fileno(), 'w')
110106

111107
###############################################################################
112108
# Session start
@@ -119,7 +115,7 @@ def compile_help (text):
119115
"Please see the documentation in Help -> Plugins -> Python")
120116
flush_prompt (">>> ")
121117
while True:
122-
line = tm_input()
118+
line = input ()
123119
if not line:
124120
continue
125121
if line[0] == DATA_COMMAND:
@@ -138,14 +134,13 @@ def compile_help (text):
138134
else:
139135
lines = [line]
140136
while line != "<EOF>":
141-
line = tm_input()
137+
line = input ()
142138
if line == '':
143139
continue
144-
lines.append(line)
145-
text = '\n'.join(lines[:-1])
140+
lines.append (line)
141+
text = '\n'.join (lines[:-1])
146142
try: # Is it an expression?
147-
result = eval(text, my_globals)
143+
result = eval (text, my_globals)
148144
except:
149-
result = CaptureStdout.capture(text, my_globals, "tm_python")
145+
result = CaptureStdout.capture (text, my_globals, "tm_python")
150146
flush_verbatim (compose_output(result))
151-

0 commit comments

Comments
 (0)