is it possible to “extend” dependency inference fo...
# plugins
s
is it possible to “extend” dependency inference for a custom target type? i.e. I’m considering making a custom target for Django
apps.py
files, to replicate the dependency rules that Django uses for pulling in models/migrations/templates etc. Our
apps.py
files are mostly lightweight, but a few import some 3rd-party libraries. wondering if I could implement a dependency-inference rule for
MyCustomDjangoAppsTarget
, and within the rule do something like
cast(PythonSourceTarget, my_custom_target)
, use that to run the “default” dependency inference for python code, then tack on the extra django-specific dependencies
f
Yes although the exact pattern to do so focuses on the subclassing field(s) in the target and not the original target per se.
🤔 1
1. Subclass either the source field (if you are using
InferDependenciesRequest
) or the
Dependencies
field (if using
InjectDependenciesRequest
) 2. Have your custom target use the same fields as the original target except use your subclassed field instead of the original field. The “target API” intentionally knows about the subclass relationship. Any request in other code for the base class will pick up your subclassed field. 3. Implement your dependency inference rule and use your subclass as what to inject/infer for.
s
aha nice, ty!
f
You can find examples in the Python rules. E.g.,
PythonTestsDependenciesField
(which uses this pattern to override a transitive excludes behavior)