astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.88k stars 467 forks source link

Can't add relative path dependencies in virtual projects and pdm-backend projects #912

Open bluss opened 8 months ago

bluss commented 8 months ago

Steps to Reproduce

mkdir relativebug
cd relativebug
rye init a
rye init main
cd main
rye add a --path ../a
# Added a @ file:///home/user/ryes/relativebug/main/../a as regular dependency

cd ..
rye init main2 --virtual
cd main2
rye add a --path ../a
# error: Failed to run uv compile error: Distribution not found at: file:///a

Expected Result

In rye 0.29, it adds the dependency "a @ file:///${PROJECT_ROOT}/../a", to the virtual project (here "main2"). Note that a virtual project like main2 or a build_system=pdm project behave the same way, they both use the PROJECT_ROOT relative paths.

Actual Result

Error message

# error: Failed to run uv compile error: Distribution not found at: file:///a

Version Info

rye 0.30.0 commit: 0.30.0 (c7cbdd955 2024-03-19) platform: linux (x86_64) self-python: cpython@3.12.2 symlink support: true uv enabled: true

Stacktrace

No response

bluss commented 8 months ago

it's possible that #897 caused this bug

j178 commented 8 months ago

I'm struggling to construct a url:Url which seralizes to file:///${PROJECT_ROOT}/../a.

The only workaround I've found is to force using absolute path on Windows, as shown in the original commit of #897.

bluss commented 8 months ago

I see. Maybe we should avoid using the Url type if it can't represent this on Windows, maybe we can do so only for relative paths? I could look into that kind of change.

bluss commented 8 months ago

Uv supports relative paths directly, https://github.com/astral-sh/uv/pull/1027 but that's a divergence from pip and requirements syntax I think

bluss commented 8 months ago

Reverting just #897 doesn't help, there's also a change related to uv that contributes to this.

The ${} syntax ends up url escaped like file:///$%7BPROJECT_ROOT%7D/../a - multiple places in rye use format_requirement to undo this escaping, and if that's done when rye uses uv to resolve this URL too, that will work like it did previously.

Using relative paths instead of these strange URLs is viable at least if using only uv in the future, otherwise these URLs seem like the most "portable" way to handle relative paths right now. One reason is that pip install from requirements files accepts lines like "foo @ file:///some/url" but not "foo @ /some/path"

It would be good to update the pep508_rs crate and use VerbatimUrl in the new version (assuming it can do this better?), but it's not a trivial upgrade.

redat00 commented 7 months ago

Hey ! Just following up on this, I'm trying to add a module with a relative path, but I end up either with a broken path, or with an absolute path (which obviously can't be put inside of a git repository for anyone to work on).

Here the details of what I want to do.


Command :

rye add tester-common-lib --path "../mysuperlib"           

Output :

error: Failed to run uv compile error: Distribution not found at: file:///mysuperlib
. uv exited with status: exit status: 2

The following command will work, but, as the parameter suggest, it will create an absolute path in the pyproject.toml file, which I can't push into a repository for others to work on..

Command :

rye add tester-common-lib --path "../mysuperlib" --absolute          

Pyproject content :

"mysuperlib @ file:///home/redat00/Documents/perso/it/app/app-api/../mysuperlib",

Would love for the solution that @bluss wrote in #928 to at least be reviewed if possible. In my case this feature is important for me, and I would love to use Rye on my project ! :pray:

Thanks!

bluss commented 7 months ago

@redat00 The workaround I think you can use right now is to update the pyproject.toml directly, the problem here is with rye add and not other parts of needed steps (like rye sync) - at least I don't know of any problems there. Consider if you want to use a (non virtual) pdm build backend for the root instead, since then it should be more well defined how standard Python tools will treat your pyproject.toml-defined project.

redat00 commented 7 months ago

Indeed I was able to make it work with the latest version of Rye by manually adding the following :

    "mysuperlib @ file:///${PROJECT_ROOT}/../mysuper",

Thanks !