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

feat: improve sync reporting #2202

Open
wants to merge 13 commits into
base: feature/pixi-global
Choose a base branch
from

Conversation

Hofer-Julian
Copy link
Contributor

@Hofer-Julian Hofer-Julian commented Oct 4, 2024

This moves from functions printing to stderr to functions returning StateChange or StateChanges.

The reporting is then done higher up.

@Hofer-Julian Hofer-Julian marked this pull request as ready for review October 7, 2024 13:30
Comment on lines +260 to +264
#[derive(Debug, Default)]
pub(crate) struct StateChanges {
changes: Vec<StateChange>,
has_updated: bool,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the interesting bit. By returning this struct we can pick and choose what to report. For example, we never want to report changes done by reverting.

Comment on lines 214 to 215
impl fmt::Display for StateChange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sure the reporting is unified across commands

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nice if we could make a formatter that expects an env_name and then formats the change a bit more informative. e.g. this is the output of installing python:

❯ pixi g i python
✔ Added environment 'python'.
✔ Added package 'python' and installed it with version: '3.12.7' in environment: 'python' .
✔ Exposed '2to3' binary from environment 'python'.
✔ Exposed '2to3-3.12' binary from environment 'python'.
✔ Exposed 'idle3' binary from environment 'python'.
✔ Exposed 'idle3.12' binary from environment 'python'.
✔ Exposed 'pydoc' binary from environment 'python'.
✔ Exposed 'pydoc3' binary from environment 'python'.
✔ Exposed 'pydoc3.12' binary from environment 'python'.
✔ Exposed 'python' binary from environment 'python'.
✔ Exposed 'python3' binary from environment 'python'.
✔ Exposed 'python3-config' binary from environment 'python'.
✔ Exposed 'python3.1' binary from environment 'python'.
✔ Exposed 'python3.12' binary from environment 'python'.
✔ Exposed 'python3.12-config' binary from environment 'python'.

Copy link
Contributor

Choose a reason for hiding this comment

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

ChatGPT came with this idea:

✔ Added environment 'python' with package 'python' (version: 3.12.7).

✔ Exposed binaries from environment 'python':
   - 2to3, 2to3-3.12
   - idle3, idle3.12
   - pydoc, pydoc3, pydoc3.12
   - python, python3, python3.12
   - python3-config, python3.12-config

Comment on lines 289 to 306
fn prune(&mut self) {
// Remove changes if the environment is removed afterwards
let mut pruned_changes: Vec<StateChange> = Vec::new();
for change in &self.changes {
match change {
StateChange::RemovedEnvironment(env) => {
pruned_changes.retain(|change| match change {
StateChange::RemovedEnvironment(_) => true,
c => c.env() != env,
});
}
_ => {
pruned_changes.push(change.clone());
}
}
}
self.changes = pruned_changes;
}
Copy link
Contributor Author

@Hofer-Julian Hofer-Julian Oct 7, 2024

Choose a reason for hiding this comment

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

At the moment, prune only makes sure that we don't report changes on an environment we later remove. This can be extended in the future.

For example, when implementing pixi global remove we could make sure that RemovedPackage and AddedPackage cancel each other out.

@baszalmstra baszalmstra added the area:global Related to pixi global label Oct 7, 2024
@ruben-arts ruben-arts added this to the New `pixi global` milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:global Related to pixi global
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants