Skip to content

Commit f0c6f16

Browse files
jeplerdpgeorge
authored andcommitted
all: Remove Python 2.7 support.
Python 2.7 has been EOL since January 2020. Ubuntu oldoldlts (Focal Fossa, 20.04) has Python 3.8. Debian oldoldstable (Buster, from 2019) has Python 3.7. RHEL 8 (from 2019) has Python 3.6. It's easier than ever to install a modern Python using uv. Given this, it seems like a fine idea to drop Python 2.7 support. Even though the build is not tested on Python as old as 3.3, I left comments stating that "3.3+" is the baseline Python version. However, it might make sense to bump this to e.g., 3.10, the oldest Python 3 version used during CI. Or, using uv or another method actually test on the oldest Python interpreter that is desirable to support (uv goes back to Python 3.7 easily; in October 2025, the oldest supported Python interpreter version will be 3.10) Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent d441788 commit f0c6f16

File tree

12 files changed

+31
-93
lines changed

12 files changed

+31
-93
lines changed

.github/workflows/mpy_format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515

1616
jobs:
1717
test:
18-
runs-on: ubuntu-22.04 # use 22.04 to get python2
18+
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v5
2121
- name: Install packages

.github/workflows/ports_unix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
run: tests/run-tests.py --print-failures
122122

123123
nanbox:
124-
runs-on: ubuntu-22.04 # use 22.04 to get python2, and libffi-dev:i386
124+
runs-on: ubuntu-22.04 # use 22.04 to get libffi-dev:i386
125125
steps:
126126
- uses: actions/checkout@v5
127127
- name: Install packages
@@ -135,7 +135,7 @@ jobs:
135135
run: tests/run-tests.py --print-failures
136136

137137
longlong:
138-
runs-on: ubuntu-22.04 # use 22.04 to get python2, and libffi-dev:i386
138+
runs-on: ubuntu-22.04 # use 22.04 to get libffi-dev:i386
139139
steps:
140140
- uses: actions/checkout@v5
141141
- name: Install packages

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ This repository contains the following components:
8080
- [examples/](examples/) -- a few example Python scripts.
8181

8282
"make" is used to build the components, or "gmake" on BSD-based systems.
83-
You will also need bash, gcc, and Python 3.3+ available as the command `python3`
84-
(if your system only has Python 2.7 then invoke make with the additional option
85-
`PYTHON=python2`). Some ports (rp2 and esp32) additionally use CMake.
83+
You will also need bash, gcc, and Python 3.3+ available as the command `python3`.
84+
Some ports (rp2 and esp32) additionally use CMake.
8685

8786
Supported platforms & architectures
8887
-----------------------------------

docs/develop/gettingstarted.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ See the `ARM GCC
106106
toolchain <https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads>`_
107107
for the latest details.
108108

109-
Python is also required. Python 2 is supported for now, but we recommend using Python 3.
109+
Python 3 is also required.
110110
Check that you have Python available on your system:
111111

112112
.. code-block:: bash

ports/stm32/boards/pllvalues.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def compute_pll2(hse, sys, relax_pll48):
105105
# VCO_OUT must be between 192MHz and 432MHz
106106
if sys * P not in mcu.range_vco_out:
107107
continue
108-
NbyM = float(sys * P) / hse # float for Python 2
108+
NbyM = sys * P / hse
109109
# scan M
110110
M_min = mcu.range_n[0] // int(round(NbyM)) # starting value
111111
while mcu.range_vco_in[-1] * M_min < hse:
@@ -121,7 +121,7 @@ def compute_pll2(hse, sys, relax_pll48):
121121
# N is restricted
122122
if N not in mcu.range_n:
123123
continue
124-
Q = float(sys * P) / 48 # float for Python 2
124+
Q = sys * P / 48
125125
# Q must be an integer in a set range
126126
if close_int(Q) and round(Q) in mcu.range_q:
127127
# found valid values
@@ -142,7 +142,6 @@ def compute_pll2(hse, sys, relax_pll48):
142142

143143

144144
def compute_derived(hse, pll):
145-
hse = float(hse) # float for Python 2
146145
M, N, P, Q = pll
147146
vco_in = hse / M
148147
vco_out = hse * N / M

ports/stm32/make-stmconst.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@
99
import argparse
1010
import re
1111

12-
# Python 2/3 compatibility
13-
import platform
1412

15-
if platform.python_version_tuple()[0] == "2":
16-
17-
def convert_bytes_to_str(b):
18-
return b
19-
20-
elif platform.python_version_tuple()[0] == "3":
21-
22-
def convert_bytes_to_str(b):
23-
try:
24-
return str(b, "utf8")
25-
except ValueError:
26-
# some files have invalid utf8 bytes, so filter them out
27-
return "".join(chr(l) for l in b if l <= 126)
28-
29-
30-
# end compatibility code
13+
def convert_bytes_to_str(b):
14+
try:
15+
return str(b, "utf8")
16+
except ValueError:
17+
# some files have invalid utf8 bytes, so filter them out
18+
return "".join(chr(l) for l in b if l <= 126)
3119

