Skip to content

Commit

Permalink
refactor: argument names in formatter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Sep 25, 2024
1 parent cf7b11b commit fdad922
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/darker/formatters/black_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def read_config(self, src: tuple[str, ...], args: Namespace) -> None:
self._read_config_file(config_path)
self._read_cli_args(args)

def _read_config_file(self, value: str) -> None: # noqa: C901
raw_config = parse_pyproject_toml(value)
def _read_config_file(self, config_path: str) -> None: # noqa: C901
raw_config = parse_pyproject_toml(config_path)
if "line_length" in raw_config:
self.config["line_length"] = raw_config["line_length"]
if "skip_magic_trailing_comma" in raw_config:
Expand All @@ -115,7 +115,9 @@ def _read_config_file(self, value: str) -> None: # noqa: C901
# Convert TOML list to a Python set
self.config["target_version"] = set(target_version)
else:
message = f"Invalid target-version = {target_version!r} in {value}"
message = (
f"Invalid target-version = {target_version!r} in {config_path}"
)
raise ConfigurationError(message)
if "exclude" in raw_config:
self.config["exclude"] = re_compile_maybe_verbose(raw_config["exclude"])
Expand All @@ -142,10 +144,10 @@ def _read_cli_args(self, args: Namespace) -> None:
if getattr(args, "preview", None):
self.config["preview"] = args.preview

def run(self, src_contents: TextDocument) -> TextDocument:
def run(self, content: TextDocument) -> TextDocument:
"""Run the Black code re-formatter for the Python source code given as a string.
:param src_contents: The source code
:param content: The source code
:return: The reformatted content
"""
Expand Down Expand Up @@ -181,15 +183,15 @@ def run(self, src_contents: TextDocument) -> TextDocument:

# The custom handling of empty and all-whitespace files below will be
# unnecessary if https://github.com/psf/black/pull/2484 lands in Black.
contents_for_black = src_contents.string_with_newline("\n")
contents_for_black = content.string_with_newline("\n")
if contents_for_black.strip():
dst_contents = format_str(contents_for_black, mode=Mode(**mode))
else:
dst_contents = "\n" if "\n" in src_contents.string else ""
dst_contents = "\n" if "\n" in content.string else ""
return TextDocument.from_str(
dst_contents,
encoding=src_contents.encoding,
override_newline=src_contents.newline,
encoding=content.encoding,
override_newline=content.newline,
)

def get_config_path(self) -> str | None:
Expand Down

0 comments on commit fdad922

Please sign in to comment.