Skip to content
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 apps which are used in project but not directly imported #373

Open
anentropic opened this issue Sep 29, 2023 · 2 comments
Labels
needs-real-projects-test This issue is more easily tackled once we have a project in `real_project` that illustrate the issue P3 minor: not priorized research-needed type: feature request

Comments

@anentropic
Copy link

Is your feature request related to a problem? Please describe.
In a Django project there are often 3rd party Django apps that you install and use with your project, but do not get imported directly by your code.

Instead they are found as strings in the INSTALLED_APPS list in the settings.py of the Django project, and Django imports them as needed.

Describe the solution you'd like
Would love some sort of Django plugin that could be enabled and provides a way for these deps to be recognised as used.

Django projects typically specify the location of the settings file like this:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

It'd also be fine if I had to manually configure a Django settings path for the plugin.

Describe alternatives you've considered
I guess the alternatives would be either:

  • add these deps to ignore_unused
  • create a dummy file that has a real import for them

Additional context
Add any other context or screenshots about the feature request here.

@jherland
Copy link
Member

jherland commented Oct 2, 2023

Thank you for reporting this issue! Yes, we_do want to support Django projects, and what you suggest sounds very reasonable. At the same time, we're wary og putting too many specifics into FawltyDeps itself, in terms of how to recognize and work with many different project types. I've just written up #375 with some more general thoughts I've had on this and related issues.

We definitely want to improve how FawltyDeps deals with these situations, but it's hard to promise an improvement in the short term. We'll be sure to keep your issue in mind while working towards a more general solution.

@anentropic
Copy link
Author

anentropic commented Oct 2, 2023

Seems like there's two parts to this

  • dealing with the various package and builder formats (pip, pip-tools, poetry, pdm, hatch etc) to extract the deps specified for the project
  • something that statically analyses src code to extract deps explicitly used in the project

I have tried 4 or 5 unused-dep tools and they were all fine at the first part (I have a pdm project with pyproject.toml)

But none of them had a fully pluggable implementation for the second part

e.g. FawltyDeps and deptry both have distinct extractors for .py and .ipynb files, switched on filename extension

For Django projects we'd maybe want to do an extra pass, after the standard .py extractor, to look for INSTALLED_APPS

I don't really care about auto-detection of Django projects, I'm happy to manually configure the dep tool to "use the Django plugin" if such a thing became available

Maybe you could have like a registry of extractors, each coupled with a glob or regex path they act on, e.g.

import_extractors = [
  ("*.py", "python_extractor"),
  ("*.ipynb", "notebook_extractor"),
  ("app/settings.py|app/settings/*.py", "django_extractor"),
]

would define three passes that run in order (actually... probably don't even need to be ordered)

just an idea, thanks for considering 😄

@jherland jherland added P3 minor: not priorized research-needed needs-real-projects-test This issue is more easily tackled once we have a project in `real_project` that illustrate the issue type: feature request labels Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-real-projects-test This issue is more easily tackled once we have a project in `real_project` that illustrate the issue P3 minor: not priorized research-needed type: feature request
Projects
None yet
Development

No branches or pull requests

2 participants