Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Commit

Permalink
Fixes for python3 (#28)
Browse files Browse the repository at this point in the history
* Fixes for Python 3
* Disable flake8 rules for backslashes and single-letter class name

Signed-off-by: Dan Davison <dandavison7@gmail.com>
  • Loading branch information
dandavison authored and bruth committed Nov 21, 2018
1 parent 94a8516 commit 88c7ab0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
11 changes: 5 additions & 6 deletions modeltree/tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import warnings

import six
from django.apps import apps
from django.db import models
from django.conf import settings
Expand Down Expand Up @@ -37,6 +38,7 @@ class ModelNotRelated(ModelLookupError):
pass


@six.python_2_unicode_compatible
class ModelTreeNode(object):
def __init__(self, model, parent=None, relation=None, reverse=None,
related_name=None, accessor_name=None, nullable=False,
Expand Down Expand Up @@ -99,9 +101,6 @@ def __str__(self):

return name

def __unicode__(self):
return unicode(str(self))

def __repr__(self):
return '<{0}>'.format(self)

Expand Down Expand Up @@ -244,7 +243,7 @@ class ModelTree(object):
An excluded route is more obvious: joining from the specified source
model to the specified target model is not allowed.
"""
""" # noqa: W605
def __init__(self, model=None, **kwargs):
if model is None and 'root_model' in kwargs:
warnings.warn('The "root_model" key has been renamed to "model"',
Expand Down Expand Up @@ -572,7 +571,7 @@ def _find_relations(self, node, depth=0):
# NOTE: the many-to-many relations are evaluated first to prevent
# 'through' models being bound as a ForeignKey relationship.
fields = sorted(model._meta.get_fields(), reverse=True,
key=lambda f: f.many_to_many)
key=lambda f: bool(f.many_to_many))

# determine relational fields to determine paths
forward_fields = [
Expand Down Expand Up @@ -824,7 +823,7 @@ def _get_or_create(self, alias=None, **kwargs):
alias = MODELTREE_DEFAULT_ALIAS

# Qualified app.model label
elif isinstance(alias, basestring) and '.' in alias:
elif isinstance(alias, six.string_types) and '.' in alias:
app_name, model_name = alias.split('.', 1)
model = apps.get_model(app_name, model_name)

Expand Down
2 changes: 1 addition & 1 deletion modeltree/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, tree=None, *args, **kwargs):
nargs.append(key)

# iterate over each kwarg and perform the conversion
for key, value in kwargs.iteritems():
for key, value in kwargs.items():
lookup = resolve_lookup(key, tree=tree)
nkwargs[lookup] = value

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'include_package_data': True,

# Dependencies
'install_requires': ['django>=1.8,<=1.11'],
'install_requires': ['django>=1.8,<=1.11', 'six>=1.11'],

'test_suite': 'test_suite',

Expand Down
10 changes: 5 additions & 5 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class Meeting(models.Model):
# Router Test Models.. no relation to the above models
# The raw model tree looks like this:
# A
# / \
# / \ # noqa: W605
# C B
# | / \
# | / \ # noqa: W605
# D G
# / \ |
# / \ | # noqa: W605
# E F |
# \ / \ |
# \ / \ | # noqa: W605
# J H
# | |
# K I
Expand Down Expand Up @@ -89,7 +89,7 @@ class H(models.Model):
f = models.ForeignKey(F)


class I(models.Model):
class I(models.Model): # noqa: E742
i = models.ManyToManyField(H)


Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ filename = *.py

[tox]
envlist =
clean,py27-django{18,19,110,111},stats
clean,py{27,37}-django{18,19,110,111},stats

[testenv]
basepython = python2.7
Expand All @@ -15,6 +15,7 @@ deps =
django19: Django==1.9.13
django110: Django==1.10.7
django111: Django==1.11.3
six == 1.11.0
commands = {envbindir}/coverage run -p --omit="*tests*" --source=modeltree --branch test_suite.py

[testenv:clean]
Expand Down

0 comments on commit 88c7ab0

Please sign in to comment.