Skip to content

BF: be resilient to optional module non-ImportError exceptions upon import #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2018

Conversation

yarikoptic
Copy link
Member

ATM h5py is giving a grief while trying to work on a filesystem without
utf-8 encoding support in filenames.

…mport

ATM h5py is giving a grief while trying to work on a filesystem without
utf-8 encoding support in filenames.
@coveralls
Copy link

coveralls commented Apr 11, 2018

Coverage Status

Coverage decreased (-0.007%) to 93.351% when pulling 2c51018 on yarikoptic:enhs into 949d466 on nipy:master.

@codecov-io
Copy link

codecov-io commented Apr 12, 2018

Codecov Report

Merging #618 into master will decrease coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #618      +/-   ##
=========================================
- Coverage   90.31%   90.3%   -0.01%     
=========================================
  Files          87      87              
  Lines       10810   10813       +3     
  Branches     1793    1793              
=========================================
+ Hits         9763    9765       +2     
- Misses        718     719       +1     
  Partials      329     329
Impacted Files Coverage Δ
nibabel/optpkg.py 90% <100%> (+0.25%) ⬆️
nibabel/py3k.py 35.71% <50%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 949d466...2c51018. Read the comment docs.

raise Exception(
"non ImportError could be thrown by some malfunctioning module "
"upon import, and optional_package should catch it too")
with mock.patch.object(builtins, '__import__', side_effect=raise_Exception):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python 3, builtins is __builtin__, and in Python 2 you're setting builtins = __builtin__. Could you just import __builtin__ and patch that here? I'm not sure what we're getting by adding this to py3k.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In Python 3, builtins is __builtin__ . I am confused with what you mean ;):
$> python3 -c 'import builtins'      
$> python3 -c 'import __builtin__'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '__builtin__'
  • py3k is a module to establish the compatibility layer and feels intended to do so that code using it stays "python3" like. With this change then any code which needs to use builtins module in either of pythons would do so with python3 naming. I didn't want to breed python 2-vs-3 code right here in the test

Copy link
Member

@effigies effigies Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, perhaps this is an IPython thing.

In [1]: __builtin__
Out[1]: <module 'builtins' (built-in)>

But:

$ python -c 'import builtins; print(builtins is __builtin__)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name '__builtin__' is not defined

@yarikoptic
Copy link
Member Author

ok - merging since no disagreement ;-)

@yarikoptic yarikoptic merged commit 586c0e0 into nipy:master Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants