Local path dependencies during development #3646
Replies: 3 comments 16 replies
-
This only leads to a conflict if Poetry considers possible that both sources can be used at the same time, but that is not possible.
I'd say |
Beta Was this translation helpful? Give feedback.
-
An option here might to talk about a net-new feature rather than coerce existing capabilities. For example, we could maybe introduce a new command pair This might function as follows. # add foobar as a dependency
poetry add foobar@1.0.0 # attach the local project into the active environment
poetry attach foobar /path/to/foobar One option, if we want to keep things isolated, might be to create the following. $ tree .poetry/
.poetry/
├── lock
└── override.toml
0 directories, 2 file
$ cat .poetry/override.toml
[tool.poetry.dependencies]
foobar = { path = "/path/to/foobar", develop = true } The # detach from active environment; remove temporary files
poetry detach foobar All that said, I am not convinced that this really brings much to the table than a workflow where you do something like this; poetry add foobar@1.0.0
poetry add -e /path/to/foobar
# do development what not
poetry add foobar@1.0.0 Is the ask in general that these "local" development dependencies be preserved in the Alternatively |
Beta Was this translation helpful? Give feedback.
-
Not sure if this can help the discussion here but on other langages I am used of having my dependencies loading first from the local That being said, we could imagine that: poetry publish --build --local-registry builds and store the generated artifact in the local filesystem. Running just behind poetry lock && poetry install would fetch this new package locally and install in in the Working that way would also mean that the [tool.poetry.dependencies]
# directory
my-package = "0.0.1-snapshot" VS [tool.poetry.dependencies]
# directory
my-package = { path = "../my-package/", develop = true } From the answer here: #1135 (comment) |
Beta Was this translation helpful? Give feedback.
-
What's the task?
I'm developing a tool
Tool
which relies on a libraryLib
which is under heavy development too. So I would like to add this library as a path dependency in editable mode during developingTool
. When publishing myTool
,Lib
should be handled as a normal dependency.A support by poetry for the above task is asked regularly, e.g. in #1168 (comment).
Why does poetry not support it (yet)?
poetry makes sure, that all defined dependencies are resolvable for the range of python versions defined in the
[tool.poetry.dependencies]
section. The result is stored in thepoetry.lock
, which makes it possible to create identical environments on different systems.Defining different sources for a package makes it necessary to resolve dependencies for all sources, because even if the name is equal, the defined dependencies can differ. This can lead to conflicts in dependency resolution.
Even one can assume that dependencies are equal, there's still the problem how to tell poetry from which source it should install the package?
Ideas about how to solve this problem are very welcome 😄
Is there a workaround?
Yes, it is! (But maybe it's not suitable for all use cases.)
To get it work, one have to publish a minimal release of
Lib
to the place, whereTool
can fetch it in production (pypi, private repository, git repository, ...). This minimal release must have defined all necessary dependencies.Once this is done, add
Lib
as a dependency toTool
in the normal way. poetry can resolve dependencies and installLib
.Now we can add the path to
Lib
to the environment variable PYTHONPATH . Doing this, python will look at this place for module files when running a script.How you set
PYTHONPATH
depends on your workflow. E.g. if you are using PyCharm you can attach theLib
project toTool
project and PyCharm will do that for you.If you are working within a terminal, it might be a good idea to create an
.env
file containing:and run
source .env
once when starting the terminal.Note: The dependency resolution, getting package metadata and installing scripts given in the
[tool.poetry.scripts]
are made based on your published minimal release. So if these things changes you have publish a new release, so poetry can fetch up these changes.Update 2024-07-09: In the meantime an alternative is to simply run
pip install -e /path/to/project
to temporary install the dependency in development mode.Beta Was this translation helpful? Give feedback.
All reactions