-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Django #467
Comments
I'm looking for the same feature, haven't found any unused dependency checker yet which is pluggable enough to add a special case for Django |
Thanks for the feedback! I have not used Django myself, but I am assuming what needs to happen for this;
for module, locations in get_imported_modules_for_list_of_files(all_python_files).items() into something like for module, locations in (
get_imported_modules_for_list_of_files(all_python_files) +
get_imported_modules_for_django(django_settings_module)
).items() Although that line and the lines around it might need some refactoring because it has become quite a long list comprehension. I am a bit busy at this time, but if I have time in the near future I will try to get around to this. I will also tag this with 'Good first issue', so if someone else needs it earlier or feels like contributing, I hope the above lines can give some idea on how to get started. |
Not at all against implementing that, but depending on how the settings definition is implemented in a Django project, So this would probably only be implemented as a "best effort", should we go with parsing the attribute with AST, given how dynamic this could be. Ideally, we would resolve the attribute through an import, but this is not something we would want to do, as we don't want to tie |
Yes I think it's not solvable in most general case without importing Django settings file, I can see why you wouldn't want to do that. In which case maybe my solution would be something like a custom Django manage.py command which parses the INSTALLED_APPS and updates the deptry config to make exceptions for them. It wouldn't have to be part of deptry. Could be run automatically as a pre-commit hook. It would need a way to map from import names back to PyPI package names, but I guess that exists somewhere in deptry already that it could borrow. |
I'd be very interested in such a feature as well, since deptry indeed shows some false positives when used on a Django project. Although I'm not currently in the capacity to participate on the technical discussion for this support, I believe there is at least a couple more settings that should be mentioned: In Django, Databases and caches configuration are made through the CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache", # String representing module path
"LOCATION": REDIS_URL,
"OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
}
} Edit: Added the rest of my message... I pressed enter too soon 🙈. |
Can we use a special function that adds the dot syntax imports into a list of registered imports?
Replace all dot imports in the code with The benefit is that deptry doesn't need to support django specifically and it is generic enough to apply anywhere. |
We would also love to see this 🙏 |
Hey @anentropic , what about making optional |
Is your feature request related to a problem? Please describe.
We use
aws-xray-sdk
with our Django app.deptry
reports:I assume the reason for this is that the module is only referenced as part of the
INSTALLED_APPS
setting:Describe the solution you would like
I have seen the following used in other projects:
This could possibly be adopted:
Alternatively could code coverage reports be used to complete a better picture on what is executed?
The text was updated successfully, but these errors were encountered: