keewis / blackdoc

run black on documentation code snippets
https://blackdoc.readthedocs.io
MIT License
47 stars 4 forks source link

Black compatibility : relative vs absolute path #210

Open Nodd opened 1 month ago

Nodd commented 1 month ago

I noticed a minor incompatibility between black and blackdoc: black displays absolute filenames in the console while blackdoc displays relative paths. This would not be a problem, except that is renders blackdoc incompatible with black-gl-code-quality. I think that it can be easily fixed on this side.

Here is the error:

$ blackdoc --check . 2>&1 | black-gl-cq
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\XXX\Scripts\black-gl-cq.exe\__main__.py", line 7, in <module>
  File "D:\XXX\Lib\site-packages\black_gl_code_quality\__main__.py", line 42, in main
    output = parse_simple_mode(lines, severity)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\XXX\Lib\site-packages\black_gl_code_quality\parser.py", line 13, in parse_simple_mode
    path = Path(line.strip(magic_word).strip()).relative_to(Path.cwd())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\XXX\Lib\pathlib.py", line 730, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: 'XXX.py' is not in the subpath of 'D:\\YYY' OR one path is relative and the other is absolute.