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

uv compile now shows annotations for -c and -r paths that causes issues cross platform #3800

Closed
inoa-jboliveira opened this issue May 23, 2024 · 10 comments · Fixed by #3804
Closed
Assignees
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@inoa-jboliveira
Copy link

inoa-jboliveira commented May 23, 2024

Since uv 0.2.x the pip compile tool adds -r and -c annotations on the "via" part of the code, but uses windows-style paths when running on Windows, not respecting the command line on "-c".

tested both
uv 0.2.1 (1fc71ea 2024-05-22)
uv 0.2.2 (e52ae0e 2024-05-22)

See diff below
Screenshot 2024-05-23 154932

my command line is (I run from the project root):
uv pip compile ./requirements/requirements.in -o ./requirements/requirements-win.txt --python-platform=windows

I run the same command line on Windows and on my Linux CI, I make sure to always use forward slashes so outputs are compatible.

In my "requirements.in" file there is a line -c dependencies.txt since the file is in the same directory, I cannot prefix it with "-c requirements/dependencies.txt" so UV gets to chose how to build the path.

I like having the annotations and wouldn't want to switch to "--no-annotate", but running the same command in 2 different OSs now accuses a diff in the files.

Since UV already respects the forward slashes when I pass "requirements/requirements.in", could it use the same prefix of the file containing the value when prefixing names that are relative?

@charliermarsh
Copy link
Member

Hmm, I think the annotation should match whatever form is used verbatim. What is the exact form used in requirements.in?

@charliermarsh
Copy link
Member

Can you include a requirements.in file that replicates it along with the command? Thanks!

@charliermarsh
Copy link
Member

Oh sorry I see. You're using a relative path. Hmm...

@charliermarsh charliermarsh added the windows Specific to the Windows platform label May 23, 2024
@inoa-jboliveira
Copy link
Author

Simplified version of my setup:

  • /project-root/
    • requirements/
      • requirements.in
      • dependencies.txt
      • requirements-win.txt
    • compile.bat

requirements.in:

-c dependencies.txt
bcrypt
bs4

dependencies.txt

pip>24

compile.bat (it contains just the commands so I use it both as a bat and sh file)

uv pip compile ./requirements/requirements.in -o ./requirements/requirements-win.txt --python-platform=windows

@inoa-jboliveira
Copy link
Author

I would be ok with the -c being verbatim. Althought it woud be less correct i guess

@inoa-jboliveira
Copy link
Author

inoa-jboliveira commented May 23, 2024

Funny thing that I just noticed: you already use ./requirements and join with \ the \dependencies.txt
So you more or less do what I described. Probably getting one extra char from the same string you extract the prefix will solve the issue

@charliermarsh
Copy link
Member

I agree that it would be nice to be consistent here. Will look into it.

@charliermarsh charliermarsh added the bug Something isn't working label May 23, 2024
@charliermarsh
Copy link
Member

Marking as a bug.

@inoa-jboliveira
Copy link
Author

I think this could be solved in the user_display method (or maybe the origin.path()). I am having issues with the rust debugger on Windows right now, but I think at this point it should be possible to acquire the path separator.

Self::Constraint(origin) => {
write!(f, "-c {}", origin.path().user_display())
}
Self::Override(origin) => {
write!(f, "--override {}", origin.path().user_display())
}

fn user_display(&self) -> std::path::Display {
let path = dunce::simplified(self.as_ref());
// Attempt to strip the current working directory, then the canonicalized current working
// directory, in case they differ.
path.strip_prefix(CWD.simplified())
.unwrap_or_else(|_| {
path.strip_prefix(CANONICAL_CWD.simplified())
.unwrap_or(path)
})
.display()
}

pub fn path(&self) -> &Path {
match self {
RequirementOrigin::File(path) => path.as_path(),
RequirementOrigin::Project(path, _) => path.as_path(),
}
}

Here is the original PR published in v0.1.43

@charliermarsh charliermarsh self-assigned this May 23, 2024
charliermarsh added a commit that referenced this issue May 24, 2024
…e` (#3804)

## Summary

I haven't tested on Windows yet, but the idea here is that we should use
a portable representation when printing paths.

I decided to limit the scope here to paths that we write to output
files.

Closes #3800.
@inoa-jboliveira
Copy link
Author

I just tried release v0.2.3 and it works perfectly. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants