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

Use full requirement when serializing receipt #5494

Merged
merged 1 commit into from
Jul 31, 2024
Merged

Conversation

charliermarsh
Copy link
Member

Summary

The current receipt doesn't capture quite enough information. For example, it doesn't differentiate between editable and non-editable requirements. This PR instead uses the full Requirement type. I think we should use a custom representation like we do in the lockfile, but I'm just using the default representation to demonstrate the idea.

@charliermarsh charliermarsh added the preview Experimental behavior label Jul 26, 2024
@@ -396,9 +396,7 @@ fn tool_install_editable() {
----- stderr -----
"###);

// Request `black`. It should retain the current installation.
// TODO(charlie): This is arguably incorrect, especially because the tool receipt removes the
// file path.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the motivating example.

@@ -380,7 +380,7 @@ fn tool_install_editable() {
// We should have a tool receipt
assert_snapshot!(fs_err::read_to_string(tool_dir.join("black").join("uv-receipt.toml")).unwrap(), @r###"
[tool]
requirements = ["black @ file://[WORKSPACE]/scripts/packages/black_editable"]
requirements = [{ name = "black", directory = { install_path = "[WORKSPACE]/scripts/packages/black_editable", lock_path = "[WORKSPACE]/scripts/packages/black_editable", editable = true, url = { url = "file://[WORKSPACE]/scripts/packages/black_editable" } } }]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're comfortable with the general idea here, I will iron out the actual requirement schema.

@charliermarsh
Copy link
Member Author

Please just focus on the concept here (example) and ignore the code and exact representation for now.

@zanieb
Copy link
Member

zanieb commented Jul 30, 2024

I think this makes sense to me. My only concern is that I want users to be able to declare tools declaratively eventually. I don't think that's in conflict though — I think the receipt can be considered "machine read / write" and "human inspectable" like the lock file. We can iron out a separate schema for users to declaratively request tools later.

@BurntSushi
Copy link
Member

I'm not terribly familiar with tool receipts yet. Can you say more at a high level about what problem this is trying to solve?

(Insomuch as I understand what this PR is doing, I think it LGTM.)

@charliermarsh
Copy link
Member Author

charliermarsh commented Jul 30, 2024

Copying my response from Discord:

Yes sorry
When a user installs a tool (like cargo install), we save a receipt alongside it enumerating the input requirements
When they run uv tool upgrade, we respect those input requirements
...
It was using PEP 508 so...
If a user did tool install -e ./black, we didn't capture that it was installed as editable, for example
Since that can't be expressed in PEP 508
But our requirement type is richer

@charliermarsh
Copy link
Member Author

Ok happy with how this turned out.

@charliermarsh
Copy link
Member Author

Ready for review @zanieb @BurntSushi at your convenience.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're using a Git URL here, perhaps we should in the lock file too? Then I could just close #4631.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems ok to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me re-review that quickly, I think I lost it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm fine with either!

charliermarsh added a commit that referenced this pull request Jul 31, 2024
## Summary

I need to reuse this in #5494, so want to abstract it out and make it
reusable.
Base automatically changed from charlie/portable to main July 31, 2024 16:00
@charliermarsh charliermarsh enabled auto-merge (squash) July 31, 2024 16:07
@charliermarsh charliermarsh merged commit f266fb7 into main Jul 31, 2024
57 checks passed
@charliermarsh charliermarsh deleted the charlie/req-toml branch July 31, 2024 16:16
charliermarsh added a commit that referenced this pull request Jul 31, 2024
## Summary

Fixes a bug in #5494. The `RequirementSourceWire` representation was
ambiguous, and so the order of the fields meant that all variants were
mapped to `Registry` when deserializing. (So the snapshots were right,
but behaviors were wrong.)
charliermarsh added a commit that referenced this pull request Aug 1, 2024
## Summary

In #5494, I made breaking changes to the tool receipt format. This would
break existing tools for all users. This PR makes the change
backwards-compatible by supporting deserialization for the deprecated
format.

Closes #5680.

## Test Plan

Beyond the automated tests, you can run `cargo run tool list` on your
existing machine.

Before:

```
warning: `uv tool list` is experimental and may change without warning
warning: Ignoring malformed tool `black` (run `uv tool uninstall black` to remove)
warning: Ignoring malformed tool `poetry` (run `uv tool uninstall poetry` to remove)
warning: Ignoring malformed tool `ruff` (run `uv tool uninstall ruff` to remove)
```

After:

```
warning: `uv tool list` is experimental and may change without warning
black v0.1.0
- black
poetry v1.8.3
- poetry
ruff v0.0.60
- ruff
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants