Skip to content

Commit d47bf81

Browse files
committed
fix: colors on Python 3.14
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 853d7be commit d47bf81

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ known-local-folder = ["pathutils"]
306306
"importlib.resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
307307
"importlib_resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
308308
"pyproject_metadata".msg = "Use scikit_build_core._vendor.pyproject_metadata instead."
309+
"argparse.ArgumentParser".msg = "Use scikit_build_core._compat.argparse instead."
309310

310311

311312
[tool.ruff.lint.per-file-ignores]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
import functools
5+
import sys
6+
7+
__all__ = ["ArgumentParser"]
8+
9+
10+
def __dir__() -> list[str]:
11+
return __all__
12+
13+
14+
ArgumentParser = functools.partial(argparse.ArgumentParser)
15+
16+
if sys.version_info >= (3, 14):
17+
ArgumentParser = functools.partial(
18+
ArgumentParser, color=True, suggest_on_error=True
19+
)

src/scikit_build_core/build/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Literal
55

66
from .._compat import tomllib
7+
from .._compat.argparse import ArgumentParser
78
from .._logging import rich_warning
89
from ..builder._load_provider import process_dynamic_metadata
910
from . import (
@@ -48,7 +49,8 @@ def get_requires(mode: Literal["sdist", "wheel", "editable"]) -> None:
4849

4950

5051
def main() -> None:
51-
parser = argparse.ArgumentParser(
52+
parser = ArgumentParser(
53+
allow_abbrev=False,
5254
description="Build backend utilities",
5355
)
5456

src/scikit_build_core/builder/wheel_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def as_tags_set(self) -> frozenset[packaging.tags.Tag]:
152152

153153

154154
if __name__ == "__main__":
155-
import argparse
155+
from .._compat.argparse import ArgumentParser
156156

157-
parser = argparse.ArgumentParser()
157+
parser = ArgumentParser(allow_abbrev=False)
158158
parser.add_argument(
159159
"--archs",
160160
nargs="*",

src/scikit_build_core/file_api/_cattrs_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def load_reply_dir(reply_dir: Path) -> Index:
6161

6262

6363
if __name__ == "__main__":
64-
import argparse
64+
from .._compat.argparse import ArgumentParser
6565

6666
rich_print: Callable[[object], None]
6767
try:
6868
from rich import print as rich_print
6969
except ModuleNotFoundError:
7070
rich_print = builtins.print
7171

72-
parser = argparse.ArgumentParser()
72+
parser = ArgumentParser(allow_abbrev=False)
7373
parser.add_argument("reply_dir", type=Path, help="Path to the reply directory")
7474
args = parser.parse_args()
7575

src/scikit_build_core/file_api/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def stateless_query(build_dir: Path) -> Path:
2323

2424

2525
if __name__ == "__main__":
26-
import argparse
26+
from .._compat.argparse import ArgumentParser
2727

28-
parser = argparse.ArgumentParser()
28+
parser = ArgumentParser(allow_abbrev=False)
2929
parser.add_argument("build_dir", type=Path, help="Path to the build directory")
3030
args = parser.parse_args()
3131

src/scikit_build_core/file_api/reply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ def load_reply_dir(path: Path) -> Index:
111111

112112

113113
if __name__ == "__main__":
114-
import argparse
114+
from .._compat.argparse import ArgumentParser
115115

116116
rich_print: Callable[[object], None]
117117
try:
118118
from rich import print as rich_print
119119
except ModuleNotFoundError:
120120
rich_print = builtins.print
121121

122-
parser = argparse.ArgumentParser()
122+
parser = ArgumentParser(allow_abbrev=False)
123123
parser.add_argument("reply_dir", type=Path, help="Path to the reply directory")
124124
args = parser.parse_args()
125125

0 commit comments

Comments
 (0)