Skip to content

Commit

Permalink
Fix py11 and 12 support
Browse files Browse the repository at this point in the history
* Remove relevant usage of `six.moves` in ramble and vendored deps
* Update `py` dep to the latest [head](https://github.com/pytest-dev/py/tree/6b219734fcd8d2f6489c2f50585a435b34c029c2/py), due to pytest-dev/py#273.
  • Loading branch information
linsword13 committed May 31, 2024
1 parent 2cce1a7 commit 3ea9e25
Show file tree
Hide file tree
Showing 52 changed files with 1,343 additions and 356 deletions.
34 changes: 19 additions & 15 deletions lib/ramble/external/py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@
(c) Holger Krekel and others, 2004-2014
"""
__version__ = '1.4.34'
from py._error import error

from py import _apipkg
try:
from py._vendored_packages import apipkg
lib_not_mangled_by_packagers = True
vendor_prefix = '._vendored_packages.'
except ImportError:
import apipkg
lib_not_mangled_by_packagers = False
vendor_prefix = ''

# so that py.error.* instances are picklable
import sys
sys.modules['py.error'] = _apipkg.AliasModule("py.error", "py._error", 'error')
import py.error # "Dereference" it now just to be safe (issue110)
try:
from ._version import version as __version__
except ImportError:
# broken installation, we don't even try
__version__ = "unknown"


_apipkg.initpkg(__name__, attr={'_apipkg': _apipkg}, exportdefs={
apipkg.initpkg(__name__, attr={'_apipkg': apipkg, 'error': error}, exportdefs={
# access to all standard lib modules
'std': '._std:std',
# access to all posix errno's as classes
'error': '._error:error',

'_pydir' : '.__metainfo:pydir',
'version': 'py:__version__', # backward compatibility

# pytest-2.0 has a flat namespace, we use alias modules
# to keep old references compatible
'test' : 'pytest',
'test.collect' : 'pytest',
'test.cmdline' : 'pytest',

# hook into the top-level standard library
'process' : {
Expand All @@ -42,13 +46,13 @@
},

'apipkg' : {
'initpkg' : '._apipkg:initpkg',
'ApiModule' : '._apipkg:ApiModule',
'initpkg' : vendor_prefix + 'apipkg:initpkg',
'ApiModule' : vendor_prefix + 'apipkg:ApiModule',
},

'iniconfig' : {
'IniConfig' : '._iniconfig:IniConfig',
'ParseError' : '._iniconfig:ParseError',
'IniConfig' : vendor_prefix + 'iniconfig:IniConfig',
'ParseError' : vendor_prefix + 'iniconfig:ParseError',
},

'path' : {
Expand Down
20 changes: 20 additions & 0 deletions lib/ramble/external/py/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any

# py allows to use e.g. py.path.local even without importing py.path.
# So import implicitly.
from . import error
from . import iniconfig
from . import path
from . import io
from . import xml

__version__: str

# Untyped modules below here.
std: Any
test: Any
process: Any
apipkg: Any
code: Any
builtin: Any
log: Any
123 changes: 12 additions & 111 deletions lib/ramble/external/py/_builtin.py
Original file line number Diff line number Diff line change
@@ -1,120 +1,21 @@
import sys

try:
reversed = reversed
except NameError:
def reversed(sequence):
"""reversed(sequence) -> reverse iterator over values of the sequence
Return a reverse iterator
"""
if hasattr(sequence, '__reversed__'):
return sequence.__reversed__()
if not hasattr(sequence, '__getitem__'):
raise TypeError("argument to reversed() must be a sequence")
return reversed_iterator(sequence)

class reversed_iterator(object):

def __init__(self, seq):
self.seq = seq
self.remaining = len(seq)

def __iter__(self):
return self

def next(self):
i = self.remaining
if i > 0:
i -= 1
item = self.seq[i]
self.remaining = i
return item
raise StopIteration

def __length_hint__(self):
return self.remaining

try:
any = any
except NameError:
def any(iterable):
for x in iterable:
if x:
return True
return False

try:
all = all
except NameError:
def all(iterable):
for x in iterable:
if not x:
return False
return True

try:
sorted = sorted
except NameError:
builtin_cmp = cmp # need to use cmp as keyword arg

def sorted(iterable, cmp=None, key=None, reverse=0):
use_cmp = None
if key is not None:
if cmp is None:
def use_cmp(x, y):
return builtin_cmp(x[0], y[0])
else:
def use_cmp(x, y):
return cmp(x[0], y[0])
l = [(key(element), element) for element in iterable]
else:
if cmp is not None:
use_cmp = cmp
l = list(iterable)
if use_cmp is not None:
l.sort(use_cmp)
else:
l.sort()
if reverse:
l.reverse()
if key is not None:
return [element for (_, element) in l]
return l

try:
set, frozenset = set, frozenset
except NameError:
from sets import set, frozenset

# pass through
enumerate = enumerate

try:
BaseException = BaseException
except NameError:
BaseException = Exception

try:
GeneratorExit = GeneratorExit
except NameError:
class GeneratorExit(Exception):
""" This exception is never raised, it is there to make it possible to
write code compatible with CPython 2.5 even in lower CPython
versions."""
pass
GeneratorExit.__module__ = 'exceptions'

# Passthrough for builtins supported with py27.
BaseException = BaseException
GeneratorExit = GeneratorExit
_sysex = (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit)
all = all
any = any
callable = callable
enumerate = enumerate
reversed = reversed
set, frozenset = set, frozenset
sorted = sorted

try:
callable = callable
except NameError:
def callable(obj):
return hasattr(obj, "__call__")

if sys.version_info >= (3, 0):
exec ("print_ = print ; exec_=exec")
exec("print_ = print ; exec_=exec")
import builtins

# some backward compatibility helpers
Expand All @@ -131,13 +32,13 @@ def _totext(obj, encoding=None, errors=None):

def _isbytes(x):
return isinstance(x, bytes)

def _istext(x):
return isinstance(x, str)

text = str
bytes = bytes


def _getimself(function):
return getattr(function, '__self__', None)

Expand Down
25 changes: 4 additions & 21 deletions lib/ramble/external/py/_code/_assertionnew.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,10 @@
from py._code.assertion import _format_explanation, BuiltinAssertionError


if sys.platform.startswith("java") and sys.version_info < (2, 5, 2):
# See http://bugs.jython.org/issue1497
_exprs = ("BoolOp", "BinOp", "UnaryOp", "Lambda", "IfExp", "Dict",
"ListComp", "GeneratorExp", "Yield", "Compare", "Call",
"Repr", "Num", "Str", "Attribute", "Subscript", "Name",
"List", "Tuple")
_stmts = ("FunctionDef", "ClassDef", "Return", "Delete", "Assign",
"AugAssign", "Print", "For", "While", "If", "With", "Raise",
"TryExcept", "TryFinally", "Assert", "Import", "ImportFrom",
"Exec", "Global", "Expr", "Pass", "Break", "Continue")
_expr_nodes = set(getattr(ast, name) for name in _exprs)
_stmt_nodes = set(getattr(ast, name) for name in _stmts)
def _is_ast_expr(node):
return node.__class__ in _expr_nodes
def _is_ast_stmt(node):
return node.__class__ in _stmt_nodes
else:
def _is_ast_expr(node):
return isinstance(node, ast.expr)
def _is_ast_stmt(node):
return isinstance(node, ast.stmt)
def _is_ast_expr(node):
return isinstance(node, ast.expr)
def _is_ast_stmt(node):
return isinstance(node, ast.stmt)


class Failure(Exception):
Expand Down
3 changes: 2 additions & 1 deletion lib/ramble/external/py/_code/_assertionold.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys, inspect
from compiler import parse, ast, pycodegen
from py._code.assertion import BuiltinAssertionError, _format_explanation
import types

passthroughex = py.builtin._sysex

Expand Down Expand Up @@ -470,7 +471,7 @@ def check(s, frame=None):
def interpret(source, frame, should_fail=False):
module = Interpretable(parse(source, 'exec').node)
#print "got module", module
if isinstance(frame, py.std.types.FrameType):
if isinstance(frame, types.FrameType):
frame = py.code.Frame(frame)
try:
module.run(frame)
Expand Down
6 changes: 1 addition & 5 deletions lib/ramble/external/py/_code/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,4 @@ def __init__(self, *args):
reinterpret_old = "old reinterpretation not available for py3"
else:
from py._code._assertionold import interpret as reinterpret_old
if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
from py._code._assertionnew import interpret as reinterpret
else:
reinterpret = reinterpret_old

from py._code._assertionnew import interpret as reinterpret
Loading

0 comments on commit 3ea9e25

Please sign in to comment.