I need 3rd party packages that I would normally ge...
# general
r
I need 3rd party packages that I would normally get from an "apt install" command. I'm not sure how to handle this in Pants. All of the libraries we used so far are python. Thanks
w
What have you tried so far? And what kind of packages?
r
Nothing yet. I'm not sure where to start. The package I'm trying to install now is ros-foxy-ros-base.
w
I've never used ROS before, so I don't really know whether those are pip installable packages, a dev environment, a system dep, etc?
r
They are not pip installable. It should be the same for all apt install packages - right?
w
As far as I know, there is no hermetic ROS plugin at the moment (e.g. Pants would pull down the appropriate ROS binaries, and use them on a per-repo basis). I'm presuming those are dependencies though, akin to having a compiler or other tooling installed on your machine? If they were something sitting in your requirements.txt like other python packages, then Pants could pull them down, wrap them into a pex, and off you go
c
I've used ROS before but it's been a long time and before I was using Pants. I currently use ffmpeg though and I would imagine a similar circumstance. Ffmpeg has python bindings and there are binaries that we just need to make sure exist before runtime
w
Yeah, my gut feel is that something would need to already be installed on the machine, and then using system_binaries to make a custom plugin, or using adhoc_tool as a placeholder to pull everything into the pants world https://www.pantsbuild.org/2.18/docs/ad-hoc-tools/integrating-new-tools-without-plugins https://www.pantsbuild.org/2.18/reference/targets/adhoc_tool
f
it all depends on what you are trying to achieve. IIUC, you are in situation when some of your Python dependencies are provided by system packages, e.g. by installing
apt install python3-apt
you'll be able to do
import apt
in your Python code that has access to the system
site-packages
. If you only want Pants to understand the imports in your code and not throw an
Copy code
UnownedDependencyError: Pants cannot infer owners for the following imports in the target
when it finds
import apt
, then you could either ignore it with
pants: no-infer-dep
pragma or abuse the default
python_requirement
target:
Copy code
python_requirement(
    name="python-requirement",
    modules=[
        "apt",
    ],
    requirements=[
        "python3-apt",
    ],
    tags=[
        "debian-package",
    ],
)
this will let Pants link the
import apt
to this package so you can reason about it. However, you won't be able to install those packages which is necessary if you'd like to do
pants run
or
pants test
. This is because Pants won't be able to install a system dependency into a sandbox where a goal process is running. If that's what you want, then you would need to extend Pants to provide support for Debian packages to be used as Python requirements so they are treated in the same way a Python requirement distributed via a Python wheel would. One way to achieve this would be to instruct Pants to bring system packages along when creating a virtual environment in a sandbox, so that all the Debian packages present in the runtime environment would be available in the sandbox virtual environment as well. Even though Pants is all about hermetic environments and having resources external to this hermetic sandbox would violate its principles, one can decide not to attempt to reproduce an "isolated" virtual environment and instead extend Pants to run tests with access to all (or some) system resources accessible on
PATH
.
👍 1
alternatively, you may have luck trying to ask Pants to ignore certain dependencies knowing that they will be present in the runtime environment (with resources accessible outside of the sandbox). This may break caching and things, but may get you closer to where you'd like to get. You may find https://github.com/pantsbuild/pants/issues/19552 to be useful to review.
r
Thanks all for your replies
@fresh-cat-90827 I have finally had a chance to get back to this. I have tried:
Copy code
python_requirement(
    name="ros-noetic",
    modules=[
        "apt",
    ],
    requirements=[
        "python3-apt",
    ],
    tags=[
        "ros-noetic-ros-base",
    ],
)
but I get the following error when I run `pants generate-lockfiles`: ERROR: Could not find a version that satisfies the requirement python3-apt (from versions: none) ERROR: No matching distribution found for python3-apt I understand the error but I do not know why. What is/is not pants looking for?
f
you cannot generate a lockfile with this input - there's no
python3-apt
PyPI package which is what Pants telling you in
Copy code
ERROR: Could not find a version that satisfies the requirement python3-apt (from versions: none)
ERROR: No matching distribution found for python3-apt
I'll start working on this in Pants rather soon as I only want to be able to model "provided" dependencies, but this is not something you can do yet
in a nutshell, one may want to tell Pants not to bother inferring dependencies for e.g.
import apt
because user knows that
python3-apt
installed in the build environment will provide this module (given PEX will have access to the extra system path, if
apt
module is not on a path already in the
PATH
)
r
@fresh-cat-90827 Could you please direct me to the relevant docs or explain the process to tell pants to defer dependencies?