poetry: Adding path dependency fails when given absolute path
Version: 1.0.0b9 (e943a4e)
Expected behaviour: I can add path dependencies specified by absolute path.
Actual behaviour: '/abs/path/to/dependency' does not start with '/abs/path/to/poetry-file/parent'
In poetry.console.commands.init:412(_parse_requirements) a call is made to
path.relative_to(), which raise
ValueErrorwhen
pathisn't a relative path to
cwd`.
I’m guessing that this was added thinking it behaves like os.path.relpath()
, which it doesn’t. AFAICT, there isn’t any functionality in pathlib
that does the same thing as os.path.relpath()
.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 15
- Comments: 18 (3 by maintainers)
Is there an update on this? I would greatly appreciate this functionality.
Any update on this? Would be really nice to do
poetry add /some/absolute/path
Putting an absolute path into the lockfile also breaks many CI setups and other interesting internal uses - an absolute path in a CI environment is highly unlikely to match up with an absolute path on my own computer.
Relative paths are probably better in general as they have a much better chance of being portable, but I could believe that’s not always what everyone wants.
Nevertheless: the problem that this issue covered was that adding direct paths simply didn’t work at all, and that clearly is fixed - so this issue should be closed, and I suggest that you should feel free to raise the other in a new one.
Update: I managed to get past the basic error being thrown when parsing the requirement, but this looks like it will require a change to
poetry-core
. These ultimately get modeled as a poetry-coreFileDependency
which always uses an absolute path, then the absolute path gets re-resolved relative to the project root when the lock file is being created inpoetry.packages.locker
Since
FileDependency
always makes it into an absolute URL, we lose the understanding of whether it was originally intended to be absolute or relative, then we don’t know which one to do when it comes to dump to the lock file.Have started working on this - not to say someone won’t beat me to it.
Basic approach is to replace
https://github.com/python-poetry/poetry/blob/master/poetry/console/commands/init.py#L441
with
Because at that point,
requirement
(the path provided by cli user) is fully vetted as a valid package. We can just accept the path as provided by the user. Tests bear this out so far@francojposa The “bug” label is still up, so I can only assume a PR would be well received.
Thanks for the quick reply! If it’s not documented and prints a
ValueError
raised from withinpathlib
, it’s not a feature 😃 That being said, I’d be happy with whatever outcome as long as I can produce a PR to improve the output.