Open BigDeepBlue opened 1 year ago
I can confirm the same issue when tested with DJ12. I put some quick print()
calls in checkers/model_content_order.py
and confirmed that the checker is executing and seeing the nodes and yielding a DJ12.
def get_issues(self, node):
elements_type_found = []
for element in node.body:
print("checking element", repr(element))
element_type = self.get_element_type(element)
if not element_type:
continue
element_type_in_wrong_order = self.find_element_type_in_wrong_order(element_type, elements_type_found)
if element_type_in_wrong_order:
print("I should yield dj12")
yield DJ12(
element,
element_type,
element_type_in_wrong_order,
)
else:
elements_type_found.append(element_type)
I get all of the expected output, including an "I should yield dj12", but flake8 passes.
When I just run flake8 normally, including using the one installed in the pre-commit managed venv, I do get the DJ12 error.
@BigDeepBlue Found it. Looks like django
needs included in the additional_dependencies
of .pre-commit-config.yaml
It happens because pre-commit runs flake8 in separate environment from your development environment(where django not installed). So it can't detect if class is model or not, because it can't check is it inherited from django.db.models.Model
. So you need to add django
and django_extensions
(if you're using it for TimeStampedModel
for example) to your pre-commit config
I stuck with the issue that if I run flake8 admin.py manually - I see error DJ07, but when I try to do that in pre-commit hook, check passes silently. So.
Python 3.9.16 (main, Mar 10 2023, 13:37:42) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
admin.py
pyproject.toml
.pre-commit-config.yaml
requirements.txt
so when I created virtualenv and install there deps from requirements.txt, then I ran
So here I can see error from your plugin, well
Then if I do
git add admin.py
then runso in that case no violations were raised.. ( Don't have and idea why, I see from logs that plugin was loaded and in both cases I see in logs line -
flake8.checker MainProcess 278 DEBUG Logical line: "fields = "xxxxxxx""
, but in case when it was run under pre-commit the DJ* was not found.my git diff --stashed
so I'm sure it should raise DJ07 error.