Skip to content

Commit 68e162d

Browse files
authored
Rollup merge of rust-lang#112483 - tgross35:py2-dep-warning, r=Mark-Simulacrum
Add deprecation warning to python versions <3.6 in x.py Introduced based on conversation on Zulip. This is a repeat of rust-lang#110439 with two changes: - Warning rather than exit - Can be suppressed via an environment variable The min to not get the warning is set to 3.6 because that's a fairly recent "old" version (went EOL in 2021) and it's the first version to support useful modern features like f-strings and type hints. cc `@Nilstrieb` (author of rust-lang#110439) and `@Mark-Simulacrum` (reviewer of that PR)
2 parents 312e676 + cec95d7 commit 68e162d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: x.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
if __name__ == '__main__':
1010
import os
1111
import sys
12+
import warnings
13+
from inspect import cleandoc
14+
15+
major = sys.version_info.major
16+
minor = sys.version_info.minor
1217

1318
# If this is python2, check if python3 is available and re-execute with that
1419
# interpreter. Only python3 allows downloading CI LLVM.
1520
#
1621
# This matters if someone's system `python` is python2.
17-
if sys.version_info.major < 3:
22+
if major < 3:
1823
try:
1924
os.execvp("py", ["py", "-3"] + sys.argv)
2025
except OSError:
@@ -24,6 +29,19 @@
2429
# Python 3 isn't available, fall back to python 2
2530
pass
2631

32+
# soft deprecation of old python versions
33+
skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1"
34+
if major < 3 or (major == 3 and minor < 6):
35+
msg = cleandoc("""
36+
Using python {}.{} but >= 3.6 is recommended. Your python version
37+
should continue to work for the near future, but this will
38+
eventually change. If python >= 3.6 is not available on your system,
39+
please file an issue to help us understand timelines.
40+
41+
This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1`
42+
""".format(major, minor))
43+
warnings.warn(msg)
44+
2745
rust_dir = os.path.dirname(os.path.abspath(__file__))
2846
# For the import below, have Python search in src/bootstrap first.
2947
sys.path.insert(0, os.path.join(rust_dir, "src", "bootstrap"))

0 commit comments

Comments
 (0)