rstcheck / rstcheck-core

Core library behind rstcheck.
http://rstcheck-core.rtfd.io/
MIT License
4 stars 8 forks source link

[Feature]: don't format tracebacks in a table #99

Closed ReenigneArcher closed 2 months ago

ReenigneArcher commented 2 months ago

To Dos

Description

The traceback is difficult to read when formatted as a table. We have a complaint of a missing file and cannot determine which file is missing.

[cmake] RemoteTraceback: 
[cmake] """
[cmake] Traceback (most recent call last):
[cmake]   File 
[cmake] "C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool
[cmake] .py", line 125, in worker
[cmake]     result = (True, func(*args, **kwds))
[cmake]                     ^^^^^^^^^^^^^^^^^^^
[cmake]   File 
[cmake] "C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\pool
[cmake] .py", line 51, in starmapstar
[cmake]     return list(itertools.starmap(args[0], args[1]))
[cmake]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 73, in check_file
[cmake]     return list(
[cmake]            ^^^^^
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 258, in check_source
[cmake]     yield from _run_code_checker_and_filter_errors(writer.checkers, 
[cmake] ignores["messages"])
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 281, in _run_code_checker_and_filter_errors
[cmake]     for lint_error in checker():
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 498, in run_check
[cmake]     for result in all_results:
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 644, in check
[cmake]     yield from checker(source_code)
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 775, in check_bash
[cmake]     result = self._run_in_subprocess(source_code, ".bash", ["bash", "-n"])
[cmake]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[cmake]   File 
[cmake] "C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\chec
[cmake] ker.py", line 889, in _run_in_subprocess
[cmake]     subprocess.run(
[cmake]   File 
[cmake] "C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line
[cmake] 548, in run
[cmake]     with Popen(*popenargs, **kwargs) as process:
[cmake]          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[cmake]   File 
[cmake] "C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line
[cmake] 1026, in __init__
[cmake]     self._execute_child(args, executable, preexec_fn, close_fds,
[cmake]   File 
[cmake] "C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line
[cmake] 1538, in _execute_child
[cmake]     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
[cmake]                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[cmake] FileNotFoundError: [WinError 2] The system cannot find the file specified
[cmake] """
[cmake] 
[cmake] The above exception was the direct cause of the following exception:
[cmake] 
[cmake] +--------------------- Traceback (most recent call last) ---------------------+
[cmake] | C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck\_cli.p |
[cmake] | y:136 in cli                                                                |
[cmake] |                                                                             |
[cmake] |   133             check_paths=files, rstcheck_config=rstcheck_config, overw |
[cmake] |   134         )                                                             |
[cmake] |   135         logger.info("Run main runner instance.")                      |
[cmake] | > 136         _runner.check()                                               |
[cmake] |   137         exit_code = _runner.print_result()                            |
[cmake] |   138                                                                       |
[cmake] |   139     except FileNotFoundError as exc:                                  |
[cmake] |                                                                             |
[cmake] | +-------------------------------- locals ---------------------------------+ |
[cmake] | |               _runner = <rstcheck_core.runner.RstcheckMainRunner object | |
[cmake] | |                         at 0x0000021DE8C9F7D0>                          | |
[cmake] | |                config = None                                            | |
[cmake] | |             exit_code = 1                                               | |
[cmake] | |                 files = [                                               | |
[cmake] | |                             WindowsPath('C:/Users/frog/Desktop/Sunshinà | |
[cmake] | |                         ]                                               | |
[cmake] | |     ignore_directives = None                                            | |
[cmake] | |      ignore_languages = None                                            | |
[cmake] | |       ignore_messages = None                                            | |
[cmake] | |          ignore_roles = None                                            | |
[cmake] | |  ignore_substitutions = None                                            | |
[cmake] | |             log_level = 'WARNING'                                       | |
[cmake] | |                logger = <Logger rstcheck._cli (WARNING)>                | |
[cmake] | |             recursive = True                                            | |
[cmake] | |          report_level = None                                            | |
[cmake] | |       rstcheck_config = RstcheckConfig(                                 | |
[cmake] | |                             report_level=None,                          | |
[cmake] | |                             ignore_directives=None,                     | |
[cmake] | |                             ignore_roles=None,                          | |
[cmake] | |                             ignore_substitutions=None,                  | |
[cmake] | |                             ignore_languages=None,                      | |
[cmake] | |                             ignore_messages=None,                       | |
[cmake] | |                             config_path=None,                           | |
[cmake] | |                             recursive=True,                             | |
[cmake] | |                             warn_unknown_settings=None                  | |
[cmake] | |                         )                                               | |
[cmake] | |               version = None                                            | |
[cmake] | | warn_unknown_settings = None                                            | |
[cmake] | +-------------------------------------------------------------------------+ |
[cmake] |                                                                             |
[cmake] | C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\r |
[cmake] | unner.py:227 in check                                                       |
[cmake] |                                                                             |
[cmake] |   224         """                                                           |
[cmake] |   225         logger.info("Run checks for all files.")                      |
[cmake] |   226         results = (                                                   |
[cmake] | > 227             self._run_checks_parallel()                               |
[cmake] |   228             if len(self._files_to_check) > 1                          |
[cmake] |   229             else self._run_checks_sync()                              |
[cmake] |   230         )                                                             |
[cmake] |                                                                             |
[cmake] | +-------------------------------- locals ---------------------------------+ |
[cmake] | | self = <rstcheck_core.runner.RstcheckMainRunner object at               | |
[cmake] | |        0x0000021DE8C9F7D0>                                              | |
[cmake] | +-------------------------------------------------------------------------+ |
[cmake] |                                                                             |
[cmake] | C:\Users\frog\Desktop\Sunshine\build\venv\Lib\site-packages\rstcheck_core\r |
[cmake] | unner.py:202 in _run_checks_parallel                                        |
[cmake] |                                                                             |
[cmake] |   199             self._pool_size,                                          |
[cmake] |   200         )                                                             |
[cmake] |   201         with _sphinx.load_sphinx_if_available(), multiprocessing.Pool |
[cmake] | > 202             return pool.starmap(                                      |
[cmake] |   203                 checker.check_file,                                   |
[cmake] |   204                 [(file, self.config, self.overwrite_config) for file  |
[cmake] |   205             )                                                         |
[cmake] |                                                                             |
[cmake] | +-------------------------------- locals ---------------------------------+ |
[cmake] | | pool = <multiprocessing.pool.Pool state=TERMINATE pool_size=20>         | |
[cmake] | | self = <rstcheck_core.runner.RstcheckMainRunner object at               | |
[cmake] | |        0x0000021DE8C9F7D0>                                              | |
[cmake] | +-------------------------------------------------------------------------+ |
[cmake] |                                                                             |
[cmake] | C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\p |
[cmake] | ool.py:375 in starmap                                                       |
[cmake] |                                                                             |
[cmake] |   372         be iterables as well and will be unpacked as arguments. Hence |
[cmake] |   373         `func` and (a, b) becomes func(a, b).                         |
[cmake] |   374         '''                                                           |
[cmake] | > 375         return self._map_async(func, iterable, starmapstar, chunksize |
[cmake] |   376                                                                       |
[cmake] |   377     def starmap_async(self, func, iterable, chunksize=None, callback= |
[cmake] |   378             error_callback=None):                                     |
[cmake] |                                                                             |
[cmake] | +-------------------------------- locals ---------------------------------+ |
[cmake] | | chunksize = None                                                        | |
[cmake] | |      func = <function check_file at 0x0000021DE64A8D60>                 | |
[cmake] | |  iterable = [                                                           | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 (                                                       | |
[cmake] | |                     WindowsPath('C:/Users/frog/Desktop/Sunshine/docs/sà | |
[cmake] | |                     RstcheckConfig(                                     | |
[cmake] | |                         report_level=None,                              | |
[cmake] | |                         ignore_directives=None,                         | |
[cmake] | |                         ignore_roles=None,                              | |
[cmake] | |                         ignore_substitutions=None,                      | |
[cmake] | |                         ignore_languages=None,                          | |
[cmake] | |                         ignore_messages=None,                           | |
[cmake] | |                         config_path=None,                               | |
[cmake] | |                         recursive=True,                                 | |
[cmake] | |                         warn_unknown_settings=None                      | |
[cmake] | |                     ),                                                  | |
[cmake] | |                     False                                               | |
[cmake] | |                 ),                                                      | |
[cmake] | |                 ... +19                                                 | |
[cmake] | |             ]                                                           | |
[cmake] | |      self = <multiprocessing.pool.Pool state=TERMINATE pool_size=20>    | |
[cmake] | +-------------------------------------------------------------------------+ |
[cmake] |                                                                             |
[cmake] | C:\Users\frog\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\p |
[cmake] | ool.py:774 in get                                                           |
[cmake] |                                                                             |
[cmake] |   771         if self._success:                                             |
[cmake] |   772             return self._value                                        |
[cmake] |   773         else:                                                         |
[cmake] | > 774             raise self._value                                         |
[cmake] |   775                                                                       |
[cmake] |   776     def _set(self, i, obj):                                           |
[cmake] |   777         self._success, self._value = obj                              |
[cmake] |                                                                             |
[cmake] | +-------------------------------- locals ---------------------------------+ |
[cmake] | |    self = <multiprocessing.pool.MapResult object at 0x0000021DE9639070> | |
[cmake] | | timeout = None                                                          | |
[cmake] | +-------------------------------------------------------------------------+ |
[cmake] +-----------------------------------------------------------------------------+
[cmake] FileNotFoundError: [WinError 2] The system cannot find the file specified
[cmake] CMake Error at docs/CMakeLists.txt:89 (execute_process):
[cmake]   execute_process failed command indexes:
[cmake] 
[cmake]     1: "Child return code: 1"

Operating System

Windows

Operating System Details

No response

Python Version

3.12

rstcheck Version

6.2.1

Cielquan commented 2 months ago

We do not format things as tables.

The exception output you see comes directly from python itself. I think this table-like output was introduced in python 3.11 with the addition of exception groups, but could also be added in 3.12. I am not 100% sure. They improved error stuff over the last version more than once.


AFAICT the error is indirectly cause because of a bash code block inside one of the files you lint. When we encounter a code block with a language we support, we write the content of the code block to a temporary file, which in turn gets check by different external tools depending on the language and we then consume the error messages and print them to the user if any. In your case you can see in the top section for the 8th file this line result = self._run_in_subprocess(source_code, ".bash", ["bash", "-n"]) showing me that a bash code block is being tried to lint via bash -n <tempfile.bash> in a subprocess. I am unsure if maybe the tempfile cannot be found. Or maybe that the bash executable cannot be found on your system, which seems more likely to me in this case because you are on windows.

Unfortunately I cannot test this myself, because I work in linux and have no windows machine to test on.

ReenigneArcher commented 2 months ago

I use python a lot, including 3.11 and have never seen tracebacks formatted in a table.

This is the specific issue... We cannot determine which file is having the issue.

[cmake] | |                 files = [                                               | |
[cmake] | |                             WindowsPath('C:/Users/frog/Desktop/Sunshinà | |
[cmake] | |                         ]

This could be easily fixed by handling the FileNotFound exception. Print the file you are expecting to find, then exit with the original exception. Would you accept a PR to at least handle the exception a little better?

Cielquan commented 2 months ago

PEP 654 added ExceptionGroups to python 3.11 which have a similar format like your output. But your output does not contain "ExceptionGroup" so that's not it.

You can see the format with a simple snippet like this:

try:
    raise AssertionError
except* AssertionError:
    raise

Actually I found the culprit: typer the CLI lib I use for rstcheck and since v0.5 they format errors like this. And you can disable the pretty output with the environment variable _TYPER_STANDARD_TRACEBACK=1

Generally I am open to PRs, but I am unsure how to handle it differently in a way which would not clutter the output. But I am open to ideas.

ReenigneArcher commented 2 months ago

you can disable the pretty output with the environment variable _TYPER_STANDARD_TRACEBACK=1

Awesome, I will try that!

Edit: this removes all the relevant info about the files it couldn't find.