billowy-motherboard-58443
10/01/2020, 4:21 PMNoOwnerError: No python_distribution target found to own gh/util/file_utils.py. Note that the owner must be in or above the owned target's directory, and must depend on it (directly or indirectly). See <https://www.pantsbuild.org/v2.0/docs/python-setup-py-goal> for how python_library targets are mapped to distributions.
aloof-angle-91616
10/01/2020, 4:22 PMimport gh.util.file_utils
(or from gh.util.file_utils import xxx
) anywhere in that target?billowy-motherboard-58443
10/01/2020, 4:23 PMaloof-angle-91616
10/01/2020, 4:24 PMpython_distribution()
too, which is likely more relevant:
So in practice, multiple libraries are typically bundled into a single distribution. Naively, you might think that a python_distribution publishes all the code of all the python_library targets it transitively depends on. But that could easily lead to trouble if you have multiple distributions that share common dependencies. You typically don't want the same code published in multiple distributions, as this can lead to all sorts of runtime import issues.
Instead, Pants applies the following algorithm:
billowy-motherboard-58443
10/01/2020, 4:25 PMaloof-angle-91616
10/01/2020, 4:25 PMbillowy-motherboard-58443
10/01/2020, 4:25 PMfile_utils
aloof-angle-91616
10/01/2020, 4:27 PMIf there are multiple such exported libraries at the same degree of ancestry, the ownership
is ambiguous and an error is raised. If there is no python_distribution that depends on L
and is its ancestor, then there is no owner and an error is raised.we are seeing "an error is raised" right now.
aloof-angle-91616
10/01/2020, 4:28 PMpython_distribution()
target (which i think is a transitive dep of gh/leader_election/*
) depends on file_utils
aloof-angle-91616
10/01/2020, 4:29 PM./pants dependencies
and rg file_utils
to see which files import file_utils
, and see where they intersect with the dependencies of the target you are trying to setup-py
aloof-angle-91616
10/01/2020, 4:29 PMaloof-angle-91616
10/01/2020, 4:29 PMrg
is ripgrep, you can use ack or ag or anything else toobillowy-motherboard-58443
10/01/2020, 4:29 PMgit grep file_utils
shows me the answer about who imports italoof-angle-91616
10/01/2020, 4:30 PMbillowy-motherboard-58443
10/01/2020, 4:30 PMbillowy-motherboard-58443
10/01/2020, 4:31 PMbillowy-motherboard-58443
10/01/2020, 4:31 PMbillowy-motherboard-58443
10/01/2020, 4:31 PMbillowy-motherboard-58443
10/01/2020, 4:32 PMbillowy-motherboard-58443
10/01/2020, 4:32 PMbillowy-motherboard-58443
10/01/2020, 4:32 PMbillowy-motherboard-58443
10/01/2020, 4:32 PMbillowy-motherboard-58443
10/01/2020, 4:32 PMaloof-angle-91616
10/01/2020, 4:32 PMbillowy-motherboard-58443
10/01/2020, 4:33 PMgh/util/file_utils.py
and util is not a dep of either core nor leader_electtionhundreds-father-404
10/01/2020, 4:33 PMResolveError: ‘core’ was not found in namespace ‘gh/core’.What’s the full message? Usually a ResolveError is when you use an address Pants doesn’t know about, and it will suggest some alternatives For example, if you mistype
:my_tgt
to be :my_tg
aloof-angle-91616
10/01/2020, 4:33 PMNoOwnerError
i think?billowy-motherboard-58443
10/01/2020, 4:34 PMbillowy-motherboard-58443
10/01/2020, 4:34 PMhundreds-father-404
10/01/2020, 4:35 PMit complains about gh/util/file_utils.pyIs anyone importing
file_utils.py
? ./pants dependees gh/util/file_utils.py
aloof-angle-91616
10/01/2020, 4:35 PMhundreds-father-404
10/01/2020, 4:36 PM./pants dependees
billowy-motherboard-58443
10/01/2020, 4:36 PMgit grep
but yesbillowy-motherboard-58443
10/01/2020, 4:37 PM$ git grep file_util
util/object_input.py:from gh.util.file_utils import load_list_from_file
billowy-motherboard-58443
10/01/2020, 4:37 PM./pants dependees gh/util/file_utils.py
Scrubbed PYTHONPATH=/home/mfischer/src/ghpylibs/python from the environment.
16:37:30.27 [WARN] <unknown>:56: DeprecationWarning: invalid escape sequence \.
16:37:30.27 [WARN] <unknown>:57: DeprecationWarning: invalid escape sequence \.
16:37:32.50 [WARN] <unknown>:587: DeprecationWarning: invalid escape sequence \{
16:37:32.52 [WARN] <unknown>:56: DeprecationWarning: invalid escape sequence \.
16:37:32.52 [WARN] <unknown>:57: DeprecationWarning: invalid escape sequence \.
16:37:32.80 [WARN] <unknown>:587: DeprecationWarning: invalid escape sequence \{
16:37:33.26 [WARN] <unknown>:614: DeprecationWarning: invalid escape sequence \w
16:37:34.20 [WARN] <unknown>:614: DeprecationWarning: invalid escape sequence \w
gh/util
gh/util/object_input.py
billowy-motherboard-58443
10/01/2020, 4:37 PMbillowy-motherboard-58443
10/01/2020, 4:38 PMhundreds-father-404
10/01/2020, 4:38 PMpants_version
in pants.toml
billowy-motherboard-58443
10/01/2020, 4:39 PMpants_version = "2.0.0b0"
billowy-motherboard-58443
10/01/2020, 4:39 PMhundreds-father-404
10/01/2020, 4:39 PM./pants
bash script reads the value and auto-updates for you.billowy-motherboard-58443
10/01/2020, 4:39 PMbillowy-motherboard-58443
10/01/2020, 4:41 PM16:40:55.45 [WARN] gh/garcon/selfserviceauthorization/model.py:614: DeprecationWarning: invalid escape sequence \w
_re12 = re.compile("^([01]?[0-9]):[0-5][0-9](\w{1,2})?$")
billowy-motherboard-58443
10/01/2020, 4:41 PMbillowy-motherboard-58443
10/01/2020, 4:42 PMimport
statements should show those warnings but...)hundreds-father-404
10/01/2020, 4:42 PMbillowy-motherboard-58443
10/01/2020, 4:42 PMgit grep
didbillowy-motherboard-58443
10/01/2020, 4:44 PMwitty-crayon-22786
10/01/2020, 4:51 PMbillowy-motherboard-58443
10/01/2020, 4:51 PMaloof-angle-91616
10/01/2020, 4:52 PMwitty-crayon-22786
10/01/2020, 4:52 PMaloof-angle-91616
10/01/2020, 4:52 PMbillowy-motherboard-58443
10/01/2020, 4:52 PMbillowy-motherboard-58443
10/01/2020, 4:53 PMbillowy-motherboard-58443
10/01/2020, 4:53 PMwitty-crayon-22786
10/01/2020, 4:54 PMwitty-crayon-22786
10/01/2020, 4:56 PMbillowy-motherboard-58443
10/01/2020, 5:01 PMbillowy-motherboard-58443
10/01/2020, 5:01 PMbillowy-motherboard-58443
10/01/2020, 5:01 PMwitty-crayon-22786
10/01/2020, 5:02 PMbillowy-motherboard-58443
10/01/2020, 5:17 PMwitty-crayon-22786
10/01/2020, 5:18 PMgh/util/file_utils.py
?witty-crayon-22786
10/01/2020, 5:19 PM*_distribution
, but *_library
witty-crayon-22786
10/01/2020, 5:20 PM./pants dependees gh/util/file_utils.py
should report itbillowy-motherboard-58443
10/01/2020, 5:20 PMbillowy-motherboard-58443
10/01/2020, 5:20 PMbillowy-motherboard-58443
10/01/2020, 5:20 PMgh/util:util_lib
gh/util/object_input.py:util_lib
witty-crayon-22786
10/01/2020, 5:21 PM*_distribution
is located where?billowy-motherboard-58443
10/01/2020, 5:21 PMwitty-crayon-22786
10/01/2020, 5:21 PMbillowy-motherboard-58443
10/01/2020, 5:21 PMwitty-crayon-22786
10/01/2020, 5:23 PMwitty-crayon-22786
10/01/2020, 5:24 PMbillowy-motherboard-58443
10/01/2020, 5:24 PMwitty-crayon-22786
10/01/2020, 5:24 PMbillowy-motherboard-58443
10/01/2020, 5:24 PMimport casssndra
billowy-motherboard-58443
10/01/2020, 5:25 PMwitty-crayon-22786
10/01/2020, 5:25 PMmodule_mapping
on https://www.pantsbuild.org/docs/python-third-party-dependencies … but you might not need a mapping if the requirement names match the importswitty-crayon-22786
10/01/2020, 5:26 PMbillowy-motherboard-58443
10/01/2020, 5:26 PMbillowy-motherboard-58443
10/01/2020, 5:26 PMhundreds-father-404
10/01/2020, 5:27 PMI want to edit how your docs left-gutter nav works.....We use readme.io to host our docs. I don’t think we can edit this easily
witty-crayon-22786
10/01/2020, 5:27 PMmodule_mapping
aspect in particular: can find in pagebillowy-motherboard-58443
10/01/2020, 5:29 PMbillowy-motherboard-58443
10/01/2020, 5:29 PMwitty-crayon-22786
10/01/2020, 5:30 PMcassandra-driver
but the import is cassandra
, then it’s likely that it will not be inferredbillowy-motherboard-58443
10/01/2020, 5:30 PMbillowy-motherboard-58443
10/01/2020, 5:30 PMbillowy-motherboard-58443
10/01/2020, 5:31 PMwitty-crayon-22786
10/01/2020, 5:31 PMbillowy-motherboard-58443
10/01/2020, 5:31 PMbillowy-motherboard-58443
10/01/2020, 5:32 PMwitty-crayon-22786
10/01/2020, 5:32 PMwitty-crayon-22786
10/01/2020, 5:32 PMwitty-crayon-22786
10/01/2020, 5:33 PMbillowy-motherboard-58443
10/01/2020, 5:34 PMbillowy-motherboard-58443
10/01/2020, 5:34 PMbillowy-motherboard-58443
10/01/2020, 5:35 PMbillowy-motherboard-58443
10/01/2020, 5:35 PMwitty-crayon-22786
10/01/2020, 5:35 PMwitty-crayon-22786
10/01/2020, 5:35 PMwitty-crayon-22786
10/01/2020, 5:35 PMbillowy-motherboard-58443
10/01/2020, 5:35 PMwitty-crayon-22786
10/01/2020, 5:36 PMwitty-crayon-22786
10/01/2020, 5:36 PMbillowy-motherboard-58443
10/01/2020, 5:36 PMbillowy-motherboard-58443
10/01/2020, 5:38 PMbillowy-motherboard-58443
10/01/2020, 5:38 PMbillowy-motherboard-58443
10/01/2020, 5:39 PMwitty-crayon-22786
10/01/2020, 5:39 PMwitty-crayon-22786
10/01/2020, 5:40 PMpython_requirements(..)
) should be next to the requirements.txt, wherever it is.hundreds-father-404
10/01/2020, 5:40 PMbillowy-motherboard-58443
10/01/2020, 5:40 PMMappingError: Failed to parse gh/leader_election/BUILD:
[Errno 2] No such file or directory: '/src/gh-pants-test/gh/leader_election/requirements.txt'
billowy-motherboard-58443
10/01/2020, 5:40 PMbillowy-motherboard-58443
10/01/2020, 5:41 PMwitty-crayon-22786
10/01/2020, 5:41 PMwitty-crayon-22786
10/01/2020, 5:41 PMpython_requirements(..)
definitionbillowy-motherboard-58443
10/01/2020, 5:43 PMbillowy-motherboard-58443
10/01/2020, 5:46 PMbillowy-motherboard-58443
10/01/2020, 5:46 PMbillowy-motherboard-58443
10/01/2020, 5:47 PMhundreds-father-404
10/01/2020, 5:47 PMcassandra
, you can run ./pants dependencies path/to/file.py
to check that //:cassandra-driver
is being properly inferredbillowy-motherboard-58443
10/01/2020, 5:48 PMbillowy-motherboard-58443
10/01/2020, 5:48 PMbillowy-motherboard-58443
10/01/2020, 5:48 PM'install_requires': (
'cassandra-driver',
'gh.config==0.1',
'gh.core==0.1',
'gh.util==0.1',
),
billowy-motherboard-58443
10/01/2020, 5:48 PMbillowy-motherboard-58443
10/01/2020, 5:49 PMbillowy-motherboard-58443
10/01/2020, 5:49 PMhundreds-father-404
10/01/2020, 5:49 PMit doesn’t check constraints.txt for that?Not for dependency inference. The
python_requirements()
target is a macro that reads your requirements.txt
and creates a bunch of python_requirement_library
targets for you automatically. One target per each distinct requirement. Dependency inference uses this when analyzing your imports.
Meanwhile, the constraints.txt
is solely used by Pex (which uses pip) when resolving requirements.billowy-motherboard-58443
10/01/2020, 5:49 PMbillowy-motherboard-58443
10/01/2020, 5:50 PMbillowy-motherboard-58443
10/01/2020, 5:50 PMbillowy-motherboard-58443
10/01/2020, 5:50 PMpython_requirements()
python_requirement_library(
name="cassandra",
requirements=["cassandra-driver==3.24"],
module_mapping={
"cassandra-driver": ["cassandra"],
},
)
`
hundreds-father-404
10/01/2020, 5:50 PMcassandra-driver
in your generated setup.py
, then you need the constraint that you want in requirements.txt
We very intentionally do not use your constraints.txt when generating setup.py. You might want your setup.py to be loose, like >=3.0,<4
, whereas a constraints.txt
should be pinning to a specific version like ==3.3
billowy-motherboard-58443
10/01/2020, 5:50 PMbillowy-motherboard-58443
10/01/2020, 5:51 PMhundreds-father-404
10/01/2020, 5:51 PMcassandra-driver
in your requirements.txt
. If it’s okay to be in your requirements.txt
, that’s simpler than explicitly defining a python_requirement_library
You would update your requirmenets.txt
to be cassandra-driver==3.24
, whereas right now it sounds like it’s cassandra-driver
billowy-motherboard-58443
10/01/2020, 5:52 PMbillowy-motherboard-58443
10/01/2020, 5:53 PMbillowy-motherboard-58443
10/01/2020, 5:53 PMhundreds-father-404
10/01/2020, 5:53 PMmodule_mapping
to your python_requirements()
macro
2. delete the python_requirement_library
target. This is important for dependency inference to work, otherwise you will have two targets describing the same requirement, and dep inference won’t know what to do with the ambiguity
3. Update your requirements.txt
to use ==3.3
billowy-motherboard-58443
10/01/2020, 5:54 PMbillowy-motherboard-58443
10/01/2020, 5:54 PMhundreds-father-404
10/01/2020, 5:54 PMbillowy-motherboard-58443
10/01/2020, 5:55 PMbillowy-motherboard-58443
10/01/2020, 5:55 PMbillowy-motherboard-58443
10/01/2020, 5:56 PMbillowy-motherboard-58443
10/01/2020, 5:56 PMpython_requirements(
# mapping for "pip install name is different from import name"
module_mapping={
"cassandra-driver": ["cassandra"],
},
)
billowy-motherboard-58443
10/01/2020, 5:56 PMhundreds-father-404
10/01/2020, 5:57 PMrequriements.txt
. Pants doesn’t know that import cassandra
means cassandra-driver
. So updating requirements.txt
doesn’t do anything.
But, it does know about the inline target you created in the BUILD file, which is why the value is still showing up.
--
Now, once you do #1 but not yet #2, you have the issue that you now have two distinct targets that are both mapped to the import cassandra
. This results in neither target being used, and nothing showing up at all. Dependency inference cannot disambiguate what you want.
--
It requires all 3 steps to work properly.hundreds-father-404
10/01/2020, 5:57 PM