Hi all, I have an issue when I try to package a p...
# general
b
Hi all, I have an issue when I try to package a pex_binary. I get the following error:
Copy code
ProcessExecutionFailure: Process 'Building src.python.herzensgut.accounts/serve.pex with 12 requirements: bcrypt==3.2.0, databases[postgresql]==0.5.3, email-validator==1.1.3, fastapi-health==0.4.0, fastapi-jwt==0.1.7, fastapi-mail==1.0.2, fastapi==0.70.0, passlib==1.7.4, pyjwt==2.0.1, python-dotenv==0.19.2, python-multipart==0.0.5, uvicorn==0.16.0' failed with exit code 1.
stdout:

stderr:
ERROR: Could not find a version that satisfies the requirement fastapi-jwt==0.1.7
ERROR: No matching distribution found for fastapi-jwt==0.1.7
The strange thing is, that running the
pex_binary
is working. This is my BUILD file:
Copy code
python_requirement(
    requirements=[
        "bcrypt==3.2.0",
        "fastapi==0.70.0",
        "fastapi-health==0.4.0",
        "fastapi-jwt==0.1.7",
        "fastapi-mail==1.0.2",
        "email-validator==1.1.3",
        "passlib==1.7.4",
        "pyjwt==2.0.1",
        "python-dotenv==0.19.2",
        "python-multipart==0.0.5",
        "uvicorn==0.16.0",
    ]
)

resources(
    name="queries",
    sources=[
        "**/*.sql",
    ],
)

resources(
    name="templates",
    sources=[
        "**/*.html",
    ],
)

python_sources(
    name="lib",
    sources=[
        "**/*.py",
    ],
    dependencies=[
        ":queries",
        ":templates",
        "src/python/herzensgut/shared:lib",
    ],
)

python_distribution(
    name="dist",
    dependencies=[
        ":lib",
    ],
    wheel=True,
    sdist=True,
    provides=setup_py(
        version="0.0.1",
        name="herzensgut.accounts",
        description="",
    ),
)

pex_binary(
    name="serve",
    restartable=True,
    entry_point="app/api/server.py",
)
Do you have an idea what the problem is? Thanks!
h
Is it possible that one of your other requirements is pulling it in transitively? Generally speaking, locking direct dependencies like that is likely to lead to an infeasible set of requirements for a package.
b
Thanks for your quick response! Hmm, no there is no other requirement which depends on the package. But, is there a better approach to organize direct dependencies?
h
There was a bit of discussion here
h
Hmm, why are you using a single
python_requirement
target for all the requirements? It means that they will always be depended on all together, and Pants won't be able to treat them as separate things. The more idiomatic way to do this would be to put those in a
requirements.txt
(or some other name) and point to it in a
python_requirements()
target .
Not sure this will solve this problem, but it stood out to me as a quirk
Also, what are the interpreter constraints in the repo? (in pants.toml)
fastapi-jwt 0.1.7
has the following interpreter constraints in its METADATA:
Requires-Python: <3.10,>=3.7
So possibly there is an interpreter incompatibility in play (e.g., you're using 3.6 or 3.10)
And finally, when you say "running the pex_binary is working", you mean
./pants run
is working but
./pants package
is not? That is strange
c
possibly related, or not, but:
you mean
./pants run
is working but
./pants package
is not? That is strange
I got this today on 2.9.0. Tried on 2.11.0rc0 and got a totally different error (but at least consistent between
run
and
package
) working on a repro, hopefully by tomorrow..
Actually, my issue was the other way around,
package
was working, while
run
would complain about missing dependencies. (and running the packaged pex worked just fine) (suspect a local_dists.pex issue, I think the
--intransient
fix from another of my issues is to blame for that)
b
Thanks for your reply Andreas. So, yep,
./pants run
is working but
./pants package
isn’t. This is my interpreter constraints:
Copy code
interpreter_constraints = [
    "CPython>=3.9.7",
]
So I dont think this is the cause.
h
Hmm, and what happens if you switch to
python_requirements()
and a
requirements.txt
file?
The error message mentions
databases[postgresql]==0.5.3
, which is not in the BUILD files, so I'm wondering where that came from
b
I’ve tried using the requirements.txt resulting in the same error. The databases[postgresql] dependency comes from the
shared:lib:
Copy code
python_requirements()

python_sources(
    name="lib",
    sources=["**/*.py"],
)

python_distribution(
    name="dist",
    dependencies=[":lib"],
    wheel=True,
    sdist=True,
    provides=setup_py(
        version="0.0.1",
        name="herzensgut.shared",
        description="",
    ),
)
Could the wheel / sdist setting being a problem? fastapi-jwt only provides a wheel file, as far I can see: https://pypi.org/simple/fastapi-jwt/
h
Yeah, it's a universal wheel so that shouldn't be an issue.
This is odd
Are you able to create a small repo that reproduces this, without exposing any internal proprietary stuff?
b
Yeah sure, will do this tomorrow, as it’s already 7 PM here in Germany 🙂 Until then, thank you very much for your help!
h
You're welcome! Ping us here with that repo and we'll keep digging 🙂 Have a good night!
b
After a last try I was able to solve the issue. 🎉 You have mentioned the interpreter constraints. Using the follwing interpreter_constraints in my pants.toml the package command succeeded.
Copy code
interpreter_constraints = [
    ">=3.9.7",
    "<3.10",
]
When I remove the “<3.10” it breaks. But I have absolutely no idea why this could break the process …
Thanks and have good day 🙂
h
Great! Glad that worked
I guess a 3.10 interpreter was being selected and it was incompatible with that package's Requires-Python.
IIRC Pants doesn't guarantee it'll pick the lowest matching interpreter, just that it'll pick one that matches.