Fix Python 3.12+ compatibility for StrictVersion, pexpect, and test runner
mininet-tests / Mininet Tests (ubuntu-20.04, python2) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-20.04, python3) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-22.04, python2) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-22.04, python3) (push) Canceled after 0s
code-check / Mininet Code Check (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-20.04, python2) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-20.04, python3) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-22.04, python2) (push) Canceled after 0s
mininet-tests / Mininet Tests (ubuntu-22.04, python3) (push) Canceled after 0s
code-check / Mininet Code Check (push) Canceled after 0s
This commit is contained in:
1 parent
d9c8f86889
commit
6f0e0f5e21
4 files changed
+52
-6
No files matched your search
@@ -19,12 +19,13 @@ from mininet.clean import cleanup
|
|||||||
def tsharkVersion():
|
def tsharkVersion():
|
||||||
"Return tshark version"
|
"Return tshark version"
|
||||||
versionStr = quietRun( 'tshark -v' )
|
versionStr = quietRun( 'tshark -v' )
|
||||||
versionMatch = re.findall( r'TShark[^\d]*(\d+.\d+.\d+)', versionStr )
|
versionMatch = re.findall( r'TShark[^\d]*(\d+\.\d+\.\d+)', versionStr )
|
||||||
return versionMatch[ 0 ]
|
return versionMatch[ 0 ] if versionMatch else '0.0.0'
|
||||||
|
|
||||||
# pylint doesn't understand pexpect.match, unfortunately!
|
# pylint doesn't understand pexpect.match, unfortunately!
|
||||||
# pylint:disable=maybe-no-member
|
# pylint:disable=maybe-no-member
|
||||||
|
|
||||||
|
@unittest.skipIf( pexpect is None, 'pexpect is not installed' )
|
||||||
class testWalkthrough( unittest.TestCase ):
|
class testWalkthrough( unittest.TestCase ):
|
||||||
"Test Mininet walkthrough"
|
"Test Mininet walkthrough"
|
||||||
|
|
||||||
|
|||||||
+46
-1
@@ -59,8 +59,53 @@ try:
|
|||||||
import packaging.version # replacement for distutils.version
|
import packaging.version # replacement for distutils.version
|
||||||
StrictVersion = packaging.version.parse
|
StrictVersion = packaging.version.parse
|
||||||
except ImportError: # python2.7 lacks ModuleNotFoundError
|
except ImportError: # python2.7 lacks ModuleNotFoundError
|
||||||
|
try:
|
||||||
import distutils.version # pylint: disable=deprecated-module
|
import distutils.version # pylint: disable=deprecated-module
|
||||||
StrictVersion = distutils.version.StrictVersion
|
StrictVersion = distutils.version.StrictVersion
|
||||||
|
except ( ImportError, AttributeError ):
|
||||||
|
import re
|
||||||
|
|
||||||
|
class FallbackStrictVersion( object ):
|
||||||
|
"Fallback version comparator when packaging/distutils are unavailable"
|
||||||
|
def __init__( self, vstring=None ):
|
||||||
|
self.vstring = str( vstring ) if vstring is not None else ''
|
||||||
|
self.version = self._parse( self.vstring )
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse( vstring ):
|
||||||
|
components = re.findall( r'\d+|\D+', vstring.strip() )
|
||||||
|
return tuple( int( c ) if c.isdigit() else c for c in components )
|
||||||
|
|
||||||
|
def __lt__( self, other ):
|
||||||
|
other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) )
|
||||||
|
return self.version < other_ver
|
||||||
|
|
||||||
|
def __le__( self, other ):
|
||||||
|
other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) )
|
||||||
|
return self.version <= other_ver
|
||||||
|
|
||||||
|
def __gt__( self, other ):
|
||||||
|
other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) )
|
||||||
|
return self.version > other_ver
|
||||||
|
|
||||||
|
def __ge__( self, other ):
|
||||||
|
other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) )
|
||||||
|
return self.version >= other_ver
|
||||||
|
|
||||||
|
def __eq__( self, other ):
|
||||||
|
other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) )
|
||||||
|
return self.version == other_ver
|
||||||
|
|
||||||
|
def __ne__( self, other ):
|
||||||
|
return not self.__eq__( other )
|
||||||
|
|
||||||
|
def __repr__( self ):
|
||||||
|
return "StrictVersion('%s')" % self.vstring
|
||||||
|
|
||||||
|
def __str__( self ):
|
||||||
|
return self.vstring
|
||||||
|
|
||||||
|
StrictVersion = FallbackStrictVersion
|
||||||
|
|
||||||
try:
|
try:
|
||||||
oldpexpect = None
|
oldpexpect = None
|
||||||
@@ -79,7 +124,7 @@ try:
|
|||||||
return getattr( oldpexpect, name )
|
return getattr( oldpexpect, name )
|
||||||
pexpect = Pexpect()
|
pexpect = Pexpect()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pexpect = None
|
||||||
|
|
||||||
|
|
||||||
# Command execution support
|
# Command execution support
|
||||||
|
|||||||
+2
-2
@@ -190,7 +190,7 @@ function mn_deps {
|
|||||||
|
|
||||||
$install gcc make socat psmisc xterm ssh iperf telnet \
|
$install gcc make socat psmisc xterm ssh iperf telnet \
|
||||||
ethtool help2man $pf pylint $pep8 \
|
ethtool help2man $pf pylint $pep8 \
|
||||||
net-tools ${PYPKG}-tk
|
net-tools ${PYPKG}-tk ${PYPKG}-packaging || true
|
||||||
|
|
||||||
# Install pip
|
# Install pip
|
||||||
$install ${PYPKG}-pip || $install ${PYPKG}-pip-whl
|
$install ${PYPKG}-pip || $install ${PYPKG}-pip-whl
|
||||||
@@ -203,7 +203,7 @@ function mn_deps {
|
|||||||
sudo ${PYTHON} get-pip.py
|
sudo ${PYTHON} get-pip.py
|
||||||
rm get-pip.py
|
rm get-pip.py
|
||||||
fi
|
fi
|
||||||
${python} -m pip install pexpect
|
${PYTHON} -m pip install pexpect || true
|
||||||
$install iproute2 || $install iproute
|
$install iproute2 || $install iproute
|
||||||
$install cgroup-tools || $install cgroup-bin
|
$install cgroup-tools || $install cgroup-bin
|
||||||
$install cgroupfs-mount
|
$install cgroupfs-mount
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ version = 'Mininet ' + run( 'PYTHONPATH=. bin/mn --version 2>&1', shell=True )
|
|||||||
version = version.strip()
|
version = version.strip()
|
||||||
|
|
||||||
# Find all Mininet path references
|
# Find all Mininet path references
|
||||||
lines = run( "egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True )
|
lines = run( r"egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True )
|
||||||
|
|
||||||
error = False
|
error = False
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user