Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect pyproject.toml parsing of boolean values #133

Merged
merged 2 commits into from Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/docformatter/configuration.py
Expand Up @@ -113,7 +113,8 @@ def do_parse_arguments(self) -> None:
"-r",
"--recursive",
action="store_true",
default=bool(self.flargs_dct.get("recursive", False)),
default=self.flargs_dct.get("recursive", "false").lower()
== "true",
help="drill down directories recursively",
)
self.parser.add_argument(
Expand Down Expand Up @@ -141,7 +142,8 @@ def do_parse_arguments(self) -> None:
self.parser.add_argument(
"--force-wrap",
action="store_true",
default=bool(self.flargs_dct.get("force-wrap", False)),
default=self.flargs_dct.get("force-wrap", "false").lower()
== "true",
help="force descriptions to be wrapped even if it may "
"result in a mess (default: False)",
)
Expand All @@ -158,38 +160,42 @@ def do_parse_arguments(self) -> None:
"--blank",
dest="post_description_blank",
action="store_true",
default=bool(self.flargs_dct.get("blank", False)),
default=self.flargs_dct.get("blank", "false").lower() == "true",
help="add blank line after description (default: False)",
)
self.parser.add_argument(
"--pre-summary-newline",
action="store_true",
default=bool(self.flargs_dct.get("pre-summary-newline", False)),
default=self.flargs_dct.get("pre-summary-newline", "false").lower()
== "true",
help="add a newline before the summary of a multi-line docstring "
"(default: False)",
)
self.parser.add_argument(
"--pre-summary-space",
action="store_true",
default=bool(self.flargs_dct.get("pre-summary-space", False)),
default=self.flargs_dct.get("pre-summary-space", "false").lower()
== "true",
help="add a space after the opening triple quotes "
"(default: False)",
)
self.parser.add_argument(
"--make-summary-multi-line",
action="store_true",
default=bool(
self.flargs_dct.get("make-summary-multi-line", False)
),
default=self.flargs_dct.get(
"make-summary-multi-line", "false"
).lower()
== "true",
help="add a newline before and after the summary of a one-line "
"docstring (default: False)",
)
self.parser.add_argument(
"--close-quotes-on-newline",
action="store_true",
default=bool(
self.flargs_dct.get("close-quotes-on-newline", False)
),
default=self.flargs_dct.get(
"close-quotes-on-newline", "false"
).lower()
== "true",
help="place closing triple quotes on a new-line when a "
"one-line docstring wraps to two or more lines "
"(default: False)",
Expand Down Expand Up @@ -217,7 +223,8 @@ def do_parse_arguments(self) -> None:
self.parser.add_argument(
"--non-strict",
action="store_true",
default=bool(self.flargs_dct.get("non-strict", False)),
default=self.flargs_dct.get("non-strict", "false").lower()
== "true",
help="don't strictly follow reST syntax to identify lists (see "
"issue #67) (default: False)",
)
Expand All @@ -238,7 +245,6 @@ def do_parse_arguments(self) -> None:
)

self.args = self.parser.parse_args(self.args_lst[1:])

if self.args.line_range:
if self.args.line_range[0] <= 0:
self.parser.error("--range must be positive numbers")
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Expand Up @@ -64,6 +64,17 @@ def temporary_file(contents, file_directory=".", file_prefix=""):
finally:
os.remove(f.name)

@pytest.fixture(scope="function")
def temporary_config(config, file_directory="/tmp",
file_name="pyproject.toml"):
"""Write contents to temporary configuration and yield it."""
f = open(f"{file_directory}/{file_name}", "wb")
try:
f.write(config.encode())
f.close()
yield f.name
finally:
os.remove(f.name)

@pytest.fixture(scope="function")
def run_docformatter(arguments, temporary_file):
Expand Down