deptry
deptry copied to clipboard
Support dependencies in inline script metadata (PEP 723)
Is your feature request related to a problem? Please describe.
Inline script metadata allow defining dependencies in Python files, that are scoped to a specific module and independents from a project. Although not easy, it could be nice to support this.
Describe the solution you would like
I'm not fully sure how this could be implemented at this time, TBH. Since the dependencies are independent from the project, for each script that contains inline script dependencies, this would imply either:
- having a dedicated virtual environment where we detect inline script metadata
- having a "degraded" mode where we try to guess the module name from the package name (and require users to set it manually if this doesn't match)
Technically, even if the dependencies are scoped to specific files, it's still possible to import modules from other scripts, so deptry would need to check for dependencies usages in all files used by the script, which makes things a bit complex, depending on the architecture of the module (if this ends up importing from parent modules for instance).
Additional context
It really doesn't seem that straightforward to support this, so maybe we'll dim that too complex to implement.
Creating this issue made me realise that we should maybe ignore files that contain inline script metadata, when we extract imports, as they likely are scripts that are independent from the project (even though I would expect most users to use a dedicated directory for those scripts, so maybe not too problematic).