Consider refactoring example folder creation
See original GitHub issueAs discussed in review comments at https://github.com/pyvista/pyvista/pull/1794, the current strategy of creating example directories in pyvista/__init__.py
is suboptimal. The issue is that choosing to raise when the example directories can’t be created for whatever reason is not an option with the current implementation, because this could affect many users who don’t use examples at all.
It seems reasonable from a design standpoint to refactor example directory creation to only happen when the directory would be first used. In that case we could raise when something’s off, and let the user try again in the correct directory or with the correct permissions. The drawback is that the implementation would probably be more complicated, with keeping track of whether the example directory has been initialised, and example calls having to check that each time.
cc. @MatthewFlamm
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Couldn’t we just keep it in the
pyvista
main namespace, initialise it toNone
and check for this inpyvista.examples
?I think there could be one helper function that is invoked at the beginning of each download function. This wouldn’t be too complex. It could also be a decorator to keep the syntax out of the function. EDIT: it could also go into
_check_examples_path
and the folders set up at that point. https://github.com/pyvista/pyvista/blob/d91b98ace4bea89412461d8bbe9eafa8192307ea/pyvista/examples/downloads.py#L27-L32I’m also wondering if it can be done when doing:
from pyvista import examples
. When importing this, it is much more likely that a file will be downloaded.