Replies: 6 comments
-
Managed to setup a simple npm registry that when the package manager visits The only difficulty is that if the package manager visits |
Beta Was this translation helpful? Give feedback.
-
I want to try this out. |
Beta Was this translation helpful? Give feedback.
-
Fwiw, pdm is a terrific packaging manager for python (I've deployed projects with it, e.g. adoc-math) with support for pnpm's functionality :-) |
Beta Was this translation helpful? Give feedback.
-
Does pdm work like npm or we still have to activate virtual environment? |
Beta Was this translation helpful? Give feedback.
-
i would be interested in this discussion if anyone if available. Poetry and hatch are not the "standard" in python, and both basically does their own caching and resolution without doing what pip already does. Both also "caches" the wheel to avoid fetching dependencies already downloaded. But
What is really missing in python:
|
Beta Was this translation helpful? Give feedback.
-
I would be interested in this dicussion also. We're really struggling to set up a Python monorepo with some of the basic guarantees provided by pnpm. We have a medium-ish collection of Python code. This entire topic is fluid enough that I think it might benefit from a live discussion. I would be willing to help coordinate that if people are interested. |
Beta Was this translation helpful? Give feedback.
-
I have recently started working on a Python project and package management is a bit of a mess in the Python ecosystem. A lot of the newer Python package managers are emulating
npm
.pipenv
is one of the newer package managers, but its incredibly slow and people are now moving away from it to an even newer one calledpoetry
. It seems that they are many years behind all the R&D that has gone into JS package managers likeyarn
andpnpm
.We are also looking at creating a monorepo for our project and there is no easy solution.
I wonder how much effort would be required to get pnpm to work with Python?
Thinking about a rapid MVP approach
Install-time dependency version resolving. Create a custom registry that will proxy
pypi.org
package registry but enrich the returned packages withpackage.json
manifests. This should allow us to use pnpm's battle-tested and flexible dependency resolution algorithm without any changes.Looks like there is a package format that can simply be copied to a location with no other install steps. This gives me hope that it could be as easy as I mention:
Or we just use
pip install
(like Poetry does) using Install from local archives. How we usepip install
would depend on whether we are going to get benefits from the symlinking and local caching, or whether we are more interested in the dependency resolution and monorepo support.a. Proxy pypi as an npm registry protocol. CON: Requires separate server.
b. Allow npm to support an alternate registry protocol (pip/pypi). Responses would still be converted to pnpm package manifest formats. But we would need to implement a new package downloader to work with the pypi registry.
Runtime dependency resolution. How do we make Python work with the nested
node_modules
structure?a. Would
shamelessly-flatten
get us most of the way there?b. Could we modify the Python package resolver to support Node's algorithm? The reason for this would be to support multiple versions of the same package...which I'm not sure the current Python package management solutions allow.
Overview of Python package importing can be found below.
sys.path_hooks
looks interesting.How Python resolves dependencies?
Good article: https://realpython.com/python-virtual-environments-a-primer/
https://docs.python.org/3/reference/import.html
It is common to use a "virtualenv". This simply modifies your
PATH
env var to prioritize apython
binary in a certain location to ensure Python uses virtualenv-specific dependencies.A virtualenv looks like this:
Python module search path (
sys.path
)sys.path
("Python module search path") is similar torequire.resolve.paths
PYTHONPATH
is similar toNODE_PATH
.sys.path
is an array of paths Python will look in to resolve animport
.DIFFERENCE: Python will not search upwards looking for packages in
node_modules
dirs like Node.js does.The python binary is located at
~/dev/my-project/.venv/bin/python
.sys.prefix
is determined by dropping the/bin
...so it becomes~/dev/my-project/.venv
(virtualenv root).Example (using
poetry
andpyenv
):See https://docs.python.org/3/library/site.html and https://github.com/python/cpython/blob/8510f430781118d9b603c3a2f06945d6ebc5fe42/Lib/site.py#L557
How Poetry works?
The package installation seems to just piggy-back on
pip install
, and its mostly just a dependency resolver for a custom package manifest format (pyproject.toml
) and a runner.See https://github.com/python-poetry/poetry/blob/master/poetry/installation/pip_installer.py
Poetry has an option to keep a project-specific directory of packages (similar to
node_modules
). You must enable the settingvirtualenvs.in-project = true
, and then it will create a dir calledmy-project/.venv
which contains a virtualenv like mentioned above.Beta Was this translation helpful? Give feedback.
All reactions