quaint-gold-40000
07/26/2021, 1:13 PM...
ResolveError: No owning targets could be found for the file `dir/package-a/tests/conftest.py`.
Please check that there is a BUILD file in the parent directory dir/package-a/tests with a target whose `sources` field includes the file. See <https://www.pantsbuild.org/v2.6/docs/targets> for more information on target definitions.
quaint-gold-40000
07/26/2021, 1:13 PM~/Repo develop $ ./pants test "dir/package-a::"
15:00:52.67 [WARN] Unmatched globs from dir/package-a's `sources` field: ["dir/package-a/*.py", "dir/package-a/*.pyi"], excludes: ["dir/package-a/*_test.py", "dir/package-a/*_test.pyi", "dir/package-a/conftest.py", "dir/package-a/test_*.py", "dir/package-a/test_*.pyi", "dir/package-a/tests.py", "dir/package-a/tests.pyi"]
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.6/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
15:00:52.73 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 234, in _run_inner
return self._perform_run(goals)
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 173, in _perform_run
return self._perform_run_body(goals, poll=False)
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/bin/local_pants_runner.py", line 190, in _perform_run_body
return self.graph_session.run_goal_rules(
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/init/engine_initializer.py", line 135, in run_goal_rules
exit_code = self.scheduler_session.run_goal_rule(
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/engine/internals/scheduler.py", line 533, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/home/user/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0rc2_py39/lib/python3.9/site-packages/pants/engine/internals/scheduler.py", line 501, in _raise_on_error
raise ExecutionError(
Exception message: 1 Exception encountered:
ResolveError: No owning targets could be found for the file `dir/package-a/tests/conftest.py`.
Please check that there is a BUILD file in the parent directory dir/package-a/tests with a target whose `sources` field includes the file. See <https://www.pantsbuild.org/v2.6/docs/targets> for more information on target definitions.
You may want to run `./pants tailor` to autogenerate your BUILD files. See <https://www.pantsbuild.org/v2.6/docs/create-initial-build-files>.
(Use --print-stacktrace for more error details and/or --no-process-execution-local-cleanup to inspect chroots and/or -ldebug for more logs. See <https://www.pantsbuild.org/v2.6/docs/troubleshooting> for common issues. Consider reaching out for help: <https://www.pantsbuild.org/v2.6/docs/getting-help.>)
quaint-gold-40000
07/26/2021, 1:15 PMdir/
package-a/
src/
...
tests/
conftest.py
test_something.py
BUILD
pants.toml
That BUILD file:
python_library()
python_tests(name="tests", sources=["tests/test_*.py"])
fast-nail-55400
07/26/2021, 1:19 PMconftest.py
from python_libary
(and its assignment to python_tests
) appears to only work if it is in the same directory as the python_tests
target. See https://github.com/pantsbuild/pants/blob/ddc3c3d791178a610a9b8988cb74ac072bdac9c0/src/python/pants/backend/python/target_types.py#L412 where it does not have a **
.
Try moving the python_tests
target to a BUILD
file in dir/package-a/tests
and it should work.fast-nail-55400
07/26/2021, 1:20 PM::
in a spec will find all targets deeper in the directory tree.quaint-gold-40000
07/26/2021, 1:23 PMpython_library()
and another with python_tests()
? Just wondering whether a link between the code and tests is then somehow lost?quaint-gold-40000
07/26/2021, 1:32 PMfast-nail-55400
07/26/2021, 1:46 PMfast-nail-55400
07/26/2021, 1:47 PMhappy-kitchen-89482
07/26/2021, 6:22 PMsrc
and tests
. The default sources for the python_library()
are non-recursive *.py
(minus test-related files), so no files in your src
directory are currently covered by a target (unless there's a BUILD file in src
that you didn't mention), and neither is conftest.py
, since you provided explicit sources in your python_tests
target that don't include conftest.py
happy-kitchen-89482
07/26/2021, 6:23 PMhappy-kitchen-89482
07/26/2021, 6:24 PM./pants tailor dir/package_a
it will generate BUILD files that should just work.happy-kitchen-89482
07/26/2021, 6:25 PMsources
manuallyhappy-kitchen-89482
07/26/2021, 6:26 PMpython_library(sources=['src/**/*.py'])
python_tests(name="tests", sources=["tests/**/*.py"])
Then conftest.py
will be captured by the python_tests
target.happy-kitchen-89482
07/26/2021, 6:27 PMhappy-kitchen-89482
07/26/2021, 6:27 PMtests
is test-related and no code under src
is, so you don't need to worry about separating tests from non-tests by looking at a test_
prefix of _test
suffix and so on...happy-kitchen-89482
07/26/2021, 6:28 PMhundreds-father-404
07/26/2021, 6:49 PMpython_library(sources=['**/*.py', '!**/*_test.py', '!**/conftest.py'])
python_tests(name="tests", sources='**/*_test.py', '**/conftest.py'])
witty-crayon-22786
07/26/2021, 7:28 PMtailor
is recommended rather than maintaining disjoint globs: see https://pantsbuild.slack.com/archives/C046T6T9U/p1627323890454200?thread_ts=1627305207.450800&cid=C046T6T9Uwitty-crayon-22786
07/26/2021, 7:30 PMquaint-gold-40000
07/27/2021, 8:08 AMYou'll probably want
python_library(sources=['src/**/*.py'])
python_tests(name="tests", sources=["tests/**/*.py"])
ThenÂBut dependency inference doesn't work for PyYAML (Â will be captured by theÂconftest.py
 target.python_tests
import yaml
).quaint-gold-40000
07/27/2021, 8:26 AMsrc
dir):
python_library(
sources=["**/*.py"],
dependencies=["mymodule/foo.py:PyYAML"],
)
yields
ResolveError: The file or directory 'mymodule/fo.py' does not exist on disk in the workspace, so the address 'mymodule/fo.py:PyYAML' cannot be resolved.
EDIT: figured this out (more below)quaint-gold-40000
07/27/2021, 8:35 AMquaint-gold-40000
07/27/2021, 8:40 AMpython_requirements
in place, ./pants dependencies dir/package-b/module.py
does finally list PyYAML and the tests run.quaint-gold-40000
07/27/2021, 8:43 AMquaint-gold-40000
07/27/2021, 8:54 AMpython_requirements()
creates new "3rd party" targets, which I need to reference.quaint-gold-40000
07/27/2021, 9:03 AMquaint-gold-40000
07/27/2021, 9:09 AMsrc
dir) that the tests fail to import _package_a_ (in conftest.py).
E ModuleNotFoundError: No module named 'package_a'
quaint-gold-40000
07/27/2021, 9:17 AM$ ./pants dependencies "dir/package-a/tests/conftest.py"
dir/package-a/src/package_a/database.py:../../package-a
dir:Sphinx
quaint-gold-40000
07/27/2021, 9:22 AMIf you delete your BUILD file and runÂÂ it will generate BUILD files that should just work../pants tailor dir/package_a
quaint-gold-40000
07/27/2021, 9:23 AM./pants tailor dir/package_a
generates BUILD files everywhere, not just in dir/package-a. Is that expected?quaint-gold-40000
07/27/2021, 9:30 AM$ ./pants list "::"
dir
dir:PyYAML
dir:Sphinx
dir:requirements.txt
dir:setuptools
dir/package_b
dir/package_b/package_b
dir/package_b/tests
dir/package-a/src/package_a
dir/package-a/tests
quaint-gold-40000
07/27/2021, 10:33 AMwitty-crayon-22786
07/27/2021, 5:57 PMI had to kill pantsd for a new dependency added to requirements.txt to be picked up.this is an unfortunate bug, sorry about that. 1) you shouldn’t need the `requirements.txt`: the poetry
pyproject.toml
is an alternative to a requirements file (although point 2 still applies).
2) there is supposed to be a hack in place to restart pantsd
for requirements.txt
/ pyproject.toml
changes to work around this bug, but it only matches files named 3rdparty/**/requirements.txt
or requirements.txt
(at the root): you can add config like the following to the [GLOBAL]
section of pants.toml
to work around it:
pantsd_invalidation_globs.add = [
"/the/path/to/my/requirements.txt",
]
happy-kitchen-89482
07/27/2021, 10:48 PMrequirements.txt
or Poetry stanzas in pyproject.toml
are how you specify the universe of possible 3rd-party dependencies, from which dep inference selects.happy-kitchen-89482
07/27/2021, 10:49 PMWhich version of Pants are you on? generates BUILD files everywhere, not just in dir/package-a. Is that expected?./pants tailor dir/package_a
hundreds-father-404
07/27/2021, 10:49 PMhappy-kitchen-89482
07/27/2021, 10:52 PMtailor
on just a subdir was not cherry-picked into 2.6.x, so it will only be available in 2.7.0happy-kitchen-89482
07/27/2021, 10:52 PMquaint-gold-40000
07/28/2021, 9:25 AMhappy-kitchen-89482
07/30/2021, 5:38 PM