Skip to content

Commit

Permalink
Add support for Python 3.14.0-alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
progval authored Dec 20, 2024
1 parent ab25c3e commit e57f7eb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
strategy:
matrix:
include:
- python-version: "3.14.0-alpha.1"
with-opt-deps: true
runs-on: ubuntu-22.04

- python-version: "3.13.0"
with-opt-deps: true
runs-on: ubuntu-22.04
Expand Down
8 changes: 2 additions & 6 deletions src/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,12 +1355,8 @@ def __init__(self, target=None, args=(), kwargs={}):
pn,
cn)
log.debug('Spawning process %s (args: %r)', procName, args)
self.__parent = super(CommandProcess, self)
self.__parent.__init__(target=target, name=procName,
args=args, kwargs=kwargs)

def run(self):
self.__parent.run()
super().__init__(target=target, name=procName,
args=args, kwargs=kwargs)

class CanonicalString(registry.NormalizedString):
def normalize(self, s):
Expand Down
32 changes: 17 additions & 15 deletions src/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ def _rlimit_min(a, b):
else:
return min(soft, heap_size)

def _process_target(f, q, heap_size, *args, **kwargs):
"""Called by :func:`process`"""
if resource:
rsrc = resource.RLIMIT_DATA
(soft, hard) = resource.getrlimit(rsrc)
soft = _rlimit_min(soft, heap_size)
hard = _rlimit_min(hard, heap_size)
resource.setrlimit(rsrc, (soft, hard))
try:
r = f(*args, **kwargs)
q.put([False, r])
except Exception as e:
q.put([True, e])

def process(f, *args, **kwargs):
"""Runs a function <f> in a subprocess.
Expand Down Expand Up @@ -122,21 +136,9 @@ def process(f, *args, **kwargs):
'(See https://github.com/travis-ci/travis-core/issues/187\n'
'for more information about this bug.)\n')
raise
def newf(f, q, *args, **kwargs):
if resource:
rsrc = resource.RLIMIT_DATA
(soft, hard) = resource.getrlimit(rsrc)
soft = _rlimit_min(soft, heap_size)
hard = _rlimit_min(hard, heap_size)
resource.setrlimit(rsrc, (soft, hard))
try:
r = f(*args, **kwargs)
q.put([False, r])
except Exception as e:
q.put([True, e])
targetArgs = (f, q,) + args
p = callbacks.CommandProcess(target=newf,
args=targetArgs, kwargs=kwargs)
targetArgs = (f, q, heap_size) + args
p = callbacks.CommandProcess(target=_process_target,
args=targetArgs, kwargs=kwargs)
try:
p.start()
except OSError as e:
Expand Down
8 changes: 8 additions & 0 deletions src/utils/math_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ def visit_Expression(self, node):
return self.visit(node.body)

def visit_Num(self, node):
"""Python < 3.14 only"""
return self._convert_num(node.n)

def visit_Constant(self, node):
"""Python >= 3.14 only"""
if type(node.value) in (float, complex, int):
return self._convert_num(node.value)
else:
raise InvalidNode('illegal constant %s' % node.value)

def visit_Name(self, node):
id_ = node.id.lower()
if id_ in self._env:
Expand Down
4 changes: 2 additions & 2 deletions src/utils/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ def perlReToReplacer(s):
flags = ''.join(flags)
r = perlReToPythonRe(sep.join(('', regexp, flags)))
if g:
return lambda s: r.sub(replace, s)
return functools.partial(r.sub, replace)
else:
return lambda s: r.sub(replace, s, 1)
return functools.partial(r.sub, replace, count=1)

_perlVarSubstituteRe = re.compile(r'\$\{([^}]+)\}|\$([a-zA-Z][a-zA-Z0-9]*)')
def perlVariableSubstitute(vars, text):
Expand Down
2 changes: 1 addition & 1 deletion src/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, *args, **kwargs):
log.debug('Spawning thread %q.', self.getName())

processesSpawned = 1 # Starts at one for the initial process.
class SupyProcess(multiprocessing.Process):
class SupyProcess(multiprocessing.get_context('fork').Process):
def __init__(self, *args, **kwargs):
global processesSpawned
processesSpawned += 1
Expand Down

0 comments on commit e57f7eb

Please sign in to comment.