Check for importability, rather than presence of file #136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes the implementation of checking extension support a bit
more robust. The old mechanism checked for the presence of
"extension_parser.py" in the same directory as the init.py. This
works in a lot of cases, but can fail in cases where the module
actually could have been imported. Simply trying to import the module
and raising an exception if it can't be imported should cover off the
other corner cases.
For a couple of examples of those corner cases: In my case I'm shipping
my code to an environment that is pretty constrained in terms of storage.
As a result, my build scripts strip out the ".py" flies and ship only the
".pyc" files. The existing code claims it can't support any extensions,
because the ".py" file is absent, even though the ".pyc" file would enable
it to function properly.
The other scenario I can think of is import hooks. See:
https://www.python.org/dev/peps/pep-0302/
Import hooks might be used to import modules from zip files, remote locations,
or other non-traditional sources. Checking the importability of a parser
module is compatible with all of these, while checking the presence
of a file is not.