Skip to content

Commit 297145d

Browse files
committed
sagews-fix-python-3.12
1 parent 1f84c73 commit 297145d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/smc_sagews/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def readme():
77

88
setup(
99
name='smc_sagews',
10-
version='1.1',
10+
version='1.2',
1111
description='CoCalc Worksheets',
1212
long_description=readme(),
1313
url='https://github.com/sagemathinc/cocalc',
@@ -28,6 +28,7 @@ def readme():
2828
'Programming Language :: Python :: 2.7',
2929
'Programming Language :: Python :: 3.6',
3030
'Programming Language :: Python :: 3.7',
31+
'Programming Language :: Python :: 3.12',
3132
'Topic :: Mathematics :: Server',
3233
],
3334
keywords='server mathematics cloud',

src/smc_sagews/smc_sagews/sage_salvus.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
# set backend of matplot lib before any other module is loaded
1919
import matplotlib
20-
import imp
2120
matplotlib.use('Agg')
2221

2322
import copy, os, sys, types, re
@@ -2569,6 +2568,12 @@ def f():
25692568
# Run some commands to tell Sage that its
25702569
# pid has changed.
25712570
import sage.misc.misc
2571+
2572+
# since python 3.12, there is no imp
2573+
try:
2574+
import imp
2575+
except:
2576+
import importlib as imp
25722577
imp.reload(sage.misc.misc)
25732578

25742579
# The pexpect interfaces (and objects defined in them) are
@@ -3369,7 +3374,7 @@ def var0(*args, **kwds):
33693374

33703375

33713376
def var(*args, **kwds):
3372-
"""
3377+
r"""
33733378
Create symbolic variables and inject them into the global namespace.
33743379
33753380
NOTE: In CoCalc, you can use var as a line decorator::

src/smc_sagews/smc_sagews/sage_server.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ def unicode8(s):
6363
def log(*args):
6464
try:
6565
debug_log = open(LOGFILE, 'a')
66-
mesg = "%s (%s): %s\n" % (PID, datetime.utcnow().strftime(
67-
'%Y-%m-%d %H:%M:%S.%f')[:-3], ' '.join([unicode8(x)
68-
for x in args]))
66+
from sys import version_info
67+
if version_info >= (3, 12):
68+
from datetime import UTC
69+
d = datetime.now(UTC)
70+
else:
71+
d = datetime.utcnow()
72+
d_txt = d.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
73+
args_str = ' '.join([unicode8(x) for x in args])
74+
mesg = "%s (%s): %s\n" % (PID, d_txt, args_str)
6975
debug_log.write(mesg)
7076
debug_log.flush()
7177
except Exception as err:

0 commit comments

Comments
 (0)