https://pantsbuild.org/ logo
#general
Title
# general
g

gorgeous-eve-12553

12/16/2022, 3:58 PM
Does the lack of aarch64 linux support mean that I can’t use the docker target from a M1 Mac?
e

enough-analyst-54434

12/16/2022, 4:00 PM
No, these are independent things. Here you built a pex_binary on Mac and you want to run it in Linux - x86_64 / aarch64 aside - that will never fly. You need to tell Pants currently that the pex_binary is intended for a foreign platform with the platforms or complete_platforms fields.
This is tricky and fiddly and may not work. It only works if all dependencies your pex_binary requires are available as pre-build aarch64 compatible wheels.
g

gorgeous-eve-12553

12/16/2022, 4:01 PM
Is there a way for me to tell it the docker requires the linux pex, but I want to still use the MacOS llocally?
e

enough-analyst-54434

12/16/2022, 4:01 PM
Well, the simple way is 2 pex_binary targets side-by-side.
We used to support
platforms=["current", "...other..."]
- that may work for doing this with one target instead of 2.
g

gorgeous-eve-12553

12/16/2022, 4:04 PM
Perfect, I just found that myself, thank you.
e

enough-analyst-54434

12/16/2022, 4:05 PM
Like I said - very titchy - you must have pre-built wheels available for Linux aarch64 out in PyPI or via additional --find-links or --indexes for your full transitive dependency set,
Just 1 sdist-only dep will stop you in your tracks.
(We don't support cross-building)
h

happy-kitchen-89482

12/16/2022, 4:06 PM
I think soon Pants should be able to support cross-building in a container via Environments? I'm not sure of the scope of that feature
e

enough-analyst-54434

12/16/2022, 4:06 PM
But that requires Pants works on Linux aarch64
Which it doesn't quite yet
I think you've done work to make that closer to so though, right @happy-kitchen-89482?
g

gorgeous-eve-12553

12/16/2022, 4:17 PM
Given that I’ve now waited for 10 minutes for it to build a pex with 2 deps, I don’t think this is working…
image.png
Anything look off here?
e

enough-analyst-54434

12/16/2022, 4:21 PM
Yeah - didn't you claim the target image was aarch64?
Just a sec for a command that will unambiguously give you the right platform or complete_platform json
g

gorgeous-eve-12553

12/16/2022, 4:24 PM
I’m on a M1 Mac, so it defaults to aarch64, but this will go into production as an x86 image.
e

enough-analyst-54434

12/16/2022, 4:24 PM
Ok.
g

gorgeous-eve-12553

12/16/2022, 4:24 PM
But right now I’m still building the pex with the right deps for my image, haven’t even gotten to the docker_image target yet.
e

enough-analyst-54434

12/16/2022, 4:26 PM
Copy code
$ docker run --rm -it python:3.11 sh -c 'python -mvenv venv && venv/bin/pip -q install pex && venv/bin/pex3 interpreter inspect -v -i2'
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
{
  "path": "/venv/bin/python",
  "version": "3.11.1",
  "requirement": "CPython==3.11.1",
  "platform": "manylinux_2_31_x86_64-cp-3.11.1-cp311",
  "venv": true,
  "base_interpreter": "/usr/local/bin/python3.11"
}
You want that
"platform"
for that image, etc.
Better is to use
complete_platforms
. You get that via:
Copy code
$ docker run --rm -it python:3.11 sh -c 'python -mvenv venv && venv/bin/pip -q install pex && venv/bin/pex3 interpreter inspect --markers --tags -i2'
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
{
  "path": "/venv/bin/python",
  "compatible_tags": [
    "cp311-cp311-manylinux_2_31_x86_64",
...
    "py30-none-any"
  ],
  "marker_environment": {
    "implementation_name": "cpython",
    "implementation_version": "3.11.1",
    "os_name": "posix",
    "platform_machine": "x86_64",
    "platform_python_implementation": "CPython",
    "platform_release": "5.15.79.1-microsoft-standard-WSL2",
    "platform_system": "Linux",
    "platform_version": "#1 SMP Wed Nov 23 01:01:46 UTC 2022",
    "python_full_version": "3.11.1",
    "python_version": "3.11",
    "sys_platform": "linux"
  }
}
Put that JSON in a file, write a BUILD
file
target for it, and reference that target address in your `complete_platforms`list.
Obviously replace the image I used with the image you care about and the python inside it you care about.
(You can nuke the
"path"
in the complete platform JSON - just the `"compatile_tags"`and `"marker_environment"`are needed to form a complete platform specification.
And, if you did not realize resolves in the whacky world of Python could depend on fields like
"platform_version": "#1 SMP Wed Nov 23 01:01:46 UTC 2022"
- well, there you go. They can! Crazy. I've not seen one that does yet, but it's in the spec in PEP-508
g

gorgeous-eve-12553

12/16/2022, 4:33 PM
Well, that is certainly complicated…
e

enough-analyst-54434

12/16/2022, 4:34 PM
It is. 1 time setup per image though.
And its the only actual correct thing. `platforms`is a drastic abbreviation of all the info needed for a resolve and is lossy.
g

gorgeous-eve-12553

12/16/2022, 4:38 PM
So right now I have the platforms for my local mac, the aarch64 image I want to use, and the x64 image I want to use:
Or do I have to move to the complete_platform with all those giant blobs of JSON?
e

enough-analyst-54434

12/16/2022, 4:40 PM
You need
complete_platforms
when you need it. It is correct. The
platforms
(abbreviated platforms) are a lie that often can work. Try the lie and see how it goes, If you get weird errors, the 1st thing to do is switch to telling the whole truth.
Basically all that data in the complete platforms is needed to resolve. Given an abbreviated platform, Pex fills in the details of a complete platform that it can, but the full list of supported tags will be incomplete - so you'll miss resolving some matching wheels you otherwise could. Also, the environment markers will be incomplete; so if there is a requirement encountered in the resolve graph walk that uses one of those missing markers, the resolve will blow up and say something about a missing marker.
g

gorgeous-eve-12553

12/16/2022, 5:13 PM
After 30 minutes of building, the PEX never finished.
I think I’m going to give up on this for now and maybe revisit it in the future.
a

ancient-vegetable-10556

12/16/2022, 5:14 PM
https://pantsbuild.slack.com/archives/C046T6T9U/p1671206760462129?thread_ts=1671206302.655719&cid=C046T6T9U Right: Once there’s a stable Pants version with Target Environments, you should be able to get an x86 binary, by building inside docker using a
docker_environment
, but this feature isn’t on a stable version yet.
If you’re interested in seeing if an alpha version works, we may be able to help a bit
h

happy-kitchen-89482

12/16/2022, 7:48 PM
After 30 minutes of building, the PEX never finished.
Eeep... Which version of Pants is this? Using a newer underlying version of Pip may help with resolve-related perf issues. This is in the
pip_version
option in
[python]
.
oh, but this will only be available in 2.16
g

gorgeous-eve-12553

12/19/2022, 5:28 PM
@happy-kitchen-89482, this was using 2.14, fresh repo created just to show you this screenshot. It never actually finished, so it was likely stuck in an infinite loop somewhere. So I don’t think making it faster would help. And I wouldn’t mind trying out an alpha build for this whole thing. I also do a lot of development inside of VSCode devcontainers, which are obviously linux containers, but on my M1 Mac that also makes them aarch64 Linux containers, which means I can’t currently use pants in my development environment. We are slowly removing all “local development” off of physical hardware and into things like devcontainers for more consistent and reproducible devX. It makes onboarding a lot easier when I don’t have to give you a list of toolchains to install and I instead just say “attach your IDE of choice to this devcontainer and everything is pre-configured for you to start running the project and developing on it”.
e

enough-analyst-54434

12/19/2022, 5:31 PM
@gorgeous-eve-12553 older versions of Pip can actually take 30 minutes to hours in some perverse backtracking cases.
So Benjy's rec. may actually be relevant here.
@gorgeous-eve-12553 do you have interpreter constraints configured? Our defaults of
>=3.7,<4
don't help at all. Thats a massive range to find compatible artifacts for. If you don't need such a range, its a good idea to set an IC range that makes sense for your project(s).
Even when a
pex_binary
lists platforms, these are resolved from the lock (assuming you have enabled resolves / use a lock). The lock will still be universal and attempt to solve for the whole IC range.
g

gorgeous-eve-12553

12/19/2022, 5:45 PM
Gross, ok. I can test some things you if you would like me to.
e

enough-analyst-54434

12/19/2022, 5:52 PM
Ok, then you'd just try setting
2.16.0.dev3
as your
pants_version
and add a:
Copy code
[python]
pip_version = "22.3"
... and set up ICs if not done already! We should never default these for you like we do.
Something like the default
<4
clause is very bad, that includes the current Python 3.12 alphas which you almost certainly do not mean to support, etc.
h

happy-kitchen-89482

12/19/2022, 7:50 PM
Yeah, our default ICs are not smart. We should force users to pick specific interpreter versions.