strictdoc-project / strictdoc

Software for technical documentation and requirements management.
https://strictdoc.readthedocs.io/en/stable/
Other
152 stars 24 forks source link

Build traceability graph throws an exception when output-dir is specified with a trailing '/' #1953

Open jelledevleeschouwer opened 6 days ago

jelledevleeschouwer commented 6 days ago

Problem

Since version 0.0.59, exporting in rst format to an output directory throws the following exception:

Traceback (most recent call last):
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\Scripts\strictdoc.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\cli\main.py", line 184, in main
    raise exc
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\cli\main.py", line 179, in main
    _main(parallelizer)
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\cli\main.py", line 74, in _main
    export_action.build_index()
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\helpers\timing.py", line 18, in wrap
    result = func(*args, **kw)
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\core\actions\export_action.py", line 41, in build_index
    TraceabilityIndexBuilder.create(
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\core\traceability_index_builder.py", line 106, in create
    TraceabilityIndexBuilder.create_from_document_tree(
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\helpers\timing.py", line 18, in wrap
    result = func(*args, **kw)
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\core\traceability_index_builder.py", line 284, in create_from_document_tree
    SDocValidator.validate_grammar_from_file(
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\backend\sdoc\validations\sdoc_validator.py", line 52, in validate_grammar_from_file
    SDocValidator.validate_grammar_element(
  File "C:\Redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\strictdoc\backend\sdoc\validations\sdoc_validator.py", line 77, in validate_grammar_element
    document: Optional[SDocDocument] = grammar_element.parent.parent
AttributeError: 'NoneType' object has no attribute 'parent'

Steps to reproduce

strictdoc export . --format=rst --output-dir sphinx/source/

Workaround

strictdoc export . --format=rst --output-dir sphinx/source
stanislaw commented 6 days ago

Thanks for reporting this.

Just to make sure: did this work before 0.0.59?

Could you provide a reduced and anonymized example that reproduces this? It could simplify the debugging of the issue.

Thanks.

stanislaw commented 5 days ago

I just double-checked the code paths and I cannot see right away how this can happen with the latest 0.0.59 version.

Could you do one basic thing to make sure it is not the outdated cache being hit?

StrictDoc caches stuff in a temporary directory. On Linux, it is /tmp/strictdoc_cache/. Could you check your Windows temp directory and remove the strictdoc cache from there and run again?

If you don't know how to find it on Windows, this is what should help you with finding out the Windows equivalent of /tmp:

import tempfile
temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)  # On Linux, it is /tmp/tmple03uidc.
jelledevleeschouwer commented 5 days ago

Very strange. I duplicated the entire directory to start stripping until I get to an anonymized example to reproduce this. But in the duplicated directory, the issue could not be reproduced.

I did put your snippet in C:\Redacted\AppData\Local\Programs\Python\Python310\Lib\site-packages\strictdoc\cli on line 16, but it yields a different path every time I run strictdoc export .... So the directory does not even exist anymore after strictdoc exits.

So now I have 2 completely identical directories (checked with meld), one in which I can reproduce the issue, the other in which I can't. I clone the project again to a pristine directory and check if I can reproduce. If not, I think this issue can be closed.

jelledevleeschouwer commented 5 days ago

Okay, that worked. I think this can be considered some strange environment issue, but I'll leave it up to you if you want to close it or not.

stanislaw commented 4 days ago

Okay, that worked. I think this can be considered some strange environment issue, but I'll leave it up to you if you want to close it or not.

Just to make sure: did you locate the strictdoc cache as per my comment here: https://github.com/strictdoc-project/strictdoc/issues/1953#issuecomment-2417157853? Now that you have it working in the second folder, I would think of the caching issue and nothing else.

P.S. I should create the troubleshooting instructions somewhere. I will think about this and implement something soon'ish.

jelledevleeschouwer commented 4 days ago

Okay, that worked. I think this can be considered some strange environment issue, but I'll leave it up to you if you want to close it or not.

Just to make sure: did you locate the strictdoc cache as per my comment here: #1953 (comment)? Now that you have it working in the second folder, I would think of the caching issue and nothing else.

P.S. I should create the troubleshooting instructions somewhere. I will think about this and implement something soon'ish.

Of course, obviously you were referring to the /tmp part of /tmp/tmple03uidc, I misinterpreted that.

Now I have found indeed the strictdoc_cache folder in C:\Users\JELLE~1\AppData\Local\Temp\ and removed it. After removing, I could not reproduce the issue anymore in the failing folder.

Thanks for the support!