diff --git a/admin/binaries.py b/admin/binaries.py index 957e5e7..a723987 100644 --- a/admin/binaries.py +++ b/admin/binaries.py @@ -27,7 +27,7 @@ def make_linux_binaries(repo_root: Path) -> None: raise ValueError(msg) code_mount = Mount( - source=str(repo_root.absolute()), + source=str(object=repo_root.absolute()), target="/" + uuid.uuid4().hex, type="bind", ) diff --git a/admin/create_pyinstaller_binaries.py b/admin/create_pyinstaller_binaries.py index a9674d5..40ce1cf 100644 --- a/admin/create_pyinstaller_binaries.py +++ b/admin/create_pyinstaller_binaries.py @@ -21,10 +21,10 @@ def remove_existing_files(scripts: set[Path]) -> None: build_dir = Path() / "build" with contextlib.suppress(FileNotFoundError): - shutil.rmtree(path=str(dist_dir)) + shutil.rmtree(path=str(object=dist_dir)) with contextlib.suppress(FileNotFoundError): - shutil.rmtree(path=str(build_dir)) + shutil.rmtree(path=str(object=build_dir)) for script in scripts: path = Path(script.name + ".spec") @@ -41,7 +41,7 @@ def create_binary(script: Path) -> None: """ pyinstaller_command = [ "pyinstaller", - str(script.resolve()), + str(object=script.resolve()), "--onefile", "--name", script.name + "-" + sys.platform, diff --git a/docs/source/conf.py b/docs/source/conf.py index 1c95bcb..df1306e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -39,7 +39,7 @@ # This method of getting the release from the version goes hand in hand with # the ``post-release`` versioning scheme chosen in the ``setuptools-scm`` # configuration. -release = version.split(".post")[0] +release = version.split(sep=".post")[0] project_metadata = importlib.metadata.metadata(distribution_name=project) requires_python = project_metadata["Requires-Python"] diff --git a/pyproject.toml b/pyproject.toml index 524d6ab..8cbc185 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,7 @@ optional-dependencies.dev = [ "furo==2024.8.6", "interrogate==1.7.0", "mypy[faster-cache]==1.14.0", + "mypy-strict-kwargs==2024.12.25", "pre-commit==4.0.1", "pydocstyle==6.3", "pyenchant==3.3.0rc1", @@ -355,6 +356,9 @@ strict = true files = [ "." ] exclude = [ "build" ] follow_untyped_imports = true +plugins = [ + "mypy_strict_kwargs", +] [tool.pyright] diff --git a/src/doccmd/__init__.py b/src/doccmd/__init__.py index 1ce5d4e..f20bdbf 100644 --- a/src/doccmd/__init__.py +++ b/src/doccmd/__init__.py @@ -26,7 +26,7 @@ from sybil.typing import Parser try: - __version__ = version(__name__) + __version__ = version(distribution_name=__name__) except PackageNotFoundError: # pragma: no cover # When pkg_resources and git tags are not available, # for example in a PyInstaller binary, @@ -126,7 +126,7 @@ def _get_file_paths( for file_suffix in file_suffixes: new_file_paths = ( path_part - for path_part in path.rglob(f"*{file_suffix}") + for path_part in path.rglob(pattern=f"*{file_suffix}") if len(path_part.relative_to(path).parts) <= max_depth ) for new_file_path in new_file_paths: @@ -179,7 +179,7 @@ def _validate_files_are_known_markup_types( rst_suffixes=rst_suffixes, ) except UnknownMarkupLanguageError as exc: - raise click.UsageError(message=str(exc)) from exc + raise click.UsageError(message=str(object=exc)) from exc @unique @@ -369,7 +369,7 @@ def _run_args_against_docs( ) ): command_str = shlex.join( - split_command=[str(item) for item in args], + split_command=[str(object=item) for item in args], ) running_command_message = ( f"Running '{command_str}' on code block at " diff --git a/tests/test_admin/test_binaries.py b/tests/test_admin/test_binaries.py index 755ce24..11b0fe1 100644 --- a/tests/test_admin/test_binaries.py +++ b/tests/test_admin/test_binaries.py @@ -36,8 +36,8 @@ def test_linux_binaries(request: pytest.FixtureRequest) -> None: mounts = [ Mount( - source=str(repo_root), - target=str(remote_repo_dir), + source=str(object=repo_root), + target=str(object=remote_repo_dir), type="bind", ), ] @@ -45,7 +45,7 @@ def test_linux_binaries(request: pytest.FixtureRequest) -> None: remote_paths: list[Path] = [] for path in dist_dir.iterdir(): relative_path = path.relative_to(repo_root) - remote_path = remote_repo_dir / str(relative_path) + remote_path = remote_repo_dir / str(object=relative_path) remote_paths.append(remote_path) client = docker.from_env() @@ -67,14 +67,14 @@ def test_linux_binaries(request: pytest.FixtureRequest) -> None: cmd_in_container = [ "chmod", "+x", - str(remote_path), + str(object=remote_path), "&&", - str(remote_path), + str(object=remote_path), "--version", "&&", "rm", "-rf", - str(remote_path), + str(object=remote_path), ] joined_cmd = " ".join(cmd_in_container) command = f'bash -c "{joined_cmd}"' diff --git a/tests/test_doccmd.py b/tests/test_doccmd.py index e9f4ed6..91a7228 100644 --- a/tests/test_doccmd.py +++ b/tests/test_doccmd.py @@ -47,7 +47,13 @@ def test_run_command(tmp_path: Path) -> None: assert x == 4 """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", "python", "--command", "cat", str(rst_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -89,7 +95,7 @@ def test_double_language(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -145,7 +151,13 @@ def test_not_utf_8_file_given(tmp_path: Path) -> None: print("\xc0\x80") """ rst_file.write_text(data=content, encoding="latin1") - arguments = ["--language", "python", "--command", "cat", str(rst_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -175,7 +187,13 @@ def test_multiple_code_blocks(tmp_path: Path) -> None: assert y == 6 """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", "python", "--command", "cat", str(rst_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -222,7 +240,13 @@ def test_language_filters(tmp_path: Path) -> None: console.assert(y === 6); """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", "python", "--command", "cat", str(rst_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -261,7 +285,7 @@ def test_run_command_no_pad_file(tmp_path: Path) -> None: "--command", "cat", "--no-pad-file", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -306,8 +330,8 @@ def test_multiple_files(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file1), - str(rst_file2), + str(object=rst_file1), + str(object=rst_file2), ] result = runner.invoke( cli=main, @@ -370,8 +394,8 @@ def test_multiple_files_multiple_types(tmp_path: Path) -> None: "--command", "cat", "--no-pad-file", - str(rst_file), - str(md_file), + str(object=rst_file), + str(object=md_file), ] result = runner.invoke( cli=main, @@ -408,14 +432,14 @@ def test_modify_file(tmp_path: Path) -> None: """ rst_file.write_text(data=content, encoding="utf-8") modify_code_script = textwrap.dedent( - """\ + text="""\ #!/usr/bin/env python import sys with open(sys.argv[1], "w") as file: file.write("foobar") - """ + """, ) modify_code_file = tmp_path / "modify_code.py" modify_code_file.write_text(data=modify_code_script, encoding="utf-8") @@ -424,7 +448,7 @@ def test_modify_file(tmp_path: Path) -> None: "python", "--command", f"python {modify_code_file.as_posix()}", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -460,7 +484,7 @@ def test_exit_code(tmp_path: Path) -> None: "python", "--command", Path(sys.executable).as_posix(), - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -494,7 +518,13 @@ def test_file_extension( assert x == 4 """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", language, "--command", "echo", str(rst_file)] + arguments = [ + "--language", + language, + "--command", + "echo", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -526,7 +556,7 @@ def test_given_temporary_file_extension(tmp_path: Path) -> None: ".foobar", "--command", "echo", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -562,7 +592,7 @@ def test_given_temporary_file_extension_no_leading_period( "foobar", "--command", "echo", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -602,7 +632,7 @@ def test_given_prefix(tmp_path: Path) -> None: "myprefix", "--command", "echo", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -629,7 +659,13 @@ def test_file_extension_unknown_language(tmp_path: Path) -> None: assert x == 4 """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", "unknown", "--command", "echo", str(rst_file)] + arguments = [ + "--language", + "unknown", + "--command", + "echo", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -665,9 +701,9 @@ def test_file_given_multiple_times(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file), - str(other_rst_file), - str(rst_file), + str(object=rst_file), + str(object=other_rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -720,7 +756,7 @@ def test_verbose_running(tmp_path: Path) -> None: "--command", "cat", "--verbose", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -766,7 +802,7 @@ def test_verbose_not_utf_8(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -820,7 +856,7 @@ def test_command_not_found(tmp_path: Path) -> None: "python", "--command", non_existent_command_with_args, - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -855,7 +891,7 @@ def test_not_executable(tmp_path: Path) -> None: "python", "--command", not_executable_command_with_args, - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -897,7 +933,7 @@ def test_multiple_languages(tmp_path: Path) -> None: "javascript", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -947,7 +983,7 @@ def test_default_skip_rst(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -998,7 +1034,7 @@ def test_custom_skip_markers_rst(tmp_path: Path) -> None: skip_marker, "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1054,7 +1090,7 @@ def test_default_skip_myst(tmp_path: Path) -> None: "python", "--command", "cat", - str(myst_file), + str(object=myst_file), ] result = runner.invoke( cli=main, @@ -1113,7 +1149,7 @@ def test_custom_skip_markers_myst(tmp_path: Path) -> None: skip_marker, "--command", "cat", - str(myst_file), + str(object=myst_file), ] result = runner.invoke( cli=main, @@ -1174,7 +1210,7 @@ def test_multiple_skip_markers(tmp_path: Path) -> None: skip_marker_2, "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1232,7 +1268,7 @@ def test_skip_start_end(tmp_path: Path) -> None: skip_marker_2, "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1286,7 +1322,7 @@ def test_duplicate_skip_marker(tmp_path: Path) -> None: skip_marker, "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1337,7 +1373,7 @@ def test_default_skip_marker_given(tmp_path: Path) -> None: skip_marker, "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1368,7 +1404,7 @@ def test_empty_file(tmp_path: Path) -> None: "python", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1413,7 +1449,7 @@ def test_detect_line_endings( "python", "--command", "cat", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1444,7 +1480,13 @@ def test_one_supported_markup_in_another_extension(tmp_path: Path) -> None: ``` """ rst_file.write_text(data=content, encoding="utf-8") - arguments = ["--language", "python", "--command", "cat", str(rst_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=rst_file), + ] result = runner.invoke( cli=main, args=arguments, @@ -1476,7 +1518,7 @@ def test_unknown_file_suffix(extension: str, tmp_path: Path) -> None: "python", "--command", "cat", - str(document_file), + str(object=document_file), ] result = runner.invoke( cli=main, @@ -1526,8 +1568,8 @@ def test_custom_rst_file_suffixes(tmp_path: Path) -> None: ".customrst", "--rst-extension", ".customrst2", - str(rst_file), - str(rst_file_2), + str(object=rst_file), + str(object=rst_file_2), ] result = runner.invoke( cli=main, @@ -1574,8 +1616,8 @@ def test_custom_myst_file_suffixes(tmp_path: Path) -> None: ".custommyst", "--myst-extension", ".custommyst2", - str(myst_file), - str(myst_file_2), + str(object=myst_file), + str(object=myst_file_2), ] result = runner.invoke( cli=main, @@ -1641,7 +1683,7 @@ def test_pty( "python", "--command", f"{Path(sys.executable).as_posix()} {script.as_posix()}", - str(rst_file), + str(object=rst_file), ] result = runner.invoke( cli=main, @@ -1676,7 +1718,7 @@ def test_source_given_extension_no_leading_period( "cat", option, "customrst", - str(source_file), + str(object=source_file), ] result = runner.invoke( cli=main, @@ -1722,7 +1764,7 @@ def test_overlapping_extensions(tmp_path: Path) -> None: ".custom2", "--myst-extension", ".custom2", - str(source_file), + str(object=source_file), ] result = runner.invoke( cli=main, @@ -1766,7 +1808,7 @@ def test_overlapping_extensions_dot(tmp_path: Path) -> None: ".", "--rst-extension", ".custom", - str(source_file), + str(object=source_file), ] result = runner.invoke( cli=main, @@ -1824,7 +1866,7 @@ def test_directory(tmp_path: Path) -> None: "--no-pad-file", "--command", "cat", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -1876,9 +1918,9 @@ def test_de_duplication_source_files_and_dirs(tmp_path: Path) -> None: "--no-pad-file", "--command", "cat", - str(tmp_path), - str(sub_directory), - str(rst_file_in_sub_directory), + str(object=tmp_path), + str(object=sub_directory), + str(object=rst_file_in_sub_directory), ] result = runner.invoke( cli=main, @@ -1944,7 +1986,7 @@ def test_max_depth(tmp_path: Path) -> None: "cat", "--max-depth", "1", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -1969,7 +2011,7 @@ def test_max_depth(tmp_path: Path) -> None: "cat", "--max-depth", "2", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -1995,7 +2037,7 @@ def test_max_depth(tmp_path: Path) -> None: "cat", "--max-depth", "3", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -2058,7 +2100,7 @@ def test_exclude_files_from_recursed_directories(tmp_path: Path) -> None: "cat", "--exclude", "exclude_*e.*", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -2130,7 +2172,7 @@ def test_multiple_exclude_patterns(tmp_path: Path) -> None: "exclude_*e.*", "--exclude", "ignore_*e.*", - str(tmp_path), + str(object=tmp_path), ] result = runner.invoke( cli=main, @@ -2161,7 +2203,13 @@ def test_lexing_exception(tmp_path: Path) -> None: """ source_file.write_text(data=invalid_content, encoding="utf-8") - arguments = ["--language", "python", "--command", "cat", str(source_file)] + arguments = [ + "--language", + "python", + "--command", + "cat", + str(object=source_file), + ] result = runner.invoke( cli=main, args=arguments,