Skip to content

Commit

Permalink
add formal support for python 3.13 (#34)
Browse files Browse the repository at this point in the history
* add formal support for python 3.13

* use f_locals to update locals

* use 3.13-dev on travis
  • Loading branch information
mmckerns authored Sep 23, 2024
1 parent ac2a71f commit cd05135
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ matrix:
- python: 'pypy3.8-7.3.9' # at 7.3.11
env:

- python: 'pypy3.9-7.3.9' # at 7.3.15
- python: 'pypy3.9-7.3.9' # at 7.3.16
env:

- python: 'pypy3.10-7.3.15'
- python: 'pypy3.10-7.3.17'
env:

allow_failures:
- python: '3.13-dev'
- python: 'pypy3.10-7.3.15' # CI missing
- python: 'pypy3.10-7.3.17' # CI missing
fast_finish: true

cache:
Expand Down
48 changes: 39 additions & 9 deletions pygrace/interactive/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
Get help >>> pg.doc()
'''

import sys
if sys.hexversion < 0x30d00b1:
_f_locals = None
else:
def _f_locals(name, val):
"update enclosing locals, given https://peps.python.org/pep-0667"
sys._getframe(1).f_locals[name] = val
return

from math import *
from numpy import *

Expand Down Expand Up @@ -125,8 +134,8 @@ def _exists(self,name):

def doc(self):
print(self.__doc__)
print(__license__[:153]) # print copyright
print(__license__[-291:]) # print reference
#print(__license__[:153]) # print copyright
#print(__license__[-291:]) # print reference
return

def restart(self):
Expand All @@ -148,15 +157,21 @@ def put(self,name,val):
code += var+" = self._getlocal('"+var+"')"
code = compile(code, '<string>', 'exec')
exec(code, _locals)
locals()[var] = _locals[var]
if _f_locals is None:
locals()[var] = _locals[var]
else:
_f_locals(var, _locals[var])
if (type(val) is type(array([]))):
val = val.tolist()
code = 'from math import *; from numpy import *;'
code += name+' = array('+str(val)+')'
else: code = name+' = '+str(val)
code = compile(code, '<string>', 'exec')
exec(code, _locals)
locals()[name] = _locals[name]
if _f_locals is None:
locals()[name] = _locals[name]
else:
_f_locals(name, _locals[name])
for var in varlist: #use varlist to update state variables
_locals[var] = locals()[var]
code = 'from math import *; from numpy import *;'
Expand All @@ -177,7 +192,10 @@ def get(self,name):
code += var+" = self._getlocal('"+var+"')"
code = compile(code, '<string>', 'exec')
exec(code, _locals)
locals()[var] = _locals[var]
if _f_locals is None:
locals()[var] = _locals[var]
else:
_f_locals(var, _locals[var])
code = 'from math import *; from numpy import *;'
code += '___ = '+name
code = compile(code, '<string>', 'exec')
Expand Down Expand Up @@ -216,7 +234,10 @@ def eval(self,com):
code += 'outlist.append("'+name+'")'
code = compile(code, '<string>', 'exec')
exec(code, _locals)
locals()[name] = _locals[name]
if _f_locals is None:
locals()[name] = _locals[name]
else:
_f_locals(name, _locals[name])
outlist[:] = _locals['outlist']
if com == 'exit':
return
Expand All @@ -232,7 +253,10 @@ def eval(self,com):
name = com.split('=')[0].strip()
if not name.count('['):
outlist.append(name)
locals()[name] = _locals[name]
if _f_locals is None:
locals()[name] = _locals[name]
else:
_f_locals(name, _locals[name])
except:
try: #if intended for gracePlot
code = 'from math import *; from numpy import *;'
Expand Down Expand Up @@ -271,7 +295,10 @@ def prompt(self):
code += 'outlist.append("'+name+'")'
code = compile(code, '<string>', 'exec')
exec(code, _locals)
locals()[name] = _locals[name]
if _f_locals is None:
locals()[name] = _locals[name]
else:
_f_locals(name, _locals[name])
outlist[:] = _locals['outlist']
while 1:
com = input('grace> ')
Expand All @@ -296,7 +323,10 @@ def prompt(self):
name = com.split('=')[0].strip()
if not name.count('['):
outlist.append(name)
locals()[name] = _locals[name]
if _f_locals is None:
locals()[name] = _locals[name]
else:
_f_locals(name, _locals[name])
except:
try: #if intended for gracePlot
code = 'from math import *; from numpy import *;'
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Scientific/Engineering',
Expand Down

0 comments on commit cd05135

Please sign in to comment.