https://pantsbuild.org/ logo
#development
Title
# development
f

fresh-cat-90827

01/03/2023, 6:57 PM
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

bitter-ability-32190

01/03/2023, 6:59 PM
Can you provide more detail? Why is it OK that Pants isn't providing so many dependencies?
f

fresh-cat-90827

01/03/2023, 6:59 PM
because I know the module isn't there on file system 🙂 but will be at runtime 🙂
b

bitter-ability-32190

01/03/2023, 7:00 PM
Right, what does that mean? That it's coming from system python's
site-packages
or
dist-packages
?
f

fresh-cat-90827

01/03/2023, 7:02 PM
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

bitter-ability-32190

01/03/2023, 7:03 PM
So the file appears through some process in CI or in your build-pipeline, but isn't in-repo?
f

fresh-cat-90827

01/03/2023, 7:03 PM
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

bitter-ability-32190

01/03/2023, 7:06 PM
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

fresh-cat-90827

01/03/2023, 7:17 PM
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

curved-television-6568

01/03/2023, 7:50 PM
yea, I think the
.pyi
approach is a good one; great suggestion @bitter-ability-32190 🙂