Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Fix compilation error when running under Python 3.4 #579

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

LeHack
Copy link

@LeHack LeHack commented Jun 3, 2017

ISSUE TYPE
  • Bugfix Pull Request
SUMMARY

This compilation error was the only obstacle I encountered when running ansible-container with Python 3.4, despite having no issues at all with Docker and Ansible standalone.
I tested the full build/run/deploy cycle and everything seems to work fine with this fix applied.

@j00bar
Copy link
Contributor

j00bar commented Jun 3, 2017

Not being a heavy user of Python3 yet, I'm a little confused. I read this in the docs: https://docs.python.org/3/library/http.html#http.HTTPStatus -- by that read, the code as present is correct. Could you help me understand your PR? Thanks!

@LeHack
Copy link
Author

LeHack commented Jun 3, 2017

Correction, this concerns Python 3.4 (but my fix works also with 3.5).
Actually regarding Python I'm not much more than a novice.
I found this suggestion somewhere on stackoverflow while trying to resolve the issue that popped up during the build process:

$ ansible-container build 
ERROR	Unknown exception	
Traceback (most recent call last):
  File "/home/.../testapp/lib/python3.4/site-packages/container/docker/engine.py", line 23, in <module>
    import httplib as StatusCodes
ImportError: No module named 'httplib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/.../testapp/lib/python3.4/site-packages/container/cli.py", line 268, in __call__
    getattr(core, u'hostcmd_{}'.format(args.subcommand))(**vars(args))
  File "/home/.../testapp/lib/python3.4/site-packages/container/__init__.py", line 28, in __wrapped__
    return fn(*args, **kwargs)
  File "/home/.../testapp/lib/python3.4/site-packages/container/core.py", line 137, in hostcmd_build
    config['services'], **kwargs)
  File "/home/.../testapp/lib/python3.4/site-packages/container/utils/loader.py", line 16, in load_engine
    package='container')
  File "/home/.../testapp/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/.../testapp/lib/python3.4/site-packages/container/docker/engine.py", line 25, in <module>
    from http import HTTPStatus as StatusCodes
ImportError: cannot import name 'HTTPStatus'

@LeHack LeHack changed the title Fix compilation error when running under Python 3.5 Fix compilation error when running under Python 3.4 Jun 3, 2017
@chouseknecht chouseknecht requested a review from j00bar June 5, 2017 12:59
@ekohl
Copy link

ekohl commented Jul 10, 2017

I can confirm that the current develop branch is broken on python 3.4. Like https://docs.python.org/3/library/http.html#http.HTTPStatus mentions it is new in 3.5. I don't think the current code is really the best solution since http.client is a different package from the enum HTTPStatus and importing it this way might lead to subtle bugs.

I'm installing 3.5 and 3.6 to check if I can come with a recommendation for a proper fix.

@ekohl
Copy link

ekohl commented Jul 11, 2017

Having looked into it I'd recommend the following:

try:  # Python 3.5+
    from http import HTTPStatus as StatusCodes
except ImportError:
    try:  # Python 3
        from http import client as StatusCodes
    except ImportError:  # Python 2
        import httplib as StatusCodes

@chouseknecht
Copy link
Contributor

@LeHack

Would you mind modifying this to use the method suggested by @ekohl. Once done, I can merge this.

Thank you for your efforts on this, and apologies for not looking at it in quite awhile.

@rinatz
Copy link

rinatz commented Feb 26, 2018

I'm in trouble because of this error.
Can I fix it instead of @LeHack?

@5444de
Copy link

5444de commented Nov 27, 2018

i have a error when i first test ansible-container,why:
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants