We have a pre-built `.whl` file which we have adde...
# general
r
We have a pre-built
.whl
file which we have added to our repo because it is particularly complex to build from source. This works fine if I use an absolute path as the requirement but can not find a way to make it work with relative paths.
Copy code
python_requirement(
    name="assimulo",
    requirements=[
        "assimulo@ file:////path/to/3rdparty/python/wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl"
    ],
)
Copy code
python_requirement(
    name="assimulo",
    requirements=[
        "assimulo@ wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl"
    ],
)
Is there a known path forward to use a relative path to a .whl as a requirement?
e
The key concept that makes this all a bit more clear is that Pants runs all processes in a sandbox (off in /tmp). As such relative paths only work if you include the target of the path in the sandbox, and you do this by dependending on files in BUILD files. If that's enough to get you rolling, I'll stop. If you need more I can spray beta.
r
Ah - I hardcoded the absolute paths when I first started playing around with pants and have just came back to it today when the path didn't exist on a coworkers machine 🙂 . Now that I know more about how pants works, I think I know what you are getting at. I'll give it a go on my end. Thanks!
Copy code
files(
    name="wheels",
    sources=[
        "wheel/*.whl",
    ],
)


python_requirement(
    name="assimulo",
    requirements=[
        "assimulo@ <file://3rdparty/python/wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl>"
    ],
    dependencies=[
        ":wheels"
    ]
)
^ This worked .. thanks again
Well almost, need to play with pip
Copy code
ValueError: non-local file URIs are not supported on this platform: '<file://3rdparty/python/wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl>'
e
Hrm, you may run into Pants nannying here unfortunately. So, Pip does not require
... @ url
style requirements. You can just pass it a relative path directly with no adornment. Pants may balk though.
Pip also supports env vars in requirement files; i.e.: `
Copy code
assimulo@ file://$PWD/3rdparty/python/wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl
Unfortunately, Pants also nanny's requirements files and splits them up into requirement strings that are then passed directly instead of beiung re-assembled into a requirement file.
Thinking but you may be stuck...
r
Yeah - running into how different tooling handles relative paths. Trying out a few more things. (https://github.com/pypa/pip/issues/6658)
e
I think the only way to do this today is by adding a find_links repo.
Just a sec for pointers there.
r
Ok - appreciate the help!
r
Will give this a go
e
So, in `pants.toml`:
Copy code
[python-repos]
repos = ["%(buildroot)s/3rdparty/python/wheel"]
And then to depend on wheels there use normal requirement strings.
The only place left to trip up is if pypi also provides a wheel. But if it does, you probably don't care. Presumably its only ornery sdists that you pre-build and check in wheels for.
r
Exactly ... no .whl on pypi 👍
🎉 - success. Thank you.
e
Ok. You probably still want the dependency on the wheel file though to fake invalidation. Without that, you'd upgrade the contents of the 3rdparty/python/wheel dir but the
[python-repos] repos
option would not change; nor would your requirement string necessarily, and Pants would no-op.
r
Ah - ok that makes sense
h
Well, you could specify the exact version in the requirement string, that would invalidate fine, right?
e
It would, but his example doesn't have that (
3rdparty/python/wheel/Assimulo-trunk-cp38-cp38-linux_x86_64.whl)
. Ideally the Pip relative path syntax approach and the Pip requirements supporting $PWD approach would be supported. But, IIRC we have issues tracking those and we're just not there yet.
We just get in the way on those due to lots of legacy not being fully unrolled.
r
I actually ended up updating my local setup such that the .whl was built with the version number correctly, as @happy-kitchen-89482 was getting at.
e
Good - that seems a bit easier to grok as a whole for random Betty looking at all this later.
r
To summarize the solution, adding the find-links repo allowed me to simply add
Assimulo==3.2
to
3rdparty/python/requirements.txt
h
That seems reasonably intuitive, great