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

refactor!(install): use builder pattern #299

Merged
merged 7 commits into from
Jan 4, 2025

Conversation

mrcjkb
Copy link
Member

@mrcjkb mrcjkb commented Jan 1, 2025

Stacked on #298

@mrcjkb mrcjkb force-pushed the mj/push-kytzywksurzs branch from 38c940d to 8452798 Compare January 2, 2025 23:41
Self {
config,
package_db: None,
packages: Vec::new(),
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: i think the builder pattern doesn't quite fit in install's case since one can install an empty set of packages by simply running Install::new().install() (which makes little sense). Can we enforce at the type level that at least one package should be provided (without having to do runtime checks in install())?

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 is also possible without the builder pattern, by passing in an empty vec.
We could change the new constructor to take a NonEmpty<PackageReq>.

I'd be in favour of that, but that would be for a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Come to think of it, sometimes we want it to be possible for the list to be empty, for example when installing test dependencies.

package_db: Option<RemotePackageDB>,
packages: Vec<(BuildBehaviour, PackageReq)>,
pin: PinnedState,
progress: Option<Arc<Progress<MultiProgress>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I just realized this exists in the other PRs (including the earlier PR that was merged) as well: we don't need to wrap this in an option, since the whole purpose of Progress<T> was to allow us to pass NoProgress :p

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason this is wrapped in an Option is so that we can fall back to default behaviour if the caller doesn't pass in one.
(right now, the default behaviour is to create a new MultiProgress).

@mrcjkb mrcjkb requested a review from teto as a code owner January 4, 2025 18:11
@mrcjkb mrcjkb merged commit 671cb26 into mj/push-vnqrqmtzrxry Jan 4, 2025
13 checks passed
@mrcjkb mrcjkb deleted the mj/push-kytzywksurzs branch January 4, 2025 18:11
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 this pull request may close these issues.

2 participants