Skip to content

Commit c795633

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 c795633

File tree

12 files changed

+83
-237
lines changed

12 files changed

+83
-237
lines changed

README.rst

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Overview
3333

3434
Kconfiglib is a `Kconfig
3535
<https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kconfig-language.rst>`__
36-
implementation in Python 2/3. It started out as a helper library, but now has a
36+
implementation in Python 3. It started out as a helper library, but now has a
3737
enough functionality to also work well as a standalone Kconfig implementation
3838
(including `terminal and GUI menuconfig interfaces <Menuconfig interfaces_>`_
3939
and `Kconfig extensions`_).
@@ -121,9 +121,7 @@ available in the C tools.
121121
the configuration and (optionally) information that can be used to rebuild only
122122
files that reference Kconfig symbols that have changed value.
123123

124-
Starting with Kconfiglib version 12.2.0, all utilities are compatible with both
125-
Python 2 and Python 3. Previously, ``menuconfig.py`` only ran under Python 3
126-
(i.e., it's now more backwards compatible than before).
124+
All utilities run under Python 3.
127125

128126
**Note:** If you install Kconfiglib with ``pip``'s ``--user`` flag, make sure
129127
that your ``PATH`` includes the directory where the executables end up. You can
@@ -164,18 +162,16 @@ Installation for the Linux kernel
164162

165163
See the module docstring at the top of `kconfiglib.py <https://github.com/zephyrproject-rtos/Kconfiglib/blob/master/kconfiglib.py>`_.
166164

167-
Python version compatibility (2.7/3.2+)
168-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165+
Python version compatibility
166+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169167

170-
Kconfiglib and all utilities run under both Python 2.7 and Python 3.2 and
171-
later. The code mostly uses basic Python features and has no third-party
172-
dependencies, so keeping it backwards-compatible is pretty low effort.
168+
Kconfiglib and all utilities run under Python 3.9 and later. The code mostly
169+
uses basic Python features and has no third-party dependencies.
173170

174171
The 3.2 requirement comes from ``argparse``. ``format()`` with unnumbered
175172
``{}`` is used as well.
176173

177-
A recent Python 3 version is recommended if you have a choice, as it'll give
178-
you better Unicode handling.
174+
A recent Python 3 version is recommended for better Unicode handling.
179175

180176
Getting started
181177
---------------
@@ -502,9 +498,9 @@ Other features
502498

503499
- **Windows support**
504500

505-
Nothing Linux-specific is used. Universal newlines mode is used for both
506-
Python 2 and Python 3.
507-
501+
Nothing Linux-specific is used. Universal newlines mode is used for
502+
interoperability between Linux and Windows.
503+
508504
The `Zephyr <https://www.zephyrproject.org/>`_ project uses Kconfiglib to
509505
generate ``.config`` files and C headers on Linux as well as Windows.
510506

@@ -562,16 +558,15 @@ Three configuration interfaces are currently available:
562558
the terminal menuconfig. Only this mode distinguishes between symbols defined
563559
with ``config`` and symbols defined with ``menuconfig``.
564560

565-
``guiconfig.py`` has been tested on X11, Windows, and macOS, and is
566-
compatible with both Python 2 and Python 3.
561+
``guiconfig.py`` has been tested on X11, Windows, and macOS.
567562

568563
Despite being part of the Python standard library, ``tkinter`` often isn't
569564
included by default in Python installations on Linux. These commands will
570565
install it on a few different distributions:
571566

572-
- Ubuntu: ``sudo apt install python-tk``/``sudo apt install python3-tk``
567+
- Ubuntu: ``sudo apt install python3-tk``
573568

574-
- Fedora: ``dnf install python2-tkinter``/``dnf install python3-tkinter``
569+
- Fedora: ``dnf install python3-tkinter``
575570

576571
- Arch: ``sudo pacman -S tk``
577572

@@ -591,10 +586,6 @@ Three configuration interfaces are currently available:
591586
I did my best with the images, but some are definitely only art adjacent.
592587
Touch-ups are welcome. :)
593588

594-
- `pymenuconfig <https://github.com/RomaVis/pymenuconfig>`_, built by `RomaVis
595-
<https://github.com/RomaVis>`_, is an older portable Python 2/3 TkInter
596-
menuconfig implementation.
597-
598589
Screenshot below:
599590

600591
.. image:: https://raw.githubusercontent.com/RomaVis/pymenuconfig/master/screenshot.PNG
@@ -784,7 +775,7 @@ configurations generated by the C tools, for a number of cases. See
784775
for the available options.
785776

786777
The `tests/reltest <https://github.com/zephyrproject-rtos/Kconfiglib/blob/master/tests/reltest>`_ script runs the test suite
787-
and all the example scripts for both Python 2 and Python 3, verifying that everything works.
778+
and all the example scripts, verifying that everything works.
788779

