Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
rev: v0.15.0
hooks:
- id: ruff-check
name: Run Ruff (lint) on Doc/
Expand Down Expand Up @@ -36,14 +36,14 @@ repos:
files: ^Tools/wasm/

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
name: Run Black on Tools/jit/
files: ^Tools/jit/

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
rev: v1.5.6
hooks:
- id: remove-tabs
types: [python]
Expand All @@ -68,19 +68,19 @@ repos:
files: '^\.github/CODEOWNERS|\.(gram)$'

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.36.0
rev: 0.36.1
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

- repo: https://github.com/rhysd/actionlint
rev: v1.7.9
rev: v1.7.10
hooks:
- id: actionlint

- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v1.19.0
rev: v1.22.0
hooks:
- id: zizmor

Expand Down
15 changes: 10 additions & 5 deletions Tools/build/check_extension_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
import sys
import sysconfig
import warnings

from collections.abc import Iterable
from importlib._bootstrap import _load as bootstrap_load # type: ignore[attr-defined]
from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec
from importlib._bootstrap import ( # type: ignore[attr-defined]
_load as bootstrap_load,
)
from importlib.machinery import (
BuiltinImporter,
ExtensionFileLoader,
ModuleSpec,
)
from importlib.util import spec_from_file_location, spec_from_loader
from typing import NamedTuple

Expand Down Expand Up @@ -201,7 +206,7 @@ def print_three_column(modinfos: list[ModuleInfo]) -> None:
# guarantee zip() doesn't drop anything
while len(names) % 3:
names.append("")
for l, m, r in zip(names[::3], names[1::3], names[2::3]):
for l, m, r in zip(names[::3], names[1::3], names[2::3]): # noqa: E741
print("%-*s %-*s %-*s" % (longest, l, longest, m, longest, r))

if verbose and self.builtin_ok:
Expand Down Expand Up @@ -433,7 +438,7 @@ def check_module_import(self, modinfo: ModuleInfo) -> None:
except ImportError as e:
logger.error("%s failed to import: %s", modinfo.name, e)
raise
except Exception as e:
except Exception:
if not hasattr(_imp, 'create_dynamic'):
logger.warning("Dynamic extension '%s' ignored", modinfo.name)
return
Expand Down
19 changes: 10 additions & 9 deletions Tools/build/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import re
import time
import types

import umarshal

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Iterator
from typing import Any, TextIO, Dict, FrozenSet, TextIO, Tuple
from typing import Any, TextIO

ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

Expand Down Expand Up @@ -63,8 +64,8 @@ def get_localsplus(code: types.CodeType) -> tuple[tuple[str, ...], bytes]:


