refined-addition-53644
04/20/2022, 6:48 PMpackage
BUILD
__init__.py
-- sub-pkg1
-- sub-pkg2
then later we do say for testing
from package.sub-pkg1 import func1
pants will complain that this package.sub-pkg1 isn't a package since it can't infer the dependency unless I explicitly add in BUILD sub-pkg1 as dependency for package. Basically is there a way around providing this explicit dependency in such case.fast-nail-55400
04/20/2022, 6:49 PMsub-pkg1/__init__.py?refined-addition-53644
04/20/2022, 6:51 PMrefined-addition-53644
04/20/2022, 6:52 PM./pants dependencies package:package and it doesn't include sub-pkg1 as dependency unless I add it explicitlyfast-nail-55400
04/20/2022, 6:52 PMpackage/BUILD and package/sub-pkg1/BUILD?witty-crayon-22786
04/20/2022, 6:53 PMfast-nail-55400
04/20/2022, 6:54 PMpackage/sub-pkg1/BUILD listed as a file. If that is missing, you will need a python_sources target in that BUILD file. ./pants tailor can make all of the necessary BUILD files for you.refined-addition-53644
04/20/2022, 6:55 PMpackage though. That's why pants can't infer it. This is just a way to organize code inside package
@fast-nail-55400 yeah all the BUILD inside sub-pkg have python_sourcesfast-nail-55400
04/20/2022, 6:56 PMrefined-addition-53644
04/20/2022, 6:58 PMpackage1
package2
tests
and then when I run ./pants test tests:tests for testing package1 and package2, imports inside tests are like from package1.sub-pkg1 import func_to_test which complainsfast-nail-55400
04/20/2022, 6:59 PMfast-nail-55400
04/20/2022, 7:00 PMhundreds-father-404
04/20/2022, 7:02 PM./pants rootsrefined-addition-53644
04/21/2022, 11:25 AMrefined-addition-53644
04/21/2022, 12:00 PMrefined-addition-53644
04/21/2022, 1:55 PM___init___.py of tests. I moved all such imports to conftest.py where I define some pytest fixtures. This fixes the issue.
Not sure if this is how it should be i.e. using conftest/fixture. It does make more sense. On the other hand pytest on its own doesn't complain when importing everything inside ___init___.py Even in this case pytest runs the test successfully.witty-crayon-22786
04/21/2022, 4:32 PM__init__.py files: you can enable it with: https://www.pantsbuild.org/docs/reference-python-infer#section-inits