sphinx-pretty-searchresults icon indicating copy to clipboard operation
sphinx-pretty-searchresults copied to clipboard

UnboundLocalError

Open timhoffm opened this issue 7 years ago • 4 comments

Version 0.3.5

Exception occurred:
  File "/home/tim/miniconda3/envs/mpl/lib/python3.6/site-packages/sphinxprettysearchresults/__init__.py", line 61, in clean_txts
    os.rename(os.path.join(root, file), os.path.join(root, file.replace('.txt', source_suffix + '.txt')))
UnboundLocalError: local variable 'source_suffix' referenced before assignment

There's some logic error here. source_suffix is not set if not file.endswith('.txt'). Not sure if there has to be an alternate default or if the rename shouldn't take place in that case.

Also the file.replace('.txt') are a bit dangerous in case that substring is present somewhere within the filename.

timhoffm avatar May 23 '18 17:05 timhoffm

Thanks for reporting. I'll take a look as soon as I find time.

TimKam avatar May 24 '18 08:05 TimKam

@timhoffm could you provide a minimal failing example? ATM, I can fix the specific issues in the code but feel a bit uncomfortable because I don't have a failing test.

TimKam avatar May 25 '18 21:05 TimKam

Unfortunately, I don't have a minimal example. It occurred when trying to build the matplotlib docs with sphinx-pretty-searchresults. The provided exception message was all information available. I have no idea what part of the docs was responsible for the error or how to obtain that information.

Additional to the above error, there was a problem with a proprietary sphinx directive. After fixing that, the above error was gone as well.

timhoffm avatar May 26 '18 14:05 timhoffm

Ok. The setup of the matplotlib docs is not really straight-forward, so it might take me some time to isolate the issue. But you could install from this branch: https://github.com/TimKam/sphinx-pretty-searchresults/tree/27-fix-unboundlocalerror. Does this fix your issue?

TimKam avatar May 27 '18 12:05 TimKam