def get_localsplus_counts(code: types.CodeType,
names: Tuple[str, ...],
kinds: bytes) -> Tuple[int, int, int]:
names: tuple[str, ...],
kinds: bytes) -> tuple[int, int, int]:
nlocals = 0
ncellvars = 0
nfreevars = 0
Expand All @@ -90,7 +91,7 @@ def get_localsplus_counts(code: types.CodeType,
PyUnicode_4BYTE_KIND = 4


def analyze_character_width(s: str) -> Tuple[int, bool]:
def analyze_character_width(s: str) -> tuple[int, bool]:
maxchar = ' '
for c in s:
maxchar = max(maxchar, c)
Expand All @@ -115,7 +116,7 @@ class Printer:
def __init__(self, file: TextIO) -> None:
self.level = 0
self.file = file
self.cache: Dict[tuple[type, object, str], str] = {}
self.cache: dict[tuple[type, object, str], str] = {}
self.hits, self.misses = 0, 0
self.finis: list[str] = []
self.inits: list[str] = []
Expand Down Expand Up @@ -319,7 +320,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.inits.append(f"_PyStaticCode_Init({name_as_code})")
return f"& {name}.ob_base.ob_base"

def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
def generate_tuple(self, name: str, t: tuple[object, ...]) -> str:
if len(t) == 0:
return f"(PyObject *)& _Py_SINGLETON(tuple_empty)"
items = [self.generate(f"{name}_{i}", it) for i, it in enumerate(t)]
Expand Down Expand Up @@ -393,7 +394,7 @@ def generate_complex(self, name: str, z: complex) -> str:
self.write(f".cval = {{ {z.real}, {z.imag} }},")
return f"&{name}.ob_base"

def generate_frozenset(self, name: str, fs: FrozenSet[Any]) -> str:
def generate_frozenset(self, name: str, fs: frozenset[Any]) -> str:
try:
fs_sorted = sorted(fs)
except TypeError:
Expand Down Expand Up @@ -479,7 +480,7 @@ def generate(args: list[str], output: TextIO) -> None:
printer = Printer(output)
for arg in args:
file, modname = arg.rsplit(':', 1)
with open(file, "r", encoding="utf8") as fd:
with open(file, encoding="utf8") as fd:
source = fd.read()
if is_frozen_header(source):
code = decode_frozen_data(source)
Expand Down Expand Up @@ -527,7 +528,7 @@ def main() -> None:
if args.file:
if verbose:
print(f"Reading targets from {args.file}")
with open(args.file, "rt", encoding="utf-8-sig") as fin:
with open(args.file, encoding="utf-8-sig") as fin:
rules = [x.strip() for x in fin]
else:
rules = args.args
Expand Down
9 changes: 3 additions & 6 deletions Tools/build/freeze_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
See the notes at the top of Python/frozen.c for more info.
"""

from collections import namedtuple
import hashlib
import os
import ntpath
import os
import posixpath
import argparse
from update_file import updating_file_with_tmpfile
from collections import namedtuple

from update_file import updating_file_with_tmpfile

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
ROOT_DIR = os.path.abspath(ROOT_DIR)
Expand Down Expand Up @@ -485,7 +484,6 @@ def regen_frozen(modules):
header = relpath_for_posix_display(src.frozenfile, parentdir)
headerlines.append(f'#include "{header}"')

externlines = UniqueList()
bootstraplines = []
stdliblines = []
testlines = []
Expand Down Expand Up @@ -628,7 +626,6 @@ def regen_makefile(modules):
def regen_pcbuild(modules):
projlines = []
filterlines = []
corelines = []
for src in _iter_sources(modules):
pyfile = relpath_for_windows_display(src.pyfile, ROOT_DIR)
header = relpath_for_windows_display(src.frozenfile, ROOT_DIR)
Expand Down
5 changes: 3 additions & 2 deletions Tools/build/generate_global_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def generate_runtime_init(identifiers, strings):
break
else:
raise NotImplementedError
assert nsmallposints and nsmallnegints
assert nsmallposints
assert nsmallnegints

# Then target the runtime initializer.
filename = os.path.join(INTERNAL, 'pycore_runtime_init_generated.h')
Expand Down Expand Up @@ -434,7 +435,7 @@ def get_identifiers_and_strings() -> 'tuple[set[str], dict[str, str]]':
# To cover tricky cases (like "\n") we also generate C asserts.
raise ValueError(
'do not use &_PyID or &_Py_STR for one-character latin-1 '
+ f'strings, use _Py_LATIN1_CHR instead: {string!r}')
f'strings, use _Py_LATIN1_CHR instead: {string!r}')
if string not in strings:
strings[string] = name
elif name != strings[string]:
Expand Down
3 changes: 1 addition & 2 deletions Tools/build/generate_levenshtein_examples.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Generate 10,000 unique examples for the Levenshtein short-circuit tests."""

import argparse
from functools import lru_cache
import json
import os.path
from functools import lru_cache
from random import choices, randrange


# This should be in sync with Lib/traceback.py. It's not importing those values
# because this script is being executed by PYTHON_FOR_REGEN and not by the in-tree
# build of Python.
Expand Down
4 changes: 2 additions & 2 deletions Tools/build/generate_re_casefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def update_file(file, content):
try:
with open(file, 'r', encoding='utf-8') as fobj:
with open(file, encoding='utf-8') as fobj:
if fobj.read() == content:
return False
except (OSError, ValueError):
Expand Down Expand Up @@ -50,7 +50,7 @@ def main(outfile='Lib/re/_casefix.py'):
# List of codes of lowercased characters which have the same uppercase.
equivalent_lower_codes = [sorted(t)
for s in equivalent_chars
for t in [set(ord(c.lower()) for c in s)]
for t in [{ord(c.lower()) for c in s}]
if len(t) > 1]

bad_codes = []
Expand Down
12 changes: 6 additions & 6 deletions Tools/build/generate_sbom.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Tool for generating Software Bill of Materials (SBOM) for Python's dependencies"""

import glob
import hashlib
import json
import os
import random
import re
import hashlib
import json
import glob
from pathlib import Path, PurePosixPath, PureWindowsPath
import subprocess
import sys
import time
import typing
import urllib.error
import urllib.request
import typing
from pathlib import Path, PurePosixPath, PureWindowsPath

CPYTHON_ROOT_DIR = Path(__file__).parent.parent.parent

Expand Down Expand Up @@ -274,7 +274,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
license_concluded = package["licenseConcluded"]
error_if(
license_concluded != "NOASSERTION",
f"License identifier must be 'NOASSERTION'"
"License identifier must be 'NOASSERTION'"
)


Expand Down
2 changes: 1 addition & 1 deletion Tools/build/generate_sre_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def update_file(file, content):
try:
with open(file, 'r') as fobj:
with open(file) as fobj:
if fobj.read() == content:
return False
except (OSError, ValueError):
Expand Down
1 change: 0 additions & 1 deletion Tools/build/generate_stdlib_module_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from check_extension_modules import ModuleChecker


SCRIPT_NAME = 'Tools/build/generate_stdlib_module_names.py'

SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
Expand Down
3 changes: 1 addition & 2 deletions Tools/build/generate_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import re


SCRIPT_NAME = 'Tools/build/generate_token.py'
AUTO_GENERATED_BY_SCRIPT = f'Auto-generated by {SCRIPT_NAME}'
NT_OFFSET = 256
Expand Down Expand Up @@ -46,7 +45,7 @@ def load_tokens(path):

def update_file(file, content):
try:
with open(file, 'r') as fobj:
with open(file) as fobj:
if fobj.read() == content:
return False
except (OSError, ValueError):
Expand Down
18 changes: 9 additions & 9 deletions Tools/build/parse_html5_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
Written by Ezio Melotti and Iuliia Proskurnia.
"""

import json
import os
import sys
import json
from urllib.request import urlopen
from html.entities import html5
from urllib.request import urlopen

SCRIPT_NAME = 'Tools/build/parse_html5_entities.py'
PAGE_URL = 'https://html.spec.whatwg.org/multipage/named-characters.html'
Expand All @@ -40,20 +40,20 @@ def compare_dicts(old, new):
"""Compare the old and new dicts and print the differences."""
added = new.keys() - old.keys()
if added:
print('{} entitie(s) have been added:'.format(len(added)))
print(f'{len(added)} entitie(s) have been added:')
for name in sorted(added):
print(' {!r}: {!r}'.format(name, new[name]))
print(f' {name!r}: {new[name]!r}')
removed = old.keys() - new.keys()
if removed:
print('{} entitie(s) have been removed:'.format(len(removed)))
print(f'{len(removed)} entitie(s) have been removed:')
for name in sorted(removed):
print(' {!r}: {!r}'.format(name, old[name]))
print(f' {name!r}: {old[name]!r}')
changed = set()
for name in (old.keys() & new.keys()):
if old[name] != new[name]:
changed.add((name, old[name], new[name]))
if changed:
print('{} entitie(s) have been modified:'.format(len(changed)))
print(f'{len(changed)} entitie(s) have been modified:')
for item in sorted(changed):
print(' {!r}: {!r} -> {!r}'.format(*item))

Expand Down Expand Up @@ -111,5 +111,5 @@ def write_items(entities, file=sys.stdout):
print('The current dictionary is updated.')
else:
compare_dicts(html5, new_html5)
print('Run "./python {0} --patch" to update Lib/html/entities.html '
'or "./python {0} --create" to see the generated ' 'dictionary.'.format(__file__))
print(f'Run "./python {__file__} --patch" to update Lib/html/entities.html '
f'or "./python {__file__} --create" to see the generated dictionary.')
Loading
Loading