pythonpantspython-polylith

PantsBuild fails to locate files in my workdir


I'm tring to run my project with pants

I work in a monorepo using the polylith structure and for some reson pants can't find my files

the file tree looks like this:

project
|
|--Workspace
|   |
|   |--bases
|   |--components
|   |  |--utils
|   |  |  |--some_file.py
|   |--projects
|   |  |--proj1
|   |  |  |--main.py
|   |--tests
|
|--pants.toml

In the pants.toml file I have the following defined:

...
[source]
root_patterns = [
  "/Workspace",
]
...

and I'm tring to import some_file from main like this:

from Workspace.components.utils import some_file

and according to this page: https://www.pantsbuild.org/2.19/docs/using-pants/key-concepts/source-roots As far as i understand this should work but instead I get:

ModuleNotFoundError: No module named 'Workspace'

i tried defining dependencies in the BUILD file for main.py but it can't see any file no matter how i change the paths in the build and the pants.toml [sources] and it returns another error:

pants.engine.target.InvalidFieldException: Workspace/projetcs/proj1: Failed to get dependencies for Workspace/projetcs/proj1/main.py: The file or directory 'components/utils' does not exist on disk in the workspace, so the address 'components/utils:some_file' from the `dependencies` field from the target Workspace/projetcs/proj1/main.py cannot be resolved.

Solution

  • i ended up giving up on dividing the Repo to different work spaces and having the base/project/components folders at the root of the project that did the trick