Hi all, love pants and I'm trying it out for the f...
# general
c
Hi all, love pants and I'm trying it out for the first time on a monorepo project. There's a use case we have that I assumed was common, but it seems to me that pants doesn't support as I get the error message:
Copy code
InvalidSourceRootPatternError: `..` disallowed in source root pattern
The code layout is like this:
Copy code
.
└── repo-root/
    ├── apps/
    │   ├── app1/
    │   │   ├── .vscode
    │   │   ├── app1/
    │   │   │   ├── __init__.py
    │   │   │   └── app.py
    │   │   ├── pants.toml
    │   │   └── pyproject.toml
    │   └── app2/
    │       ├── .vscode
    │       ├── app2/
    │       │   ├── __init__.py
    │       │   └── app.py
    │       ├── pants.toml
    │       └── pyproject.toml
    └── libs/
        ├── __init__.py
        ├── my_cool_lib/
        │   └── __init__.py
        └── my_random_lib.py
... whoops hit Send too early, will continue the question here
The use case is that I'd like to open VS Code for either app1 or app2 and not for the whole repo. VS Code supports source roots that are not in a subfolder of the folder you've opened, so you can configure the app1 project to open the libs folder inline. I've done this before in PyCharm too.
The problem is that I can't define the pants source root patterns from the
pants.toml
in the app1 project directory to include the
libs
folder the same way that I can with the IDE.
I also tried it another way - putting the
pants.toml
in the
repo-root
folder, but then pants won't run in the app1 project folder (unlike e.g. git which can run in any subfolder of the repo).
Can I ask for assistance - am I missing how things are supposed to work? Or is this a known design choice that has been made and I'm trying to fight against the intended patterns?
g
I also tried it another way - putting the
pants.toml
in the
repo-root
folder, but then pants won't run in the app1 project folder (unlike e.g. git which can run in any subfolder of the repo).
This is the proper solution; and I'm not sure why pants would not work that way for you. Are you using the old
./pants
script?
l
I just checked, Tim, and it should work to run pants from a subdir of the repo. But I think the commands you issue will probably have to refer to targets based on the absolute path ... let me check ...
So like, in the example-python repo you can do:
Copy code
example-python $ cd helloworld/translator

example-python/helloworld/translator $ ls
BUILD                   translator.py
__init__.py             translator_test.py

example-python/helloworld/translator $ pants --no-local-cache test helloworld/translator/translator_test.py:tests

✓ helloworld/translator/translator_test.py:tests succeeded in 0.53s.
g
I'm quite sure that is also resolved in latest versions @late-advantage-75311 🙂 I'm able to
cd foobar && pants fix ./file.py
without issue in our local repo.
l
oh wow, yes it is, just bumped from 2.16 to 2.17 in example-python and it does work to do. Thank you @gorgeous-winter-99296!
Copy code
example-python/helloworld/translator $ pants test translator_test.py
c
Thanks @late-advantage-75311 and @gorgeous-winter-99296. I'll give it another crack!