core
core copied to clipboard
Should we extensively use pushd_popd instead of try ... catch ... finally os.chdir() pattern?
> Should we extensively use pushd_popd instead of try ... catch ... finally os.chdir() pattern?
Not without adapting pushd_popd first. However, I don't want to mess with that to not break something else.
Originally posted by @MehmedGIT in https://github.com/OCR-D/core/issues/987#issuecomment-1479681602
Would working_directory be a better name for it?
with working_directory("/foo/bar"):
do_something()
Python 3.11's contextlib now has chdir. (Sadly, jazzband's contextlib2 does not have a backport yet and the project seems to lacking behind. That would have been a nice solution.)