Skip to content

Commit 71c0b59

Browse files
committed
python: update min version to 3.9
Debian 11 (bullseye) includes Python 3.9, and is what our kokoro build environment uses still. Everywhere else we care about has upgraded to even newer versions. gLinux, CrOS, and Crostini (Debian 12 bookworm) are all at 3.11. This will let us use newer typing style, and stop writing code that is compatible with 3.6. Change-Id: Ie28b646e00bcacd1b8ffdc05583cfef7b32d91ab Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/6201553 Reviewed-by: Joel Hockey <[email protected]> Tested-by: kokoro <[email protected]>
1 parent 4f5d09f commit 71c0b59

File tree

11 files changed

+31
-67
lines changed

11 files changed

+31
-67
lines changed

kokoro/lint

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
from pathlib import Path
99
import sys
10-
from typing import List
1110

1211
import kokoro
1312
import libdot # pylint: disable=wrong-import-order
1413

1514

16-
def _get_default_paths(basedir: Path) -> List[Path]:
15+
def _get_default_paths(basedir: Path) -> list[Path]:
1716
"""Get list of paths to lint by default."""
1817
kokoro_files = sorted(libdot.lint.get_known_sources(basedir))
1918

libdot/bin/black

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import logging
1111
import shutil
1212
import subprocess
1313
import sys
14-
from typing import List
1514

1615
import libdot
1716

@@ -86,7 +85,7 @@ def get_parser() -> argparse.ArgumentParser:
8685
return parser
8786

8887

89-
def main(argv: List[str]) -> int:
88+
def main(argv: list[str]) -> int:
9089
"""The main func!"""
9190
parser = get_parser()
9291
opts, args = parser.parse_known_args(argv)

libdot/bin/cpplint

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from pathlib import Path
99
import sys
10-
from typing import List
1110

1211
import libdot
1312

@@ -29,7 +28,7 @@ CPPLINT_URL = (
2928
CPPLINT = libdot.BIN_DIR / f".cpplint.{CHROMIUM_REF}"
3029

3130

32-
def filter_known_files(paths: List[Path]) -> List[Path]:
31+
def filter_known_files(paths: list[Path]) -> list[Path]:
3332
"""Figure out what files this linter supports."""
3433
ret = []
3534
for path in paths:

libdot/bin/jsonlint

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import json
1111
import logging
1212
from pathlib import Path
1313
import sys
14-
from typing import List
1514

1615
import libdot
1716

1817

19-
def filter_known_files(paths: List[Path]) -> List[Path]:
18+
def filter_known_files(paths: list[Path]) -> list[Path]:
2019
"""Figure out what files this linter supports."""
2120
ret = []
2221
for path in paths:
@@ -84,7 +83,7 @@ def check_messages(path: Path, fix: bool = False) -> bool:
8483
return check_common(path, old_data, new_data, fix=fix)
8584

8685

87-
def check_files(paths: List[Path], fix: bool = False) -> bool:
86+
def check_files(paths: list[Path], fix: bool = False) -> bool:
8887
"""Check all the JSON files."""
8988
ret = True
9089
for path in paths:

libdot/bin/libdot.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sys
2020
import time
2121
import types
22-
from typing import Dict, List, Optional, Union
22+
from typing import Optional, Union
2323
import urllib.error
2424
import urllib.request
2525

@@ -28,8 +28,8 @@
2828
# NB: We cannot require newer versions than CrOS itself supports.
2929
assert sys.version_info >= (
3030
3,
31-
6,
32-
), f"Python 3.6 or newer is required; found {sys.version}"
31+
9,
32+
), f"Python 3.9 or newer is required; found {sys.version}"
3333

3434

3535
BIN_DIR = Path(__file__).resolve().parent
@@ -176,12 +176,12 @@ def cmdstr(cmd):
176176

177177

