
On Wed, Sep 15, 2021 at 8:41 PM Christian Heimes <christian@python.org> wrote:
On 15/09/2021 11.56, Marc-Andre Lemburg wrote:
- Chris mentioned that library code should not be changing the CWD. In an ideal world, I'd agree, but there are cases where you don't have an option and you need to change the CWD in order make certain things work, e.g. you don't control the code you want to run, but need to make it work in a specific directory by changing the CWD and then passing relative paths to the code.
This seems rather hypothetical to me. Can you provide a real-world example where you cannot use absolute paths?
Sometimes there is no valid path to something, or you need to be immune to directory renames. The normal solution would be to use openat() etc (or, in Python, os.open() with a dir_fd). I'm not sure what happens on Windows. Does Windows let you open a directory and retain a handle to it? If not, it probably just won't allow the concept in question, and absolutification would be a solution. This would be another good reason to wrap this up into a library - on POSIX systems, it can open a directory and make everything use dir_fd, but on Windows, it remembers the drive letter and path, and absolutes out all path names. Additional wrinkle: Can this be made asyncio compatible? Is it possible to make it, instead of thread-local, aware in some way of which task it's running? ChrisA