From a7b92457e5485cfedbdd49e4ec6839d5a6ea6ae4 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 11 Oct 2023 22:52:34 +0100 Subject: [PATCH 1/8] Resolve ruff PLW1510: add explicit 'check' argument to subprocess.run --- sphinx/__init__.py | 1 + sphinx/testing/fixtures.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/__init__.py b/sphinx/__init__.py index 037e041134a..d5fe45bb723 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -44,6 +44,7 @@ ['git', 'rev-parse', '--short', 'HEAD'], cwd=package_dir, capture_output=True, + check=False, encoding='ascii', errors='surrogateescape', ).stdout: diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 0cc4882fe1c..1fce8d5be40 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -211,7 +211,7 @@ def if_graphviz_found(app: SphinxTestApp) -> None: # NoQA: PT004 graphviz_dot = getattr(app.config, 'graphviz_dot', '') try: if graphviz_dot: - subprocess.run([graphviz_dot, '-V'], capture_output=True) # show version + subprocess.run([graphviz_dot, '-V'], capture_output=True, check=False) return except OSError: # No such file or directory pass From 62c896986d8bf269f3a450d8cb08535c68321529 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 11 Oct 2023 22:57:44 +0100 Subject: [PATCH 2/8] Resolve ruff E226: add missing whitespace around arithmetic operator --- sphinx/environment/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 9b9e9dd306a..24fbe33d4e3 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -751,7 +751,7 @@ def _last_modified_time(filename: str | os.PathLike[str]) -> int: def _format_modified_time(timestamp: int) -> str: """Return an RFC 3339 formatted string representing the given timestamp.""" seconds, fraction = divmod(timestamp, 10**6) - return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(seconds)) + f'.{fraction//1_000}' + return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(seconds)) + f'.{fraction // 1_000}' def _traverse_toctree( From 47d75fef1011d78bfc9a91e1b13d2dcfbf6485b3 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 11 Oct 2023 23:00:01 +0100 Subject: [PATCH 3/8] Resolve ruff COM819: remove trailing comma after method invocation argument list --- sphinx/writers/texinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 7032c65833c..e927dbe8715 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -430,7 +430,7 @@ def _add_detailed_menu(name: str) -> None: entries = self.node_menus[name] if not entries: return - self.body.append(f'\n{self.escape(self.node_names[name], )}\n\n') + self.body.append(f'\n{self.escape(self.node_names[name])}\n\n') self.add_menu_entries(entries) for subentry in entries: _add_detailed_menu(subentry) From 2259ac5a04639b99421120db96b7f1c92a952698 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 11 Oct 2023 23:01:09 +0100 Subject: [PATCH 4/8] Resolve ruff PT014: remove duplicate test fixture parameter --- tests/test_pycode_ast.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_pycode_ast.py b/tests/test_pycode_ast.py index 5efd0cbfa42..13777bfe7b1 100644 --- a/tests/test_pycode_ast.py +++ b/tests/test_pycode_ast.py @@ -34,7 +34,6 @@ ("a % b", "a % b"), # Mod ("a * b", "a * b"), # Mult ("sys", "sys"), # Name, NameConstant - ("1234", "1234"), # Num ("not a", "not a"), # Not ("a or b", "a or b"), # Or ("a**b", "a**b"), # Pow From 06d5da5d9cc312a43d8e766f6c1582ded0c93650 Mon Sep 17 00:00:00 2001 From: James Addison Date: Wed, 11 Oct 2023 23:10:54 +0100 Subject: [PATCH 5/8] Resolve ruff SIM115: disable specific lintcheck flag on affected line --- sphinx/testing/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py index f4069ba4133..49e62ce9ebb 100644 --- a/sphinx/testing/path.py +++ b/sphinx/testing/path.py @@ -150,7 +150,7 @@ def utime(self, arg: Any) -> None: os.utime(self, arg) def open(self, mode: str = 'r', **kwargs: Any) -> IO: - return open(self, mode, **kwargs) + return open(self, mode, **kwargs) # NoQA: SIM115 def write_text(self, text: str, encoding: str = 'utf-8', **kwargs: Any) -> None: """ From f2814485ba7895ebce5532d1f4ebf54b489fcde9 Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Oct 2023 00:08:00 +0100 Subject: [PATCH 6/8] Fixup: handle one more ruff PLW1510 case --- tests/test_ext_imgconverter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ext_imgconverter.py b/tests/test_ext_imgconverter.py index 18be7004889..cfa82536e8c 100644 --- a/tests/test_ext_imgconverter.py +++ b/tests/test_ext_imgconverter.py @@ -10,7 +10,7 @@ def _if_converter_found(app): image_converter = getattr(app.config, 'image_converter', '') try: if image_converter: - subprocess.run([image_converter, '-version'], capture_output=True) # show version + subprocess.run([image_converter, '-version'], capture_output=True, check=False) return except OSError: # No such file or directory pass From b2b1b12c5ac90e3946727e0955e101bfd1554e49 Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Oct 2023 11:40:21 +0100 Subject: [PATCH 7/8] Feedback: add explanatory comment when commands are run to test their availability on the system --- sphinx/testing/fixtures.py | 1 + tests/test_ext_imgconverter.py | 1 + 2 files changed, 2 insertions(+) diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 1fce8d5be40..154323bf92b 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -211,6 +211,7 @@ def if_graphviz_found(app: SphinxTestApp) -> None: # NoQA: PT004 graphviz_dot = getattr(app.config, 'graphviz_dot', '') try: if graphviz_dot: + # print the graphviz_dot version, to check that the binary is available subprocess.run([graphviz_dot, '-V'], capture_output=True, check=False) return except OSError: # No such file or directory diff --git a/tests/test_ext_imgconverter.py b/tests/test_ext_imgconverter.py index cfa82536e8c..73eacbd42a6 100644 --- a/tests/test_ext_imgconverter.py +++ b/tests/test_ext_imgconverter.py @@ -10,6 +10,7 @@ def _if_converter_found(app): image_converter = getattr(app.config, 'image_converter', '') try: if image_converter: + # print the image_converter version, to check that the command is available subprocess.run([image_converter, '-version'], capture_output=True, check=False) return except OSError: # No such file or directory From 954dd650a52fe8f4b005ea3eb3b88e3038ef522b Mon Sep 17 00:00:00 2001 From: James Addison Date: Thu, 12 Oct 2023 11:41:39 +0100 Subject: [PATCH 8/8] Feedback: restore 'Num' annotation to AST parsing test fixture parameter --- tests/test_pycode_ast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pycode_ast.py b/tests/test_pycode_ast.py index 13777bfe7b1..3a5977a5853 100644 --- a/tests/test_pycode_ast.py +++ b/tests/test_pycode_ast.py @@ -18,7 +18,7 @@ ("a and b and c", "a and b and c"), # BoolOp ("b'bytes'", "b'bytes'"), # Bytes ("object()", "object()"), # Call - ("1234", "1234"), # Constant + ("1234", "1234"), # Constant, Num ("{'key1': 'value1', 'key2': 'value2'}", "{'key1': 'value1', 'key2': 'value2'}"), # Dict ("a / b", "a / b"), # Div