Hi! I am struggling a bit with setting up dependen...
# general
a
Hi! I am struggling a bit with setting up dependencies in pants for python. My folder structure looks like this:
Copy code
pants.toml
packages/
    projA/
        src/projA
        tests/
        pyproject.toml
        setup.py
    projB/
        src/projB
        tests/
        pyproject.toml
        setup.py
    projC/
        src/projC
        tests/
        pyproject.toml
        setup.py
projB and projC depend on projA. I found https://github.com/jsirois/pants-issues-11118/tree/72b3d80283dcb66f80078201d474cc3fcef8cb6c and with that I could see that the tests are finding the package, meaning the tests of projA found projA at all. However, how do I now add third-party dependencies? My root patterns all look like this:
Copy code
root_patterns = [
    '/packages/projA/src',
    '/packages/projA/tests',
...
]
The projects were all created with PyScaffold if that helps. It is basically a package generator https://pyscaffold.org/en/stable/usage.html I would appreciate any help!
e
For more reading, see here: https://www.pantsbuild.org/prerelease/docs/python/overview/third-party-dependencies I would start adding 3rd party dependencies like this: 1. Follow https://www.pantsbuild.org/prerelease/docs/python/overview/lockfiles to enable lockfiles (ie. using pinned versions of libraries) 2. Create a
3rdparty/python
directory at the root (ie. so it is global to all projects) 3. Create a requirements.txt (or pyproject.toml) in
3rdparty/python
4. Add your 3rd party dependencies (see link for details) 5. Import a dep from a source code file and it should work. The idea is that you teach pants about your "universe of dependencies", and it will use dependency inference to make the 3rd party dependencies available to any source code that needs them. This is probably the simplest approach, and it comes with the benefit that all your source projects will use the same versions of each library (but not be bloated by any libraries that are not used). The downside is that if you have multiple projects that must use different versions of the same library (eg. a project using Django 3 and another using Django 4), this approach will not work, and you will need to look into "multiple resolves". It gets a bit more complicated, so I would only go there if you really need it.
Also go through https://www.pantsbuild.org/prerelease/docs/using-pants/setting-up-an-ide which contains some steps for exporting a virtualenvironment based on your lockfile. This is to enable your IDE to understand your 3rd party dependencies (ie. so it can syntax highlight and autocomplete and stuff)
a
Thanks! This really helped 🙂