Skip to content

Commit

Permalink
Let DjangoInstalledChecker warn when Django isn't available
Browse files Browse the repository at this point in the history
by ignoring the import failure Python will not produce a traceback
but instead let DjangoInstalledChecker do its job and warn the user.

I also add a CI build stage to test this scenario since we don't want
to continue if this isn't working.

Finally properly fixes #96.
  • Loading branch information
atodorov committed Mar 9, 2018
1 parent 6e34b7a commit 65850c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ python:
env:
- DJANGO=1.11
- DJANGO=2.0
stages:
- django_not_installed
- test
matrix:
exclude:
# Python/Django combinations that aren't officially supported
- { python: 2.7, env: DJANGO=2.0 }
include:
- { python: 3.6, env: TOXENV=flake8 }
- { python: 3.6, env: TOXENV=pylint }
- { python: 3.6, env: TOXENV=readme }
- { stage: django_not_installed, python: 3.6, env: TOXENV=django_not_installed }
- { stage: test, python: 3.6, env: TOXENV=flake8 }
- { stage: test, python: 3.6, env: TOXENV=pylint }
- { stage: test, python: 3.6, env: TOXENV=readme }
allow_failures:
- env: TOXENV=flake8
- env: TOXENV=pylint
Expand Down
9 changes: 7 additions & 2 deletions pylint_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pylint.checkers.base import NameChecker
from pylint_plugin_utils import get_checker

from pylint_django.augmentations import apply_augmentations
from pylint_django.checkers import register_checkers

# we want to import the transforms to make sure they get added to the astroid manager,
Expand All @@ -26,4 +25,10 @@ def register(linter):
register_checkers(linter)

# register any checking fiddlers
apply_augmentations(linter)
try:
from pylint_django.augmentations import apply_augmentations
apply_augmentations(linter)
except ModuleNotFoundError:
# probably trying to execute pylint_django when Django isn't installed
# in this case the django-not-installed checker will kick-in
pass
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[tox]
envlist =
django_not_installed
flake8
pylint
readme
Expand All @@ -11,6 +12,7 @@ envlist =

[testenv]
commands =
django_not_installed: pylint --load-plugins=pylint_django ./setup.py | grep django-not-available
flake8: flake8
pylint: pylint --rcfile=tox.ini pylint_django setup
readme: python setup.py check --restructuredtext --strict
Expand Down

0 comments on commit 65850c7

Please sign in to comment.