Changes between Initial Version and Version 1 of Ticket #7173, comment 2
- Timestamp:
- Jun 24, 2022, 5:24:01 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #7173, comment 2
initial v1 1 Sorry, I know we'll be discussing this Monday but I just can't help myself. :-). This situation is exactly what import hooks are for, and they provide a seamless solution where the programmer does not have to write a whole bunch of additional code to handle a missing package. If ChimeraX knows how to get the bundle then it handles the situation. Conversely, the proposed solutions are bad in that catching ImportError does not in fact in any way guarantee that the bundle isn't already installed. The bundle may be in turn importing something (such as gdcm) that is causing theImportError. To ensure that you aren't mystifying the user by telling them to install a bundle that they've already installed, you would have to scan sys.modules to ensure that the bundle is in fact missing -- which is what an import hook does for you automatically!1 Sorry, I know we'll be discussing this Monday but I just can't help myself. :-). This situation is exactly what import hooks are for, and they provide a seamless solution where the programmer does not have to write a whole bunch of additional code to handle a missing package. If ChimeraX knows how to get the bundle then it handles the situation. Conversely, the proposed solutions are bad in that catching !ImportError does not in fact in any way guarantee that the bundle isn't already installed. The bundle may be in turn importing something (such as gdcm) that is causing the !ImportError. To ensure that you aren't mystifying the user by telling them to install a bundle that they've already installed, you would have to scan sys.modules to ensure that the bundle is in fact missing -- which is what an import hook does for you automatically!