I'm having an issue where my source is here: `cont...
# general
g
I'm having an issue where my source is here:
container/package-a/bin/main.py
When creating pex_binary it's using the following import path
container.package_a.bin.main
instead of just
package_a.bin.main
. How can I fix this? ๐Ÿงต
b
Usually this will be related to source roots: https://www.pantsbuild.org/2.19/docs/using-pants/key-concepts/source-roots What does
pants roots
say for your repo?
๐Ÿ‘ 1
g
pants.toml:
Copy code
[source]
root_patterns = ["/"]
container/package-a/BUILD:
Copy code
poetry_requirements(
    name="poetry",
    resolve="package-a",
)
container/package-a/BUILD
Copy code
python_sources()

pex_binary(
    name="pex_binary",
    entry_point="main.py",
    resolve="package-a",
)
I was using
Copy code
[source]
root_patterns = ["/"]
instead of :
Copy code
[source]
marker_filenames = ["pyproject.toml"]
because the docs said they're the same.
b
Ah, it sounds like the latter might be more like what you want. That sounds like a bug in the docs, that we should fix. Can you find where you saw it specifically?
g
but I can say switching it to use
marker_filenames = ["pyproject.toml"]
yields a different result. This time though the import path is too short, i.e.
bin.main
when it should be
package_a.bin.main
b
Oh, right, hm. It looks like
container
needs to be the source root, so
root_patterns = ["container/", "...anything else..."]
would be closer
๐Ÿ‘ 1
g
I'm going to try hard coding the actual root pattern... ๐Ÿ™‚
b
Although... I don't know if
package-a
with a hyphen will behave as expected.
g
I'll report back shortly.
๐Ÿ‘ 1
b
at the very bottom
Oh, I think that's trying to say "for this specific example", but is definitely ambigious. Do you feel like contributing a fix to add an extra qualifier to that and the one above? (Not a problem if not!) https://github.com/pantsbuild/pants/blob/42ff1dd86a7c3b370a2802df272d27ff0bb42ce3/docs/docs/using-pants/key-concepts/source-roots.mdx#L354
๐Ÿ‘ 1
g
@broad-processor-92400 I started to think of wording and I'm actaully lost. I don't know in what context those two are the same.
I only know of the context when they're not the same.
So it's "working" in the sense that the import path is correct now; but I'm getting a
ModuleNotFoundError
-- I have no idea where to even begin to debug ๐Ÿ˜„
I'm guessing the pex_binary isn't correctly inferring dependencies and they need to be manually added.
b
Ah, hm, maybe something like: Pants can deduce the appropriate root using
pyproject.toml
as a marker file:
Copy code
[source]
marker_filenames = ["pyproject.toml"]
For this example, this pattern is equivalent to using the build root
/
as the fully-qualified pattern:
Copy code
[source]
root_patterns = ["/"]
And then similar for the earlier one, basically flip the code blocks to have the pattern version first, and then expand that to be the fully-qualified file paths second. Do you think that's clearer/would've avoided your confusion?
I'm guessing the pex_binary isn't correctly inferring dependencies and they need to be manually added.
yeah. Do you hvae any warnings about dependencies that can't be inferred? Which module isn't found?
g
> Ah, hm, maybe something like @broad-processor-92400 not really helpful. and I'm not sure how to clarify it.
b
okay, no worries! docs are hard ๐Ÿ˜…
๐Ÿ’ฏ 1
g
yeah. Do you hvae any warnings about dependencies that can't be inferred? Which module isn't found?
No warnings. When I call this it returns 0 deps
Copy code
pants dependencies container/package-a/bin:pex_binary
b
hm, it should definitely at least have
main.py
๐Ÿค” The first thing I'd check is if the hyphen is causing issues; is it easy to
mv package-a package_a
as an experiment, and see if that works better?
g
This fixed it...
Copy code
diff --git i/utility/company-devops/company_devops/BUILD.pants w/utility/company-devops/company_devops/BUILD.pants
index db46e8d6c9..fcc078087a 100644
--- i/utility/company-devops/company_devops/BUILD.pants
+++ w/utility/company-devops/company_devops/BUILD.pants
@@ -1 +1 @@
-python_sources()
+python_sources(resolve="company-devops")
diff --git i/utility/company-devops/company_devops/azure_devops/BUILD.pants w/utility/company-devops/company_devops/azure_devops/BUILD.pants
index db46e8d6c9..fcc078087a 100644
--- i/utility/company-devops/company_devops/azure_devops/BUILD.pants
+++ w/utility/company-devops/company_devops/azure_devops/BUILD.pants
@@ -1 +1 @@
-python_sources()
+python_sources(resolve="company-devops")
diff --git i/utility/company-devops/compdev/BUILD.pants w/utility/company-devops/compdev/BUILD.pants
index 0c23d586da..2db6047e1a 100644
--- i/utility/company-devops/compdev/BUILD.pants
+++ w/utility/company-devops/compdev/BUILD.pants
@@ -1,10 +1,11 @@
-python_sources()
+python_sources(resolve="company-devops")
 
 pex_binary(
     name="pex_binary",
     entry_point="main.py",
+    dependencies=[
+      "utility/company-devops/company_devops",
+      "utility/company-devops/compdev",
+    ],
     resolve="company-devops",
 )
diff --git i/utility/company-devops/compdev/commands/BUILD.pants w/utility/company-devops/compdev/commands/BUILD.pants
index db46e8d6c9..fcc078087a 100644
--- i/utility/company-devops/compdev/commands/BUILD.pants
+++ w/utility/company-devops/compdev/commands/BUILD.pants
@@ -1 +1 @@
-python_sources()
+python_sources(resolve="company-devops")
I started with adding dependencies and then the warnings where clear enough to update all automatically generated python_sources() with the resolve parameter.
Is it fair to say that pants hasn't been optimized to onboard repos that require 100's of custom resolves?
b
ah, that's not great that it was silently ignored, despite the explicit
main.py
reference as an entry point. Can you file an issue that cross-resolve
pex_binary
entry_point
s don't work. As a minor fix-up, now that you've been guided to update the resolves, does removing the explicit dependencies work?
g
@broad-processor-92400 I literally just tried that because my of my curiosity and it works without explicit dependencies!
b
Is it fair to say that pants hasn't been optimized to onboard repos that require 100's of custom resolves?
Yeah, I think so
๐Ÿ‘ 2
g
I can file a bug
b
Thank you!
g
you're welcome. If you want to collab on the docs update, I'm game. As a newcomer to pants I can't discern the difference between the two root sources arguments. My main feedback, is I'm not even sure why it's valuable to mention that the two are the "same" -- even though they're not really in all circumstances. Because when reading the docs, my original instinct was to use the marker filenames and when I read that they were identical, I updated my pants.toml.
b
Yeah, I see where you're coming from. I think the intention is to have both the pattern version and then "expand" the pattern into the equivalent set of explicit paths (like "here's what the short-hand means"), but that doesn't come across and, as you say, is maybe not valuable.
g
@broad-processor-92400 totally get it. I think what would be most useful is an expansion on how the two differ and where they're the same and elaborating wherever necessary. Because for new people (or at least for me), it reads, "we are literally identical in outcome, so feel free to use either one."
๐Ÿ‘ 1
Thanks for the quick help. The community here is amazing so far.
โค๏ธ 1