-
-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Avoid itkConfig double import trap
This potential failure mode can be summed up in the following general guideline: “Never add a package directory, or any directory inside a package, directly to the Python path”. The reason that adding nested directories to the Python sys.path is problematic is that every module in that directory is now potentially accessible under two different names: as a top level module (since the directory is on sys.path) and as a submodule of the package (if the higher level directory containing the package itself is also on sys.path). We must import the itkConfig module from python path, not local reference in order to maintain the desired behavior that the module acts as a singleton for the module values (i.e. once the itkConfig module is loaded, we assume it is never loaded again, thus changed values like itkConfig.LazyLoading persist across diffent modules). `import .conf.itkConfig` is a different context than `import itkConfig`, even if they are the same file. The LazyLoading and other values may be different in the two contexts. In order to maintain backward compatibility AND avoid the double import trap by “Never add a package directory, or any directory inside a package, directly to the Python path”, the itkConfig.py file must exist outside of the itk package directory (it *must* be a stand-alone single file module). http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html
- Loading branch information
1 parent
b011102
commit 1e334c9
Showing
8 changed files
with
22 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Python pth file to add WrapITK's path to sys.path. | ||
# Python pth file to add itk package path to sys.path | ||
# for itk version "@ITK_VERSION_MAJOR@.@ITK_VERSION_MINOR@.@ITK_VERSION_PATCH@" | ||
@CONFIG_ITK_WRAP_PYTHON_DIR@ | ||
@CONFIG_ITK_WRAP_LIBRARY_DIR@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.