pubgrub-rs / pubgrub

PubGrub version solving algorithm implemented in Rust
https://pubgrub-rs.github.io/pubgrub/pubgrub/
Mozilla Public License 2.0
337 stars 30 forks source link

Root package version should be optional #150

Open zanieb opened 7 months ago

zanieb commented 7 months ago

Example at https://github.com/zanieb/pubgrub/blob/zanie/examples/examples/unsat_root_messages.rs

In practice, the root package often does not have a real or known version number. To get around this, we just use a dummy minimum version for the root package but then the version appears in messaging e.g.

Because there is no version of foo in 1.0.0 and root 0.0.0 depends on foo 1.0.0, root 0.0.0 is forbidden.

To resolve this, a PubGrub user must:

Ideally the root package version would be optional entirely or it would be an option to omit it from the report.

Eh2406 commented 7 months ago

Thank you for trying PubGrub! I appreciate the production feedback.

I am just giving first reactions here. I may disagree with the opinion stated upon further reflection or the arrival of evidence.

Reading over your statement again and my response, I may be responding to "my repackage doesn't have a name" not "my repackage doesn't have a version". If I have misunderstood and the two topics are not deeply intertwined, my responses may be entirely irrelevant.

zanieb commented 7 months ago

Thanks for the response!

enum<P> {Root, Else(P)} is not a problem itself. We actually need to do Root(Option<String>) to allow it to have a name in some cases but that's fine.

The greater problem is that the version of root is meaningless and propagated through the reporting system. Here's an example of the code I wrote to strip versions from the display of the root package

https://github.com/zanieb/pubgrub/blob/zanie/examples/examples/unsat_root_message_no_version.rs

mpizenberg commented 7 months ago

The error reporting is probably the part of this lib that received the less love. It's not much optimized, performance-wise and there could be much better ways saying what the errors are while reading the derivation tree. It really is a minimal viable error reporting. The structure used for error reporting is a derivation tree, roughly presented here: https://pubgrub-rs-guide.netlify.app/pubgrub_crate/custom_report. We haven't tried implementing easy way to extend the default reporter as frankly, it was a minimum effort reporter and I didn't expect to live until now.

Regarding the "root" name, I agree it's very weird to have it presented like that in the reports. In your example :

Because there is no version of foo in 1.0.0 and root 0.0.0 depends on foo 1.0.0, root 0.0.0 is forbidden.

it would make much more sense if the report said instead something like this:

Because you depend on foo @ 1.0.0 and there is no such version, there is no solution

I don't know how much of a better minimal version reporter we could make by "just" updating it a bit. Or if it needs a full rewrite ...

Regarding the version associated with root package. It's because the solver can be used to solve both projects and package roots. And for a package root it's nice to have it's version displayed too. We didn't make a distinction in the reporter.

zanieb commented 7 months ago

Thanks for the additional context.

Because you depend on foo @ 1.0.0 and there is no such version, there is no solution

I agree this would be ideal. The existing error messages are unfortunately insufficient for our use-case and thus it is my highest priority to determine if we can reach a more user-friendly state.

It sounds like I should attempt to write a new reporter that is specifically for "projects".

Eh2406 commented 7 months ago

The greater problem is that the version of root is meaningless and propagated through the reporting system. Here's an example of the code I wrote to strip versions from the display of the root package

While looking over the changes you had to make I got to wondering. Should you have an enum for version? Where the display of the Version::Root is the empty string?

I completely agree that we should provide a more flexible reporter, but in the meantime I wonder if that would help.

zanieb commented 7 months ago

Should you have an enum for version? Where the display of the Version::Root is the empty string?

Hm interesting I hadn't considered that. Then we'd end often up with an extra space since the formatting is "blah blah {package} {version} blah blah", right? It also seems slightly more complicated when dealing with version sets.