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

Error with unicode module names on Python2 #9

Closed
brutus opened this Issue Jul 4, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@brutus

brutus commented Jul 4, 2016

I maintain a Django installation and want to migrate the settings (lots of from X import *) to django-split-setings. Seems everything went fine, but the tox test for Python 2.7 (the only tested version < 3) bailed on me with the following error:

Traceback (most recent call last):
  File ".tox/py27/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/…/source/streambox/streambox/settings/test.py", line 19, in <module>
    scope=globals()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/tools.py", line 84, in include
    exec(compile(to_compile.read(), included_file, 'exec'), scope)
  File "/home/…/source/streambox/streambox/settings/components/base.py", line 147, in <module>
    scope=globals()
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/tools.py", line 90, in include
    module = types.ModuleType(module_name)
TypeError: module.__init__() argument 1 must be string, not unicode

This might be a result of from __future__ import unicode_literals. Any ideas how to handle this?

@sobolevn

This comment has been minimized.

Owner

sobolevn commented Jul 5, 2016

Thanks, will dig it soon. Do you have any fix for yourself?

@brutus

This comment has been minimized.

brutus commented Jul 5, 2016

Not really… For starters we just dropped Python 2 support (cause it's not needed in house). But that's temporary, cause we would like to keep 2.7 supported. I'm not sure, if unicode_literals is absolutely needed, but have to read up on it and check our code a lot more.

So, just workarounds for now. I was thinking about monkey–patching and "byteify" the relevant parts… but not sure where to start and what's relevant.

@sobolevn sobolevn added the bug label Jul 5, 2016

@sobolevn sobolevn self-assigned this Jul 5, 2016

@sobolevn sobolevn closed this in d3d1afb Jul 8, 2016

@sobolevn

This comment has been minimized.

Owner

sobolevn commented Jul 8, 2016

Hi, I got this working. Damn this unicode/str things in python2.

Here's the change itself:

module = types.ModuleType(str(module_name))

It won't probably work on decode error, but that's intended.

This is your example, I guess:
https://github.com/sobolevn/django-split-settings/blob/d3d1afb3bbab117ab4479537f170056f6c4a809a/tests/test_unicode.py

Basic unicode test:

@brutus

This comment has been minimized.

brutus commented Jul 14, 2016

Thanks for the fast fix!

While we will wait with re–enabling Python 2 support for your next release, I ran the latest Github version in some test environments and it works.

@sobolevn

This comment has been minimized.

Owner

sobolevn commented Jul 14, 2016

Nice, I will release it soon.

sobolevn added a commit that referenced this issue Jul 14, 2016

Version 0.2.2 release
* Now supporting `unicode` filenames, fixes #9
* Tests structure is changed
* Removed example
* Changed how `MANIFEST.in` is defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment