Skip to content

Commit 21487b4

Browse files
committed
Running black against the new Foreign Key checker and fixing CHANGELOG header
1 parent 26f3af3 commit 21487b4

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changelog
22
=========
33

4+
Version 2.3.1 (TBD)
5+
-------------------
6+
7+
- Allowed configuration of the Django settings module to be used via a
8+
commandline argument `#286 <https://github.com/PyCAQ/pylint-django/issues/286>`_
9+
- If Django settings are not specified via a commandline argument or environment
10+
variable, an error is issued but defaults are loaded from Django, removing the
11+
fatal error behaviour. `#277 <https://github.com/PyCAQ/pylint-django/issues/277>`__
12+
and `#243 <https://github.com/PyCAQ/pylint-django/issues/243>`__
13+
- Fixed tests to work with pylint>2.6
14+
415
Version 2.3.0 (05 Aug 2020)
516
---------------------------
617

pylint_django/checkers/foreign_key_strings.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import absolute_import
2+
3+
import astroid
24
from pylint.checkers import BaseChecker
3-
from pylint.interfaces import IAstroidChecker
45
from pylint.checkers.utils import check_messages
6+
from pylint.interfaces import IAstroidChecker
7+
58
from pylint_django.__pkginfo__ import BASE_ID
69
from pylint_django.transforms import foreignkey
7-
import astroid
810

911

1012
class ForeignKeyStringsChecker(BaseChecker):
@@ -41,15 +43,27 @@ class ForeignKeyStringsChecker(BaseChecker):
4143
),
4244
)
4345

44-
msgs = {"E%s10" % BASE_ID: ("Django was not configured. For more information run pylint --load-plugins=pylint_django --help-msg=django-not-configured", "django-not-configured", _LONG_MESSAGE),
45-
"F%s10" % BASE_ID: (
46-
'Provided Django settings %s could not be loaded',
47-
'django-settings-module-not-found',
48-
'The provided Django settings module %s was not found on the path'
49-
)}
46+
msgs = {
47+
"E%s10"
48+
% BASE_ID: (
49+
"Django was not configured. For more information run"
50+
"pylint --load-plugins=pylint_django --help-msg=django-not-configured",
51+
"django-not-configured",
52+
_LONG_MESSAGE,
53+
),
54+
"F%s10"
55+
% BASE_ID: (
56+
"Provided Django settings %s could not be loaded",
57+
"django-settings-module-not-found",
58+
"The provided Django settings module %s was not found on the path",
59+
),
60+
}
61+
62+
def __init__(self, *args, **kwargs):
63+
super().__init__(*args, **kwargs)
64+
self._raise_warning = False
5065

5166
def open(self):
52-
self._raise_warning = False
5367
# This is a bit of a hacky workaround. pylint-django does not *require* that
5468
# Django is configured explicitly, and will use some basic defaults in that
5569
# case. However, as this is a WARNING not a FATAL, the error must be raised
@@ -66,15 +80,15 @@ def open(self):
6680
# must wait until some module is inspected to be able to raise... so that
6781
# state is stashed in this property.
6882

69-
from django.core.exceptions import (
83+
from django.core.exceptions import ( # pylint: disable=import-outside-toplevel
7084
ImproperlyConfigured,
71-
) # pylint: disable=import-outside-toplevel
85+
)
7286

7387
try:
7488
import django # pylint: disable=import-outside-toplevel
7589

7690
django.setup()
77-
from django.apps import apps # pylint: disable=import-outside-toplevel
91+
from django.apps import apps # noqa pylint: disable=import-outside-toplevel,unused-import
7892
except ImproperlyConfigured:
7993
# this means that Django wasn't able to configure itself using some defaults
8094
# provided (likely in a DJANGO_SETTINGS_MODULE environment variable)
@@ -83,21 +97,33 @@ def open(self):
8397
# we will warn the user that they haven't actually configured Django themselves
8498
self._raise_warning = True
8599
# but use django defaults then...
86-
from django.conf import settings # pylint: disable=import-outside-toplevel
100+
from django.conf import ( # pylint: disable=import-outside-toplevel
101+
settings,
102+
)
87103
settings.configure()
88104
django.setup()
89105
else:
90106
# see if we can load the provided settings module
91107
try:
92-
from django.conf import settings, Settings # pylint: disable=import-outside-toplevel
108+
from django.conf import ( # pylint: disable=import-outside-toplevel
109+
settings,
110+
Settings,
111+
)
112+
93113
settings.configure(Settings(self.config.django_settings_module))
94114
django.setup()
95115
except ImportError:
96116
# we could not find the provided settings module...
97117
# at least here it is a fatal error so we can just raise this immediately
98-
self.add_message('django-settings-module-not-found', args=self.config.django_settings_module)
118+
self.add_message(
119+
"django-settings-module-not-found",
120+
args=self.config.django_settings_module,
121+
)
99122
# however we'll trundle on with basic settings
100-
from django.conf import settings # pylint: disable=import-outside-toplevel
123+
from django.conf import ( # pylint: disable=import-outside-toplevel
124+
settings,
125+
)
126+
101127
settings.configure()
102128
django.setup()
103129

@@ -108,7 +134,6 @@ def open(self):
108134
# duplicating the django_installed checker, it'll do for now. In the future, merging
109135
# those two checkers together might make sense.
110136

111-
112137
@check_messages("django-not-configured")
113138
def visit_module(self, node):
114139
if self._raise_warning:

pylint_django/transforms/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
fields.add_transforms(astroid.MANAGER)
1919

2020

21-
2221
def _add_transform(package_name):
2322
def fake_module_builder():
2423
"""

pylint_django/transforms/foreignkey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ def infer_key_classes(node, context=None):
108108
# 'auth.models', 'User' which works nicely with the `endswith()`
109109
# comparison below
110110
module_name += '.models'
111-
except ImproperlyConfigured:
111+
except ImproperlyConfigured as exep:
112112
raise RuntimeError("DJANGO_SETTINGS_MODULE required for resolving ForeignKey "
113113
"string references, see Usage section in README at "
114-
"https://pypi.org/project/pylint-django/!")
114+
"https://pypi.org/project/pylint-django/!") from exep
115115

116116
# ensure that module is loaded in astroid_cache, for cases when models is a package
117117
if module_name not in MANAGER.astroid_cache:

0 commit comments

Comments
 (0)