PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
254 stars 203 forks source link

Improve switching between working directories #2089

Closed oscarlevin closed 7 months ago

oscarlevin commented 7 months ago

This implements a with working_directory(path) context that switches to the directory path, and then switches back to the previous directory when the tasks in the context are complete (or even if they fail). This should provide consistent behavior in every situation where there used to be,

owd = os.getcwd()
os.chdir(tmp_dir)
...
os.chdir(owd)

The hope is that this will prevent mysterious errors that sometimes pop up for windows and perhaps the Critical 2 error.

rbeezer commented 7 months ago

OK, for the record, I've put this through the pretext/pretext script for each option that appears to be affected, and everything seems to function just fine.

The diff is really bad - not just gross indentation, but also coincindental matches due to the shifts. And --diff-algorithm=patience does not seem to help. C'est la vie.

Hopefully the Windows "No 2" error goes away, or the messages from the context manager help to pinpoint the problem. Thanks, @oscarlevin , for putting this together.