Skip to content

Commit 162f025

Browse files
committed
drop support for Python 2.x as it is very much EOL
A follow-up to b96a5ad where we stopped having CI run tests on Python 2.x. This actually drops the few remaining Python 2.x compatibility bits as Python 2.x has EOL'd a long time ago. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 1e6f644 commit 162f025

File tree

5 files changed

+15
-39
lines changed

5 files changed

+15
-39
lines changed

examples/menuconfig_example.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@
130130
TRI_TO_STR
131131

132132

133-
# Python 2/3 compatibility hack
134-
if sys.version_info[0] < 3:
135-
input = raw_input
136-
137-
138133
def indent_print(s, indent):
139134
print(indent*" " + s)
140135

kconfiglib.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,8 +3926,7 @@ def _open(self, filename, mode):
39263926
# - For Python 3, force the encoding. Forcing the encoding on Python 2
39273927
# turns strings into Unicode strings, which gets messy. Python 2
39283928
# doesn't decode regular strings anyway.
3929-
return open(filename, "rU" if mode == "r" else mode) if _IS_PY2 else \
3930-
open(filename, mode, encoding=self._encoding)
3929+
return open(filename, mode, encoding=self._encoding)
39313930

39323931
def _check_undef_syms(self):
39333932
# Prints warnings for all references to undefined symbols within the
@@ -3956,7 +3955,7 @@ def is_num(s):
39563955

39573956
return True
39583957

3959-
for sym in (self.syms.viewvalues if _IS_PY2 else self.syms.values)():
3958+
for sym in self.syms.values():
39603959
# - sym.nodes empty means the symbol is undefined (has no
39613960
# definition locations)
39623961
#
@@ -6896,12 +6895,11 @@ def _shell_fn(kconf, _, command):
68966895
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
68976896
).communicate()
68986897

6899-
if not _IS_PY2:
6900-
try:
6901-
stdout = stdout.decode(kconf._encoding)
6902-
stderr = stderr.decode(kconf._encoding)
6903-
except UnicodeDecodeError as e:
6904-
_decoding_error(e, kconf.filename, kconf.linenr)
6898+
try:
6899+
stdout = stdout.decode(kconf._encoding)
6900+
stderr = stderr.decode(kconf._encoding)
6901+
except UnicodeDecodeError as e:
6902+
_decoding_error(e, kconf.filename, kconf.linenr)
69056903

69066904
if stderr:
69076905
kconf._warn("'{}' wrote to stderr: {}".format(
@@ -6938,9 +6936,6 @@ def _shell_fn(kconf, _, command):
69386936
# Symbol will do. We test this with 'is'.
69396937
_NO_CACHED_SELECTION = 0
69406938

6941-
# Are we running on Python 2?
6942-
_IS_PY2 = sys.version_info[0] < 3
6943-
69446939
try:
69456940
_UNAME_RELEASE = os.uname()[2]
69466941
except AttributeError:
@@ -7233,11 +7228,11 @@ def _shell_fn(kconf, _, command):
72337228

72347229

72357230
def _re_match(regex):
7236-
return re.compile(regex, 0 if _IS_PY2 else re.ASCII).match
7231+
return re.compile(regex, re.ASCII).match
72377232

72387233

72397234
def _re_search(regex):
7240-
return re.compile(regex, 0 if _IS_PY2 else re.ASCII).search
7235+
return re.compile(regex, re.ASCII).search
72417236

72427237

72437238
# Various regular expressions used during parsing

menuconfig.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,7 @@ def _init():
989989
# Looking for this in addition to KEY_BACKSPACE (which is unreliable) makes
990990
# backspace work with TERM=vt100. That makes it likely to work in sane
991991
# environments.
992-
_ERASE_CHAR = curses.erasechar()
993-
if sys.version_info[0] >= 3:
994-
# erasechar() returns a one-byte bytes object on Python 3. This sets
995-
# _ERASE_CHAR to a blank string if it can't be decoded, which should be
996-
# harmless.
997-
_ERASE_CHAR = _ERASE_CHAR.decode("utf-8", "ignore")
992+
_ERASE_CHAR = curses.erasechar().decode("utf-8", "ignore")
998993

999994
_init_styles()
1000995

oldconfig.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
from kconfiglib import Symbol, Choice, BOOL, TRISTATE, HEX, standard_kconfig
3333

3434

35-
# Python 2/3 compatibility hack
36-
if sys.version_info[0] < 3:
37-
input = raw_input
38-
39-
4035
def _main():
4136
# Earlier symbols in Kconfig files might depend on later symbols and become
4237
# visible if their values change. This flag is set to True if the value of

testsuite.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,16 +2699,12 @@ def verify_bad_argno(name):
26992699

27002700
sys.path.pop(0)
27012701

2702-
# This test can fail on older Python 3.x versions, because they don't
2703-
# preserve dict insertion order during iteration. The output is still
2704-
# correct, just different.
2705-
if not (3, 0) <= sys.version_info <= (3, 5):
2706-
print("Testing KCONFIG_WARN_UNDEF")
2702+
print("Testing KCONFIG_WARN_UNDEF")
27072703

2708-
os.environ["KCONFIG_WARN_UNDEF"] = "y"
2709-
c = Kconfig("Kconfiglib/tests/Kundef", warn_to_stderr=False)
2704+
os.environ["KCONFIG_WARN_UNDEF"] = "y"
2705+
c = Kconfig("Kconfiglib/tests/Kundef", warn_to_stderr=False)
27102706

2711-
verify_equal("\n".join(c.warnings), """
2707+
verify_equal("\n".join(c.warnings), """
27122708
warning: the int symbol INT (defined at Kconfiglib/tests/Kundef:8) has a non-int range [UNDEF_2 (undefined), 8 (undefined)]
27132709
warning: undefined symbol UNDEF_1:
27142710
@@ -2747,7 +2743,7 @@ def verify_bad_argno(name):
27472743
visible if UNDEF_3
27482744
"""[1:-1])
27492745

2750-
os.environ.pop("KCONFIG_WARN_UNDEF")
2746+
os.environ.pop("KCONFIG_WARN_UNDEF")
27512747

27522748

27532749
print("\nAll selftests passed\n" if all_passed else

0 commit comments

Comments
 (0)