hi - im running some tests with a `python_tests` t...
# general
a
hi - im running some tests with a
python_tests
target. I would like to add some regression tests that make use of data files (eg json) is there a way to have these included in the test run ? I tried adding `files`/`resources` but
python_tests
doesnt have these params, and if i try to add a non-py file to
sources
that also fails
c
You need to add a separate target for the data files like this:
Copy code
resources(
    name="data",
    sources=[
        "**/*.json",
    ],
)
Then make that a dependency of the tests target
a
ah, thanks
l
related to this, is there a way to write your python code such that pants can figure out these sort of dependenies?
or do you need to always specify a python -> resources dependency in a BUILD file?
h
We currently have [python-infer].string_imports for strings that look like modules, but it risks false positives (which mean less fine grained cache keys) We probably could do something more intelligent? like look for open() and the different resources APIs
c
i'm guessing it will have a hard time if you are programmatically constructing paths which we almost always are
1
h
True. And I do want to be aware of the risk of over engineering this here. Should stay something performant and predictable Probably no variable analysis 😂
l
would you consider allowing hints inline in the code? Like in a comment?
h
Definitely! We support that already for Shell by using Shellcheck comments (we use shellcheck as the import parser), and it works great Would you be interested in opening a GH issue with that idea? Maybe a suggested syntax?
l
sure
e
With
pyproject.toml
supported already, it seems like a good place when a project is leaning heavily on inference and wants minimal
BUILD
files.
h
What do you mean, like centralize config into pyproject.toml?
e
Yeah. Create a tool.pants section and put meta data that can't be inferred in their.
h
Given that we're multilingual, I think we'd want to stick with
pants.toml
rather than a Python-specific file like
pyproject.toml
. But definitely that's an option to move more config into
pants.toml
I bias towards it not being the best approach because it doesn't scale well. We generally believe metadata should live near the code it describes. But definitely still worth considering! What do you think are the benefits of putting in a centralized config file?
e
There is a
dependencies
section, but that is for pip installed dependencies.