If I know that a particular module won't be found ...
# development
f
If I know that a particular module won't be found at the dependency inference stage (i.e. I do not expect an import to be inferrable), I can add
# pants: no-infer-dep
to the import line. Do you think it would be sensible to add a new option to provide list of modules that should be ignored during the inference? It is a nuisance to add
# pants: no-infer-dep
in dozens of files that import a module that should be ignored:
Copy code
18:45:50.19 [WARN] Pants cannot infer owners for the following imports in the target foo/bar/baz.py:
  * some.odd.module.i.do.not.want.to.infer (line: 2)
I am pretty sure this is not currently configurable. If folks think that would be helpful, I'll take a look at the code to see if that would be possible to extend and what would be the effort like
1
b
Can you provide more detail? Why is it OK that Pants isn't providing so many dependencies?
f
because I know the module isn't there on file system 🙂 but will be at runtime 🙂
b
Right, what does that mean? That it's coming from system python's
site-packages
or
dist-packages
?
f
oh sorry, I should have been more clear. The module will be in the source code (after being generated) among the rest of the first-party code (
src/app/foo.py
) before the code is run in production.
b
So the file appears through some process in CI or in your build-pipeline, but isn't in-repo?
f
exactly that, yes
and it's not protobuf or similar, so I cannot use Pants to generate this; it's done with some
make
magic and friends :)
which I may dig into later, but for now it would be helpful just to ignore those imports as I'd like to error on unowned dependencies
b
Technically you can do A LOT in Pants through plugins 😛 . Is the set of files self-contained? You could make empty files in-repo. Or Add
.pyi
files so you could typecheck
🚀 1
f
Technically you can do A LOT in Pants through plugins
yes, I know 😛 wanted to check if people think it's a common request to ignore modules like that so that it's worth making it a core feature of Pants. How much of an effort do you think it would be to add such an option?
Is the set of files self-contained?
pardon me, do you mean if the generated file depend on anything else in the repo?
You could make empty files in-repo.
an important detail - the file is also generated locally to be able to run apps locally during the bootstrap of the local dev env. Having empty files checked in would trigger local Git diffs.
Or Add .pyi files so you could typecheck
I haven't realized having a stub would actually matter for the dep inference - I just created a copy of the file as
.pyi
and the inference didn't warn me this time. This may be worth investigating!
c
yea, I think the
.pyi
approach is a good one; great suggestion @bitter-ability-32190 🙂