Skip to content
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

Python 3 compatibility #16

Merged
merged 4 commits into from
Sep 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
env:
- DJANGO=1.2.7
- DJANGO=1.3.1
- DJANGO=1.4
- DJANGO=1.5
- DJANGO=1.6.6
install:
- pip install -q Django==$DJANGO --use-mirrors
- pip install -q flake8 --use-mirrors
Expand Down
18 changes: 15 additions & 3 deletions logan/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

try:
unicode
except NameError:
basestring = unicode = str # Python 3

try:
execfile
except NameError: # Python3
def execfile(afile, globalz=None, localz=None):
with open(afile, "r") as fh:
exec(fh.read(), globalz, localz)

import sys
from django.utils.importlib import import_module
Expand Down Expand Up @@ -51,7 +63,7 @@ def validate(self):
})
except Exception as e:
exc_info = sys.exc_info()
raise ConfigurationError, unicode(e), exc_info[2]
raise ConfigurationError(unicode(e), exc_info[2])

def find_module(self, fullname, path=None):
if fullname != self.name:
Expand Down Expand Up @@ -79,7 +91,7 @@ def load_module(self, fullname):
return self._load_module(fullname)
except Exception as e:
exc_info = sys.exc_info()
raise ConfigurationError, unicode(e), exc_info[2]
raise ConfigurationError(unicode(e), exc_info[2])

def _load_module(self, fullname):
# TODO: is this needed?
Expand Down
18 changes: 12 additions & 6 deletions logan/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:license: Apache License 2.0, see LICENSE for more details.
"""

from __future__ import absolute_import
from __future__ import absolute_import, print_function

from django.core import management
from optparse import OptionParser
Expand All @@ -18,6 +18,12 @@
from logan.settings import create_default_settings


try:
raw_input
except NameError: # PYthon 3
raw_input = input


def sanitize_name(project):
project = project.replace(' ', '-')
return re.sub('[^A-Z0-9a-z_-]', '-', project)
Expand Down Expand Up @@ -126,7 +132,7 @@ def run_app(**kwargs):
args, command, command_args = parse_args(sys_args[1:])

if not command:
print "usage: %s [--config=/path/to/settings.py] [command] [options]" % runner_name
print("usage: %s [--config=/path/to/settings.py] [command] [options]" % runner_name)
sys.exit(1)

default_config_path = kwargs.get('default_config_path')
Expand All @@ -146,15 +152,15 @@ def run_app(**kwargs):
while resp not in ('Y', 'n'):
resp = raw_input('File already exists at %r, overwrite? [nY] ' % config_path)
if resp == 'n':
print "Aborted!"
print("Aborted!")
return

try:
create_default_settings(config_path, settings_initializer)
except OSError, e:
raise e.__class__, 'Unable to write default settings file to %r' % config_path
except OSError as e:
raise e.__class__('Unable to write default settings file to %r' % config_path)

print "Configuration file created at %r" % config_path
print("Configuration file created at %r" % config_path)

return

Expand Down
14 changes: 13 additions & 1 deletion logan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

from __future__ import absolute_import

try:
unicode
except NameError:
basestring = unicode = str # Python 3

try:
execfile
except NameError: # Python3
def execfile(afile, globalz=None, localz=None):
with open(afile, "r") as fh:
exec(fh.read(), globalz, localz)

import errno
import imp
import os
Expand Down Expand Up @@ -84,6 +96,6 @@ def add_settings(mod, allow_extras=True, settings=django_settings):

setattr(settings, setting, setting_value)

for key, value in extras.iteritems():
for key, value in extras.items():
curval = getattr(settings, key)
setattr(settings, key, curval + type(curval)(value))
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
tests_require=[
'django>=1',
'mock>=0.8.0',
'nose>=1.1.2',
'unittest2',
'nose>=1.1.2'
],
test_suite='unittest2.collector',
test_suite='nose.collector',
license='Apache License 2.0',
include_package_data=True,
classifiers=[
Expand Down
2 changes: 1 addition & 1 deletion tests/logan/runner/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest2 import TestCase
from unittest import TestCase

from logan.runner import sanitize_name, parse_args

Expand Down
2 changes: 1 addition & 1 deletion tests/logan/settings/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest2 import TestCase
from unittest import TestCase

import mock
from logan.settings import add_settings
Expand Down