Skip to content
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

Can't add relative path dependencies in virtual project #912

Open
bluss opened this issue Mar 20, 2024 · 8 comments · May be fixed by #928
Open

Can't add relative path dependencies in virtual project #912

bluss opened this issue Mar 20, 2024 · 8 comments · May be fixed by #928

Comments

@bluss
Copy link
Contributor

bluss commented Mar 20, 2024

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 (c7cbdd9 2024-03-19)
platform: linux (x86_64)
self-python: cpython@3.12.2
symlink support: true
uv enabled: true

Stacktrace

No response

@bluss
Copy link
Contributor Author

bluss commented Mar 20, 2024

it's possible that #897 caused this bug

@j178
Copy link
Contributor

j178 commented Mar 21, 2024

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

  • Url:parse("file:///${PROJECT_ROOT}/../a") and url.set_path("${PROJECT_ROOT}/../a") will shorten the .., resulting in file:///a.
  • Url::from_file_path("/${PROJECT_ROOT}/../a") panics on Windows.

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

@bluss
Copy link
Contributor Author

bluss commented Mar 21, 2024

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
Copy link
Contributor Author

bluss commented Mar 21, 2024

Uv supports relative paths directly, astral-sh/uv#1027 but that's a divergence from pip and requirements syntax I think

@bluss bluss changed the title Can't add path dependencies in virtual project Can't add relative path dependencies in virtual project Mar 21, 2024
@bluss
Copy link
Contributor Author

bluss commented Mar 23, 2024

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.

@bluss bluss linked a pull request Mar 23, 2024 that will close this issue
@redat00
Copy link

redat00 commented Apr 16, 2024

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 ! 🙏

Thanks!

@bluss
Copy link
Contributor Author

bluss commented Apr 16, 2024

@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
Copy link

redat00 commented Apr 17, 2024

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants