Skip to content

Commit

Permalink
Remove choose_package_with_fewest_versions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 authored Jan 30, 2025
1 parent 9ebd2d1 commit 1be2365
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 10 additions & 8 deletions src/limitations/multiple_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ index.add_deps("a", (2, 0, 0), &[("b", (1, 0, 0)..)]);
### Implementing a dependency provider for the index

Since our `Index` is ready, we now have to implement the `DependencyProvider`
trait for it. As explained previously, we'll need to differenciate packages
trait for it. As explained previously, we'll need to differentiate packages
representing buckets and proxies, so we define the following new `Package` type.

```rust
Expand All @@ -180,13 +180,15 @@ pub struct Bucket {
}
```

In order to implement the first required method, `choose_package_version`, we
simply reuse the `choose_package_with_fewest_versions` helper function provided
by pubgrub. That one requires a list of available versions for each package, so
we have to create that list. As explained previously, listing the existing
(virtual) versions depend on if the package is a bucket or a proxy. For a bucket
package, we simply need to retrieve the original versions and filter out those
outside of the bucket.
Any `prioritize` will work equally well for this example, even just returning a
constant value.

Let's implement the second function required by a dependency provider,
`choose_version`. For that we defined a `available_versions()` method on an
`Index` to list existing versions of a given package in descending order. As
explained previously, listing the existing (virtual) versions depend on if the
package is a bucket or a proxy. For a bucket package, we simply need to retrieve
the original versions and filter out those outside of the bucket.

```rust
match package {
Expand Down
3 changes: 2 additions & 1 deletion src/limitations/optional_deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ pub enum Package {
}
```

We'll ignore `prioritize` for this example.
Any `prioritize` will work equally well for this example, even just returning a
constant value.

Let's implement the second function required by a dependency provider,
`choose_version`. For that we defined the `base_pkg()` method on a `Package`
Expand Down
10 changes: 6 additions & 4 deletions src/limitations/public_private.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ pub struct Seed {
}
```

Implementing `choose_package_version` is trivial if we simply use the function
`choose_package_with_fewest_versions` provided by pubgrub. Implementing
`get_dependencies` is slightly more complicated. Have a look at the complete
implementation if needed, the main ideas are the following.
Any `prioritize` will work equally well for this example, even just returning a
constant value. Implementing `choose_version` is straightforward enough not to
get additional commentary.

Implementing `get_dependencies` is slightly more complicated. Have a look at the
complete implementation if needed, the main ideas are the following.

```rust
fn get_dependencies(&self, package: &Package, version: &SemVer)
Expand Down

0 comments on commit 1be2365

Please sign in to comment.