From d228460676ae9834c3d89ebddc98447ba5ab411f Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Fri, 9 Mar 2018 13:02:42 +0200 Subject: [PATCH] Let DjangoInstalledChecker warn when Django isn't available 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. NOTE: tox doesn't allow us to easily execute shell scripts and commands outside its virtualenv so I have to resort to ugly bash escaping to make this work! Finally properly fixes #96. --- .travis.yml | 10 +++++++--- pylint_django/plugin.py | 9 +++++++-- tox.ini | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6258fd4c..9ed2fe9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/pylint_django/plugin.py b/pylint_django/plugin.py index 06fb6f4d..9420e351 100644 --- a/pylint_django/plugin.py +++ b/pylint_django/plugin.py @@ -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, @@ -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 diff --git a/tox.ini b/tox.ini index 3f374773..350c073a 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ [tox] envlist = + django_not_installed flake8 pylint readme @@ -11,6 +12,7 @@ envlist = [testenv] commands = + django_not_installed: bash -c \'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 @@ -35,6 +37,7 @@ setenv = PIP_DISABLE_PIP_VERSION_CHECK = 1 PYTHONPATH = . whitelist_externals = + django_not_installed: bash clean: find clean: rm