Hello, what is the preferred way of adding a speci...
# general
w
Hello, what is the preferred way of adding a specific dependency to only one file in a directory and still use the convenient
python_sources()
target? This one looks clean to me:
Copy code
python_sources(
    overrides={"script.py": {"dependencies":["dirctory:somelib"]}},
)
but since there is
python_source()
, i feel i should use it instead but then i cant use
python_sources()
anymore because
script.py
will be in multiple targets and receive this error:
UnownedDependencyError: Pants cannot infer owners for the following imports in the target
b
You can exclude the file from python_sources by prefixing it with an exclamation mark. https://www.pantsbuild.org/stable/reference/targets/python_sources#sources > Paths are relative to the BUILD file's directory. You can ignore files/globs by prefixing them with
!
. > Example:
sources=['example.py', 'new_*.py', '!old_ignore.py']
Though the overrides approach is also fine from my POV.
w
But this will override the sensible default set by pants right? According to the docs: ``('*.py', '*.pyi', '!test_*.py', '!test.py', '!tests.py', '!conftest.py', '!test.pyi', '!*_test.pyi', '!tests.pyi')``
Also, thank you for your help.
b
Yes. You could reference and extend them by:
Copy code
python_sources.sources.default
https://www.pantsbuild.org/dev/docs/using-pants/key-concepts/targets-and-build-files#extending-field-defaults
But definitely more verbose than then overrides.
h
I think
overrides
is more idiomatic
before it existed you would have had to do the sources exclusion dance you describe, but now that it does exist…
w
Thank you for your help. It seems like this is the way to go.