roocs / clisops

Climate Simulation Operations
https://clisops.readthedocs.io/en/latest/
Other
21 stars 9 forks source link

PermissionError upon importing clisops.core in some Windows environments #320

Closed RondeauG closed 6 months ago

RondeauG commented 6 months ago

Description

When importing clisops.core, clisops.core.regrid.weights_cache_init() is called, with the goal to create a temporary folder where weights would be stored.

However, the default path specified in roocs.ini (/tmp/clisops_grid_weights) is very Linux-centric and can provoke a PermissionError in some Windows setups, since it tries to create a new folder under C:\tmp\clisops_grid_weights.

Using a platform-independent temporary folder would be preferable.

aulemahal commented 6 months ago

I'd also note that the mere import of clisops.core does not mean the user will perform any regridding. Would it be possible to delay the folder creation to the first time it is necessary ?

sol1105 commented 6 months ago

Thank you for reporting this issues.

I think one could use the tempfile module. The name of the directory should however be persistent. The initialisation could be moved to Weights.__init__. @cehbrecht For rook you could specify a path under /home in roocs.ini so the cache persists.

@Zeitsperre I see you self assigned this. If you do not find the time, however, I will look at it next week.

Zeitsperre commented 6 months ago

@sol1105

Thanks for following up. My idea was to leverage platformdirs to use an OS-dependent fixed location by default (perhaps user_config_dir or user_cache_dir) in order to have a persistent location that can be wiped if needed.

Here's one way to implement it: https://github.com/Ouranosinc/xclim/blob/080e0b227fa6ca886691035d19f66355d9911219/xclim/testing/utils.py#L59 (Perhaps we could even do the same for the test data fetching here?)

sol1105 commented 6 months ago

@Zeitsperre Yes, that sounds good :) Generally using a persistent directory makes sense

Zeitsperre commented 6 months ago

Closed via #323