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: Dependency tree command #1069

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 121 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ List project's packages. Highlighted packages are explicit dependencies.
- `--locked`: Only install if the `pixi.lock` is up-to-date with the [manifest file](configuration.md)[^1]. It can also be controlled by the `PIXI_LOCKED` environment variable (example: `PIXI_LOCKED=true`). Conflicts with `--frozen`.
- `--no-install`: Don't install the environment for pypi solving, only update the lock-file if it can solve without installing. (Implied by `--frozen` and `--locked`)

```shell

```shell
pixi list
pixi list --json-pretty
Expand Down Expand Up @@ -368,6 +366,127 @@ Output will look like this, where `python` will be green as it is the package th
xz 5.2.6 h166bdaf_0 408.6 KiB conda xz-5.2.6-h166bdaf_0.tar.bz2
```

## `tree`

Display the project's packages in a tree. Highlighted packages are those specified in the manifest.

The package tree can also be inverted (`-i`), to see which packages require a specific dependencies.

##### Arguments

- `REGEX` optional regex of which direct dependencies to filter the tree to, or which dependencies to start with when inverting the tree.

##### Options

- `--invert (-i)`: Invert the dependency tree, that is given a `REGEX` pattern that matches some packages, show all the packages that depend on those.
- `--platform <PLATFORM> (-p)`: The platform to list packages for. Defaults to the current platform
- `--manifest-path <MANIFEST_PATH>`: The path to [manifest file](configuration.md), by default it searches for one in the parent directories.
- `--environment`(`-e`): The environment's packages to list, if non is provided the default environment's packages will be listed.
abkfenris marked this conversation as resolved.
Show resolved Hide resolved
- `--frozen`: Install the environment as defined in the lockfile. Without checking the status of the lockfile. It can also be controlled by the `PIXI_FROZEN` environment variable (example: `PIXI_FROZEN=true`).
- `--locked`: Only install if the `pixi.lock` is up-to-date with the [manifest file](configuration.md)[^1]. It can also be controlled by the `PIXI_LOCKED` environment variable (example: `PIXI_LOCKED=true`). Conflicts with `--frozen`.
- `--no-install`: Don't install the environment for pypi solving, only update the lock-file if it can solve without installing. (Implied by `--frozen` and `--locked`)

```shell
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
pixi tree
pixi tree pre-commit
pixi tree -i yaml
pixi tree --environment docs
```

!!! warning
Use `-v` to show which `pypi` packages are not yet parsed correctly. The `extras` and `markers` parsing is still under development.

Output will look like this, where direct packages in the [manifest file](configuration.md) will be green.
Once a package has been displayed once, the tree won't continue to recurse through it's dependencies (compare the first time `livzlib` appears, vs the rest), and it will instead be marked with a star `(*)`.
abkfenris marked this conversation as resolved.
Show resolved Hide resolved

Version numbers are colored by the package type, yellow for Conda packages and blue for PyPI.

```shell
➜ pixi tree
├── pre-commit v3.3.3
│ ├── cfgv v3.3.1
│ │ └── python v3.12.2
│ │ ├── libsqlite v3.45.2
│ │ │ └── libzlib v1.2.13
│ │ ├── libzlib v1.2.13 (*)
│ │ ├── libffi v3.4.2
│ │ ├── libexpat v2.6.2
│ │ ├── readline v8.2
│ │ │ └── ncurses v6.4.20240210
│ │ ├── xz v5.2.6
│ │ ├── openssl v3.2.1
│ │ ├── bzip2 v1.0.8
│ │ ├── tk v8.6.13
│ │ │ └── libzlib v1.2.13 (*)
│ │ └── ncurses v6.4.20240210 (*)
│ ├── pyyaml v6.0.1
...
├── rust v1.76.0
│ └── rust-std-aarch64-apple-darwin v1.76.0
├── openssl v3.2.1
├── pkg-config v0.29.2
│ ├── libglib v2.78.4
│ │ ├── libiconv v1.17
│ │ ├── gettext v0.21.1
│ │ │ └── libiconv v1.17 (*)
...
```

A regex pattern can be specified to filter the tree to just those that show a specific direct dependency:

```shell
➜ pixi tree pre-commit
└── pre-commit v3.3.3
├── virtualenv v20.25.1
│ ├── filelock v3.13.1
│ │ └── python v3.12.2
│ │ ├── libexpat v2.6.2
│ │ ├── readline v8.2
│ │ │ └── ncurses v6.4.20240210
│ │ ├── libsqlite v3.45.2
│ │ │ └── libzlib v1.2.13
│ │ ├── bzip2 v1.0.8
│ │ ├── libzlib v1.2.13 (*)
│ │ ├── libffi v3.4.2
│ │ ├── tk v8.6.13
│ │ │ └── libzlib v1.2.13 (*)
│ │ ├── xz v5.2.6
│ │ ├── ncurses v6.4.20240210 (*)
│ │ └── openssl v3.2.1
│ ├── platformdirs v4.2.0
│ │ └── python v3.12.2 (*)
│ ├── distlib v0.3.8
│ │ └── python v3.12.2 (*)
│ └── python v3.12.2 (*)
├── pyyaml v6.0.1
...
```

Additionly the tree can be inverted, and it can show which packages depend on a regex pattern.
The packages specified in the manifest will also be highlighted (in this case `cffconvert` and `pre-commit` would be).

```shell
➜ pixi tree -i yaml

ruamel.yaml v0.18.6
├── pykwalify v1.8.0
│ └── cffconvert v2.0.0
└── cffconvert v2.0.0

pyyaml v6.0.1
└── pre-commit v3.3.3

ruamel.yaml.clib v0.2.8
└── ruamel.yaml v0.18.6
├── pykwalify v1.8.0
│ └── cffconvert v2.0.0
└── cffconvert v2.0.0

yaml v0.2.5
└── pyyaml v6.0.1
└── pre-commit v3.3.3
```

## `shell`

This command starts a new shell in the project's environment.
Expand Down
3 changes: 3 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod self_update;
pub mod shell;
pub mod shell_hook;
pub mod task;
pub mod tree;
pub mod upload;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -75,6 +76,7 @@ pub enum Command {
Remove(remove::Args),
SelfUpdate(self_update::Args),
List(list::Args),
Tree(tree::Args),
}

#[derive(Parser, Debug, Default, Copy, Clone)]
Expand Down Expand Up @@ -230,6 +232,7 @@ pub async fn execute_command(command: Command) -> miette::Result<()> {
Command::Remove(cmd) => remove::execute(cmd).await,
Command::SelfUpdate(cmd) => self_update::execute(cmd).await,
Command::List(cmd) => list::execute(cmd).await,
Command::Tree(cmd) => tree::execute(cmd).await,
}
}

Expand Down
Loading
Loading