New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workspace support #1505
Comments
That would be awesome. |
Yes it would be similar to Cargo:
For example, the content of [tool.pdm.workspace]
packages = ["packages/*"] File structure:
|
What would be the best workaround for now to emulate this feature at the least cost, @frostming? |
Using editable installs. Here is a simple example. parent [tool.pdm.dev-dependencies]
workspace = [
"-e file:///${PROJECT_ROOT}/packages/foo#egg=foo",
"-e file:///${PROJECT_ROOT}/packages/bar#egg=bar",
] Metadata of [project]
name = "foo"
version = "0.1.0"
[build-system]
requires = ["pdm-pep517"]
build-backend = ["pdm.pep517.api"] Metadata of [project]
name = "bar"
version = "0.1.0"
dependencies = ["foo"] # specify dependency of other packages inside your workspace as named requirement
[build-system]
requires = ["pdm-pep517"]
build-backend = ["pdm.pep517.api"] Then in the parent project, run: This should work NOW, the proposal in this issue will be a wrapper around the above with a more friendly UI. |
Background: major in Python, sometimes Scala (sbt) and Rust (cargo) I also want to propose a file layout with my opinion. Here is an example of my ideal PDM workspace:
And let me add some notes:
Other thoughts:
I create a repo (which could be transferred into PDM org) to illustrate current proposals of PDM workspace. Maybe we could write some specifications there or use repo for unit tests and examples in the future. Feedback is welcome and appreciated. I'm willing to help to develop workspace feature because I could use it in my projects right now. My concerning is I'm not an expert on Python packaging area yet, perhaps guidance under mentor are required. Finally, thanks for @frostming's efforts! |
And next problem struggle me is how to make linter tools (pre-commit hook / mypy / ruff / etc ...) fit for mono-repo. |
Just sharing my experience of trying to use pdm for a monorepo setup in case it's useful to anyone.
Basically you can probably technically make it work, but you'll need to write a bunch of custom scripts to make the DX tolerable. But it doesn't seem far to go, just some CLI sugar! I guess monas is your (frontming) experiment to resolve this? |
How does building wheels of packages with path dependencies work in this context? |
I would prefer to specify dependency versions in sub packages, rather than specifying path dependencies, and those dependencies, if included by the workspace, will be installed with the local paths: Something like: [project]
dependencies = [
"foo==${workspace_version}"
] And when being built, the version variable will be replaced with the real version in the current workspace. However, this is not valid PEP 621 metadata, which doesn't allow |
Imitating other popular tools may be wise to converge on a standard over time. |
I think this could be related to what I just wrote in a PDM discussions thread about monorepos: |
@frostming any progress with the above proposal? Is there any way to help with this coming to fruition? The workaround using editable installs is not working well. |
No, just run |
A fruitful initial design could be to accept multiple project root directories on the CLI and complete the operation in parallel. A later workspace definition-based feature could reuse a lot of this early work by running a subprocess under the hood. |
@frostming Okay, |
I would also be happy to help with any development |
@alexcochran There still exist many that is undetermined, such as how to reuse or refer the config from the parent project in subprojects, and that will inevitably bring some new fields to the |
@frostming I think that's a great direction. On the Node side, I think PNPM is a great model to reference. Their workspace design makes monorepo setup pretty trivial, and you can specify production and development dependencies for each project in their own package.json, very similar to how you have things working already |
There's several ways of organizing a monorepo (of course), and I suggest to have a look at the way the Polylith Architecture solves these kind of problems. I understand the need of PDM features and a cargo-like way of doing that. Polylith has a different take on this thing and focuses on the sharing code between projects, and a nice developer "single project"-like developer experience. This means all code will have the same linting and all other dev related things same across all code in the monorepo. You can use this architecture already today with PDM. I am the developer of the tooling support for this in Python, and there is a PDM-specific hook available. Really nice work with this way of interacting with PDM, by the way 👏 ⭐ The hook system has made adding tooling like this really simple. |
@DavidVujic IIUC, does it look like https://github.com/GreyElaina/Mina ? BTW, polylith is a wonderful project, good job! |
Thank you! I haven't seen the Mina repo before, but will have a look to learn if there are similarities. |
I have some interest in this feature. I'm currently with a monorepo using poetry at work, if workspaces are added to PDM I will immediately start migrating. I'd like to support its development wherever I can. For my use case, it's especially important that the feature works well with package registries. This is because I'm using a monorepo to manage multiple packages which need to be uploaded to an index. Dependencies would be specified as usual, using regular version requirements. In development it should prefer workspace packages if the version is valid, but when packaged and uploaded it should resolve versions using the index. I believe this behavior matches with pnpm workspaces, which has been mentioned before. I also want to clarify what is expected to happen when you install from a project rather than the workspace root. I would expect it to detect the workspace and function accordingly. Finally I want to clarify how non-pdm backends are treated. I think it makes sense to support alternative PEP517 compliant backends when they are specified in the pyproject.toml file. Not only does this make migration easier, it may be required in some cases. Like when you want to link to Rust code using maturin. I feel like this would be a common enough occurrence in practice that it warrants explicit support. |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: