conda-incubator / conda-tree

conda dependency tree helper
MIT License
152 stars 12 forks source link

Add ability to find and/or output constraints, as well as dependencies #26

Open DManowitz opened 1 month ago

DManowitz commented 1 month ago

This package is excellent for showing dependencies between packages. However, sometimes packages put constraints on other packages that can be installed together. It would be nice to be able to see these constraints in the tree output and possibly some other commands like constrains and who-constrains.

rvalieris commented 1 month ago

Hello, can you give an example of package constrains you want to visualize ?

I think that this is already possible, at least in part, with these commands:

$ conda tree whoneeds -t yaml
yaml==0.2.5
  └─ pyyaml 6.0.1 [required: >=0.2.5,<0.3.0a0]
     └─ jupyter_events 0.10.0 [required: >=5.3]
        └─ jupyter_server 2.14.0 [required: >=0.9.0]
           ├─ jupyter-lsp 2.2.5 [required: >=1.1.2]
           │  └─ jupyterlab 4.2.0 [required: >=2.0.0]
           ├─ nbclassic 1.0.0 [required: >=1.8]
           │  └─ notebook 6.5.4 [required: >=0.4.7]
           │     └─ nb_conda_kernels 2.5.1 [required: any]
           ├─ jupyterlab_server 2.27.1 [required: >=1.21,<3]
           │  └─ jupyterlab 4.2.0 [required: >=2.19.0,<3]
           ├─ jupyterlab 4.2.0 [required: >=2.4.0,<3]
           └─ notebook-shim 0.2.4 [required: >=1.8,<3]
              ├─ nbclassic 1.0.0 [required: >=0.2.3]
              │  └─ dependent packages of nbclassic displayed above
              └─ jupyterlab 4.2.0 [required: >=0.2]

$ conda tree depends -t yaml
yaml==0.2.5
  └─ libgcc-ng 13.2.0 [required: >=9.4.0]
     ├─ _openmp_mutex 4.5 [required: >=4.5]
     │  ├─ _libgcc_mutex 0.1 [required: 0.1, conda_forge]
     │  └─ libgomp 13.2.0 [required: >=7.5.0]
     │     └─ _libgcc_mutex 0.1 [required: 0.1, conda_forge]
     └─ _libgcc_mutex 0.1 [required: 0.1, conda_forge]

the command whoneeds -t <pkg> displays packages that depend on <pkg>, and inside square brackets the version constraints of each package. and the command depends -t <pkg>displays the dependencies of <pkg>, with their version constraints.

It is important to note that these only display the constraints of the currently installed packages. so in this example pyyaml requires yaml to be between 0.2.5 and under 0.3.0, however it is possible that there are other versions of pyyaml we could install that support yaml >0.3.0 or yaml < 0.2.5.

DManowitz commented 1 month ago

When you look at a package using conda search -i, you get output like this:

cupy 10.5.0 py37h72a7169_0
--------------------------
file name   : cupy-10.5.0-py37h72a7169_0.tar.bz2
name        : cupy
version     : 10.5.0
build       : py37h72a7169_0
build number: 0
size        : 51.3 MB
license     : MIT
subdir      : win-64
url         : https://conda.anaconda.org/conda-forge/win-64/cupy-10.5.0-py37h72a7169_0.tar.bz2
md5         : 3525aebb821f1415f5eebe1ebce213db
timestamp   : 2022-06-01 06:17:08 UTC
constraints :
  - cutensor >=1.3,<2.0a0
  - cudnn >=8.2.1.32,<9.0a0
  - scipy >=1.4
  - optuna >=2
  - cusparselt >=0.2.0.1,<0.3.0a0
dependencies:
  - cudatoolkit >=11.2,<12
  - fastrlock >=0.8,<0.9.0a0
  - numpy >=1.18
  - python >=3.7,<3.8.0a0
  - python_abi 3.7.* *_cp37m
  - vc >=14.1,<15
  - vs2015_runtime >=14.16.27033

From what I can see, conda-tree only deals with packages listed in the dependencies section above (i.e., those other packages which are required for the package of interest to work). However, I'm talking about those packages listed under the constraints section above. These packages are not required for the package of interest to work, but, if present, they must satisfy the specified constraints.

rvalieris commented 1 month ago

ah, I see. indeed these constraints aren't visible on conda tree, that is something we could add in the future. I think it makes sense to have a separate command for this but I will think about this more for a future update.