3220

3321
# given a list of (name,regex) pairs, find the first one that matches the given line

py/makeqstrdata.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
"""
22
Process raw qstr file and output qstr data with length, hash and data bytes.
33
4-
This script works with Python 2.6, 2.7, 3.3 and 3.4.
4+
This script works with Python 3.3+.
55
"""
66

77
from __future__ import print_function
88

99
import re
1010
import sys
1111

12-
# Python 2/3/MicroPython compatibility:
13-
# - iterating through bytes is different
14-
# - codepoint2name from html.entities is hard-coded
15-
if sys.version_info[0] == 2:
16-
bytes_cons = lambda val, enc=None: bytearray(val)
17-
elif sys.version_info[0] == 3: # Also handles MicroPython
18-
bytes_cons = bytes
12+
bytes_cons = bytes
1913

2014
# fmt: off
2115
codepoint2name = {
@@ -57,7 +51,6 @@
5751
253: "yacute", 165: "yen", 255: "yuml", 950: "zeta", 8205: "zwj", 8204: "zwnj"
5852
}
5953
# fmt: on
60-
# end compatibility code
6154

6255
codepoint2name[ord("-")] = "hyphen"
6356

py/makeqstrdefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This script processes the output from the C preprocessor and extracts all
33
qstr. Each qstr is transformed into a qstr definition of the form 'Q(...)'.
44
5-
This script works with Python 2.6, 2.7, 3.3 and 3.4.
5+
This script works with Python 3.3+.
66
"""
77

88
from __future__ import print_function

py/makeversionhdr.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Generate header file with macros defining MicroPython version info.
33
4-
This script works with Python 2.6, 2.7, 3.3 and 3.4.
4+
This script works with Python 3.3+.
55
"""
66

77
from __future__ import print_function
@@ -22,12 +22,6 @@
2222
# "vX.Y.Z-preview.N.gHASH.dirty" -- building at any subsequent commit in the cycle
2323
# with local changes
2424
def get_version_info_from_git(repo_path):
25-
# Python 2.6 doesn't have check_output, so check for that
26-
try:
27-
subprocess.check_output
28-
except AttributeError:
29-
return None
30-
3125
# Note: git describe doesn't work if no tag is available
3226
try:
3327
git_tag = subprocess.check_output(
@@ -57,12 +51,6 @@ def get_version_info_from_git(repo_path):
5751

5852

5953
def get_hash_from_git(repo_path):
60-
# Python 2.6 doesn't have check_output, so check for that.
61-
try:
62-
subprocess.check_output
63-
except AttributeError:
64-
return None
65-
6654
try:
6755
return subprocess.check_output(
6856
["git", "rev-parse", "--short", "HEAD"],

tools/ci.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,12 @@ function ci_code_size_build {
130130

131131
function ci_mpy_format_setup {
132132
sudo apt-get update
133-
sudo apt-get install python2.7
134133
sudo pip3 install pyelftools
135-
python2.7 --version
136134
python3 --version
137135
}
138136

139137
function ci_mpy_format_test {
140138
# Test mpy-tool.py dump feature on bytecode
141-
python2.7 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy
142139
python3 ./tools/mpy-tool.py -xd tests/frozen/frozentest.mpy
143140

144141
# Build MicroPython
@@ -683,12 +680,11 @@ function ci_unix_coverage_run_native_mpy_tests {
683680
function ci_unix_32bit_setup {
684681
sudo dpkg --add-architecture i386
685682
sudo apt-get update
686-
sudo apt-get install gcc-multilib g++-multilib libffi-dev:i386 python2.7
683+
sudo apt-get install gcc-multilib g++-multilib libffi-dev:i386
687684
sudo pip3 install setuptools
688685
sudo pip3 install pyelftools
689686
sudo pip3 install ar
690687
gcc --version
691-
python2.7 --version
692688
python3 --version
693689
}
694690

@@ -706,13 +702,12 @@ function ci_unix_coverage_32bit_run_native_mpy_tests {
706702
}
707703

708704
function ci_unix_nanbox_build {
709-
# Use Python 2 to check that it can run the build scripts
710-
ci_unix_build_helper PYTHON=python2.7 VARIANT=nanbox CFLAGS_EXTRA="-DMICROPY_PY_MATH_CONSTANTS=1"
705+
ci_unix_build_helper VARIANT=nanbox CFLAGS_EXTRA="-DMICROPY_PY_MATH_CONSTANTS=1"
711706
ci_unix_build_ffi_lib_helper gcc -m32
712707
}
713708

714709
function ci_unix_nanbox_run_tests {
715-
ci_unix_run_tests_full_no_native_helper nanbox PYTHON=python2.7
710+
ci_unix_run_tests_full_no_native_helper nanbox
716711
}
717712

718713
function ci_unix_longlong_build {

0 commit comments

Comments
 (0)