178178
def run(
179-
cmd: List[str],
180-
cmd_prefix: List[str] = None,
181-
log_prefix: List[str] = None,
179+
cmd: list[str],
180+
cmd_prefix: list[str] = None,
181+
log_prefix: list[str] = None,
182182
check: bool = True,
183183
cwd: str = None,
184-
extra_env: Dict[str, str] = None,
184+
extra_env: dict[str, str] = None,
185185
**kwargs,
186186
):
187187
"""Run |cmd| inside of |cwd| and exit if it fails.
@@ -200,14 +200,6 @@ def run(
200200
Returns:
201201
A subprocess.CompletedProcess instance.
202202
"""
203-
# Python 3.6 doesn't support capture_output.
204-
if sys.version_info < (3, 7):
205-
capture_output = kwargs.pop("capture_output", None)
206-
if capture_output:
207-
assert "stdout" not in kwargs and "stderr" not in kwargs
208-
kwargs["stdout"] = subprocess.PIPE
209-
kwargs["stderr"] = subprocess.PIPE
210-
211203
# The |env| setting specifies the entire environment, so we need to manually
212204
# merge our |extra_env| settings into it before passing it along.
213205
if extra_env is not None:
@@ -252,7 +244,7 @@ def sha256(path: Union[Path, str]) -> str:
252244
def unpack(
253245
archive: Union[Path, str],
254246
cwd: Optional[Path] = None,
255-
files: Optional[List[Union[Path, str]]] = (),
247+
files: Optional[list[Union[Path, str]]] = (),
256248
):
257249
"""Unpack |archive| into |cwd|."""
258250
archive = Path(archive)
@@ -283,9 +275,9 @@ def unpack(
283275

284276
def pack(
285277
archive: Union[Path, str],
286-
paths: List[Union[Path, str]],
278+
paths: list[Union[Path, str]],
287279
cwd: Optional[Path] = None,
288-
exclude: Optional[List[Union[Path, str]]] = (),
280+
exclude: Optional[list[Union[Path, str]]] = (),
289281
):
290282
"""Create an |archive| with |paths| in |cwd|.
291283

libdot/bin/lint

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import logging
1010
import os
1111
from pathlib import Path
1212
import sys
13-
from typing import List
1413

1514
import libdot
1615

@@ -45,7 +44,7 @@ def is_generated_path(path):
4544
)
4645

4746

48-
def get_known_files(basedir: Path) -> List[Path]:
47+
def get_known_files(basedir: Path) -> list[Path]:
4948
"""Return list of files committed to the tree."""
5049
# -z appends \0 to each path, it doesn't delimit them. So strip off the
5150
# trailing \0 to avoid a spurious '' entry at the end.
@@ -62,7 +61,7 @@ def get_known_files(basedir: Path) -> List[Path]:
6261
return [basedir / x for x in all_files if (basedir / x).exists()]
6362

6463

65-
def get_known_sources(basedir: Path) -> List[Path]:
64+
def get_known_sources(basedir: Path) -> list[Path]:
6665
"""Get list of committed files that we could possibly lint."""
6766
return (
6867
x
@@ -101,7 +100,7 @@ def lint_whitespace_data(path: Path, data: str) -> bool:
101100
return ret
102101

103102

104-
def lint_whitespace_files(paths: List[Path]) -> bool:
103+
def lint_whitespace_files(paths: list[Path]) -> bool:
105104
"""Basic whitespace checks on text files."""
106105
ret = True
107106

@@ -114,7 +113,7 @@ def lint_whitespace_files(paths: List[Path]) -> bool:
114113
return ret
115114

116115

117-
def lint_html_files(paths: List[Path]) -> bool:
116+
def lint_html_files(paths: list[Path]) -> bool:
118117
"""Basic lint checks on HTML files."""
119118
logging.info("Linting HTML files %s", libdot.cmdstr(paths))
120119
ret = True
@@ -134,13 +133,13 @@ def lint_html_files(paths: List[Path]) -> bool:
134133
return ret
135134

136135

137-
def lint_text_files(paths: List[Path]) -> bool:
136+
def lint_text_files(paths: list[Path]) -> bool:
138137
"""Basic lint checks on HTML files."""
139138
logging.info("Linting text files %s", libdot.cmdstr(paths))
140139
return lint_whitespace_files(paths)
141140

142141

143-
def _get_default_paths(basedir: Path) -> List[Path]:
142+
def _get_default_paths(basedir: Path) -> list[Path]:
144143
"""Get list of paths to lint by default."""
145144
most_files = sorted(
146145
x for x in get_known_sources(basedir) if x.suffix not in {".js"}

libdot/bin/mdlint

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
from pathlib import Path
99
import sys
10-
from typing import List
1110

1211
import libdot
1312

1413

15-
def filter_known_files(paths: List[Path]) -> List[Path]:
14+
def filter_known_files(paths: list[Path]) -> list[Path]:
1615
"""Figure out what files this linter supports."""
1716
ret = []
1817
for path in paths:

libdot/bin/node_sync_with_chromium

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99
import re
1010
import sys
11-
from typing import Dict
1211

1312
import libdot
1413

@@ -50,7 +49,7 @@ def update_file(var, value):
5049
NODE_SCRIPT.write_text("\n".join(lines) + "\n", encoding="utf-8")
5150

5251

53-
def update_hash(var: str, deps: Dict) -> None:
52+
def update_hash(var: str, deps: dict) -> None:
5453
"""Update |var| in our tree with the |new_hash|."""
5554
# The structure expected is:
5655
# {
@@ -77,7 +76,7 @@ def update_hash(var: str, deps: Dict) -> None:
7776
update_file(var, new_hash)
7877

7978

80-
def fetch_deps(uri: str) -> Dict:
79+
def fetch_deps(uri: str) -> dict:
8180
"""Fetch & parse Chromium DEPS file."""
8281
data = fetch_data(uri)
8382
# Very basic implementation of the format to get the data we care about.

libdot/bin/pylint

+3-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import os
1212
from pathlib import Path
1313
import shutil
1414
import sys
15-
from typing import List
1615

1716
import libdot
1817

@@ -68,7 +67,7 @@ def convert_to_kokoro(data):
6867
}
6968

7069

71-
def filter_known_files(paths: List[Path]) -> List[Path]:
70+
def filter_known_files(paths: list[Path]) -> list[Path]:
7271
"""Figure out what files this linter supports."""
7372
ret = []
7473
for path in paths:
@@ -95,18 +94,11 @@ def filter_known_files(paths: List[Path]) -> List[Path]:
9594

9695
@functools.lru_cache(maxsize=1)
9796
def find_pylint():
98-
"""Figure out the name of the pylint tool.
99-
100-
It keeps changing with Python 2->3 migrations. Fun.
101-
"""
97+
"""Figure out the name of the pylint tool."""
10298
# Prefer our vpython copy if possible.
10399
if shutil.which("vpython3"):
104100
return libdot.BIN_DIR / "pylint-vpython"
105101

106-
# Prefer pylint3 as that's what we want.
107-
if shutil.which("pylint3"):
108-
return "pylint3"
109-
110102
# If there's no pylint, give up.
111103
if not shutil.which("pylint"):
112104
logging.error(
@@ -115,18 +107,7 @@ def find_pylint():
115107
)
116108
sys.exit(1)
117109

118-
# Make sure pylint is using Python 3.
119-
result = libdot.run(
120-
["pylint", "--version"], capture_output=True, encoding="utf-8"
121-
)
122-
if "Python 3" in result.stdout:
123-
return "pylint"
124-
125-
logging.error(
126-
"pylint does not support Python 3; please upgrade:\n%s",
127-
result.stdout.strip(),
128-
)
129-
sys.exit(1)
110+
return "pylint"
130111

131112

132113
def setup():

nassh/bin/generate-changelog

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import html
99
import logging
1010
import os
1111
import sys
12-
from typing import List
1312

1413
import nassh # pylint: disable=wrong-import-order
1514
import libdot
@@ -23,7 +22,7 @@ CHANGELOG_ENTRY_TEMPLATE = """\
2322
"""
2423

2524

26-
def generate_html(tag: str, entries: List[List[str]]):
25+
def generate_html(tag: str, entries: list[list[str]]):
2726
"""Generate the changelog file from |entries|."""
2827
with open(CHANGELOG_TEMPLATE, "r", encoding="utf-8") as fp:
2928
template = fp.read()
@@ -38,7 +37,7 @@ def generate_html(tag: str, entries: List[List[str]]):
3837
fp.write(output)
3938

4039

41-
def get_entries(tag: str) -> List[List[str]]:
40+
def get_entries(tag: str) -> list[list[str]]:
4241
"""Find all the commits since |tag|."""
4342
output = libdot.run(
4443
["git", "log", "--format=%H %s", f"{tag}..HEAD"],
@@ -90,7 +89,7 @@ def get_parser():
9089
return parser
9190

9291

93-
def main(argv: List[str]):
92+
def main(argv: list[str]):
9493
"""The main func!"""
9594
parser = get_parser()
9695
opts = parser.parse_args(argv)

ssh_client/bin/ssh_client.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import re
1313
import shutil
1414
import sys
15-
from typing import List
1615

1716

1817
BIN_DIR = Path(__file__).resolve().parent
@@ -77,7 +76,7 @@ def emake(*args, **kwargs):
7776
run(["make", f"-j{jobs}"] + list(args), **kwargs)
7877

7978

80-
def get_mandoc_cmd(p: str) -> List[str]:
79+
def get_mandoc_cmd(p: str) -> list[str]:
8180
"""Get the mandoc command for the specified package."""
8281
return [
8382
"mandoc",

0 commit comments

Comments
 (0)