789780
Rarely, the output from the C tools is changed slightly (most recently due to a
790781
`change <https://www.spinics.net/lists/linux-kbuild/msg17074.html>`_ I added).

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

genconfig.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,15 @@ def main():
131131
kconf.sync_deps(args.sync_deps)
132132

133133
if args.file_list is not None:
134-
with _open_write(args.file_list) as f:
134+
with open(args.file_list, "w", encoding="utf-8") as f:
135135
for path in kconf.kconfig_filenames:
136136
f.write(path + "\n")
137137

138138
if args.env_list is not None:
139-
with _open_write(args.env_list) as f:
139+
with open(args.env_list, "w", encoding="utf-8") as f:
140140
for env_var in kconf.env_vars:
141141
f.write("{}={}\n".format(env_var, os.environ[env_var]))
142142

143143

144-
def _open_write(path):
145-
# Python 2/3 compatibility. io.open() is available on both, but makes
146-
# write() expect 'unicode' strings on Python 2.
147-
148-
if sys.version_info[0] < 3:
149-
return open(path, "w")
150-
return open(path, "w", encoding="utf-8")
151-
152-
153144
if __name__ == "__main__":
154145
main()

guiconfig.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
A Tkinter-based menuconfig implementation, based around a treeview control and
1111
a help display. The interface should feel familiar to people used to qconf
12-
('make xconfig'). Compatible with both Python 2 and Python 3.
12+
('make xconfig').
1313
1414
The display can be toggled between showing the full tree and showing just a
1515
single menu (like menuconfig.py). Only single-menu mode distinguishes between
@@ -55,23 +55,11 @@
5555
import errno
5656
import os
5757
import re
58-
import sys
59-
60-
_PY2 = sys.version_info[0] < 3
61-
62-
if _PY2:
63-
# Python 2
64-
from Tkinter import *
65-
import ttk
66-
import tkFont as font
67-
import tkFileDialog as filedialog
68-
import tkMessageBox as messagebox
69-
else:
70-
# Python 3
71-
from tkinter import *
72-
import tkinter.ttk as ttk
73-
import tkinter.font as font
74-
from tkinter import filedialog, messagebox
58+
59+
from tkinter import *
60+
import tkinter.ttk as ttk
61+
import tkinter.font as font
62+
from tkinter import filedialog, messagebox
7563

7664
from kconfiglib import Symbol, Choice, MENU, COMMENT, MenuNode, \
7765
BOOL, TRISTATE, STRING, INT, HEX, \
@@ -395,8 +383,7 @@ def _init_misc_ui():
395383
# Does misc. UI initialization, like setting the title, icon, and theme
396384

397385
_root.title(_kconf.mainmenu_text)
398-
# iconphoto() isn't available in Python 2's Tkinter
399-
_root.tk.call("wm", "iconphoto", _root._w, "-default", _icon_img)
386+
_root.iconphoto(True, _icon_img)
400387
# Reducing the width of the window to 1 pixel makes it move around, at
401388
# least on GNOME. Prevent weird stuff like that.
402389
_root.minsize(128, 128)
@@ -514,9 +501,7 @@ def tree_select(_):
514501
desc["state"] = "disabled"
515502
return
516503

517-
# Text.replace() is not available in Python 2's Tkinter
518-
desc.delete("1.0", "end")
519-
desc.insert("end", _info_str(_id_to_node[sel[0]]))
504+
desc.replace("1.0", "end", _info_str(_id_to_node[sel[0]]))
520505

521506
desc["state"] = "disabled"
522507

@@ -1118,11 +1103,6 @@ def _change_node(node, parent):
11181103
if sc.type in (INT, HEX, STRING):
11191104
s = _set_val_dialog(node, parent)
11201105

1121-
# Tkinter can return 'unicode' strings on Python 2, which Kconfiglib
1122-
# can't deal with. UTF-8-encode the string to work around it.
1123-
if _PY2 and isinstance(s, unicode):
1124-
s = s.encode("utf-8", "ignore")
1125-
11261106
if s is not None:
11271107
_set_val(sc, s)
11281108

@@ -1174,9 +1154,10 @@ def _set_val_dialog(node, parent):
11741154
# Pops up a dialog for setting the value of the string/int/hex
11751155
# symbol at node 'node'. 'parent' is the parent window.
11761156

1157+
_entry_res = None
1158+
11771159
def ok(_=None):
1178-
# No 'nonlocal' in Python 2
1179-
global _entry_res
1160+
nonlocal _entry_res
11801161

11811162
s = entry.get()
11821163
if sym.type == HEX and not s.startswith(("0x", "0X")):
@@ -1187,7 +1168,7 @@ def ok(_=None):
11871168
dialog.destroy()
11881169

11891170
def cancel(_=None):
1190-
global _entry_res
1171+
nonlocal _entry_res
11911172
_entry_res = None
11921173
dialog.destroy()
11931174

0 commit comments

Comments
 (0)