PySCeS / pysces

The official PySCeS project source code repository.
https://pysces.github.io
Other
34 stars 10 forks source link

Changing the current working directory is an unexpected side effect #39

Closed jonrkarr closed 3 years ago

jonrkarr commented 3 years ago

Importing PySCeS and calling some methods causes the current working directory to change. Generally, importing Python modules doesn't have side effects like this. As a result, this behavior is unexpected, which could confusion users. This behavior requires codes that import PySCeS to work around this by undoing PySCeS' changing of the current working directory. More conventional behavior would be for PySCeS not to change the current working. PySCeS can read/write data from the configured directories without changing the current working directory, or methods which need to change the current working directory could undo their changes.

jmrohwer commented 3 years ago

This is something that has been bothering me for a while as well. To a large extent this is legacy behaviour. I am thinking of making this configurable in .pys_usercfg.ini. Refer to the nocwd branch.

bgoli commented 3 years ago

Indeed this is a legacy behaviour that was necessary when Windows had no consistently defined "home" variable and and mktemp was considered insecure. I'm fine with making this an optional behaviour, however, for this to be portable we'll have to modify the parser to use TemporaryFile, NamedTemporaryFile etc. I'll open another issue for that.

jonrkarr commented 3 years ago

Thanks! We worked around this; its easy to work around once you realize that PySCeS is doing this. I mentioned this because others would likely prefer this mode as well.

jmrohwer commented 3 years ago

Implemented in #42.