We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Opening on behalf of @pwalsh (originally posted in different ticket).
With (snippets from pyproject.toml):
[tool.importlinter] root_packages = ["survey", "api", "django"] include_external_packages = true [[tool.importlinter.contracts]] name = "Dont use cache dependencies directly" type = "forbidden" source_modules = ["survey", "api"] forbidden_modules = ["django.core.cache"]
I would expect django.core.cache to be forbidden, but, I get a huge list of import errors as any import under django.* is listed as an error.
If I change root_packages to either
root_packages = ["survey", "api", "django.core"] # root_packages = ["survey", "api", "django.core.cache"]
then no linting errors related to the Django package are detected.
I'd like to, for example, prevent usage of anything under django.core.cache by raising lint errors. is this possible some other way?
The text was updated successfully, but these errors were encountered:
I get a huge list of import errors as any import under django.* is listed as an error.
Is it possible that the problem might be because a lot of django modules indirectly depend on django.core.cache?
For example, on a sample project I set up, I included an import of django.db.models in survey.main. I get this contract failure:
django.db.models
survey.main
---------------- Broken contracts ---------------- Dont use cache dependencies directly ------------------------------------ survey is not allowed to import django.core.cache: - survey.main -> django.db.models (l.1) django.db.models -> django.db.models.fields (l.39, l.38) django.db.models.fields -> django.core.checks (l.14) django.core.checks -> django.core.checks.caches (l.18) django.core.checks.caches -> django.core.cache (l.4) - survey.main -> django.db.models (l.1) django.db.models -> django.db.models.fields (l.39, l.38) django.db.models.fields -> django.core.checks (l.14) django.core.checks -> django.core.checks.caches (l.18) django.core.checks.caches -> django.core.cache.backends.filebased (l.5)
If you don't mind indirect imports, you could add allow_indirect_imports = true to the contract, i.e.
allow_indirect_imports = true
[[tool.importlinter.contracts]] name = "Dont use cache dependencies directly" type = "forbidden" source_modules = ["survey", "api"] forbidden_modules = ["django.core.cache"] allow_indirect_imports = true
Does that solve your problem?
Sorry, something went wrong.
No branches or pull requests
Opening on behalf of @pwalsh (originally posted in different ticket).
Original post
With (snippets from pyproject.toml):
I would expect django.core.cache to be forbidden, but, I get a huge list of import errors as any import under django.* is listed as an error.
If I change root_packages to either
then no linting errors related to the Django package are detected.
I'd like to, for example, prevent usage of anything under django.core.cache by raising lint errors. is this possible some other way?
The text was updated successfully, but these errors were encountered: