From 22dc4e0d773a93a149b3194fce8450a1e3d64264 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 28 Nov 2025 22:55:07 +0000 Subject: [PATCH 1/2] Read additional args from file with with `@`. --- README.rst | 7 +++++++ codespell_lib/_codespell.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index fdd16cc5e5..a9562e8f2b 100644 --- a/README.rst +++ b/README.rst @@ -229,6 +229,13 @@ instead of these invalid entries: .. _tomli: https://pypi.org/project/tomli/ +Reading arguments from file +--------------------------- + +Additional arguments can be read from a file with ``@PATH``. Arguments are +extracted using ``shlex.split()``. + + pre-commit hook --------------- diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 94ab65d068..ce4f4a57a3 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -23,6 +23,7 @@ import itertools import os import re +import shlex import sys import textwrap from collections.abc import Iterable, Sequence @@ -388,7 +389,20 @@ def _supports_ansi_colors() -> bool: def parse_options( args: Sequence[str], ) -> tuple[argparse.Namespace, argparse.ArgumentParser, list[str]]: - parser = argparse.ArgumentParser(formatter_class=NewlineHelpFormatter) + + # Split lines read from `@PATH` using shlex.split(), otherwise default + # behaviour is to have one arg per line. See: + # https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.convert_arg_line_to_args + class ArgumentParser(argparse.ArgumentParser): + def convert_arg_line_to_args(self, arg_line: str + ) -> list[str]: + return shlex.split(arg_line) + + parser = ArgumentParser( + formatter_class=NewlineHelpFormatter, + fromfile_prefix_chars="@", + epilog="Use @ to read additional arguments from file .", + ) parser.set_defaults(colors=_supports_ansi_colors()) parser.add_argument("--version", action="version", version=VERSION) From 7b7910e4c97ac9ad8628a317a0c150155e729d60 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 29 Nov 2025 00:08:23 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- codespell_lib/_codespell.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index ce4f4a57a3..814e30d4bb 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -389,15 +389,13 @@ def _supports_ansi_colors() -> bool: def parse_options( args: Sequence[str], ) -> tuple[argparse.Namespace, argparse.ArgumentParser, list[str]]: - # Split lines read from `@PATH` using shlex.split(), otherwise default - # behaviour is to have one arg per line. See: + # behaviour is to have one arg per line. See: # https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.convert_arg_line_to_args class ArgumentParser(argparse.ArgumentParser): - def convert_arg_line_to_args(self, arg_line: str - ) -> list[str]: + def convert_arg_line_to_args(self, arg_line: str) -> list[str]: return shlex.split(arg_line) - + parser = ArgumentParser( formatter_class=NewlineHelpFormatter, fromfile_prefix_chars="@",