pants icon indicating copy to clipboard operation
pants copied to clipboard

Using complete_platforms that loads a resource (instead of file) should show an error

Open Jackevansevo opened this issue 2 years ago • 0 comments

Describe the bug

repo example here: https://github.com/Jackevansevo/pants-complete-platforms-bug

import sqlalchemy
import greenlet

def handler():
    print(sqlalchemy.__version__)
    print(greenlet.__version__)

Running pants package :cloud_function gives me the following build error

A distribution for greenlet could not be resolved for /home/jackevans/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.9.
Found 1 distribution for greenlet that do not apply:
1.) The wheel tags for greenlet 3.0.3 are cp311-cp311-manylinux_2_28_x86_64, cp311-cp311-manylinux_2_24_x86_64 which do not match the supported tags of /home/jackevans/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/bin/python3.9:
cp39-cp39-manylinux_2_38_x86_64
... 809 more ...

If I use

resource(name="platforms", source="platforms.json")

Instead of

file(name="platforms", source="platforms.json")

Inside the following BUILD

python_sources(name="root")

python_requirement(name="sqlalchemy", requirements=["sqlalchemy"])

python_requirement(name="greenlet", requirements=["greenlet"])

python_google_cloud_function(
    name="cloud_function",
    complete_platforms=[":platforms"],
    handler="app.py:handler",
    type="http",
)

resource(name="platforms", source="platforms.json")
[GLOBAL]
pants_version = "2.20.0"
backend_packages = [
  "pants.backend.python",
  "pants.backend.google_cloud_function.python",
]

[python]
interpreter_constraints = ['==3.11.*']

IMO attempting to mistakenly use a resource instead of a file when loading complete_platforms should throw an error or at least show a warning when building python_google_cloud_function targets.

The complete_platforms docs state

Complete platforms should be addresses of file targets that point to files that contain complete platform JSON as described by Pex (https://pex.readthedocs.io/en/latest/buildingpex.html#complete-platform).

But would be nice if this could be turning into a warning/error.

Pants version 2.20.0 but also tested on 2.19*

OS Both!

Additional info

An equivalent pex_binary target that uses the same complete_platform resource works. The following builds with no issues (despite :platforms being a resource).

pex_binary(
    name="main",
    entry_point="app.py",
    complete_platforms=[":platforms"],
)

Jackevansevo avatar Apr 17 '24 22:04 Jackevansevo