Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[feature request] opam dichotomic search for upper/lower bound of a given dependency of a given package #5323

Open
UnixJunkie opened this issue Oct 20, 2022 · 3 comments

Comments

@UnixJunkie
Copy link
Contributor

Hello,

Cc @mseri I think there is definitively a feature that would save some time to users:

  • the ability to search automatically for the lower (or upper) bound version constraint of a given dependency of a given package.

I.e. in my current opam switch (i.e. for some fixed OCaml version), I might want to know the version constraints of one (or maybe all) of the dependencies of a given package (which might be pinned to its development version).

I think being able to search automatically for the lower bound might be useful for opam package maintainers.
Maybe, for several dependencies of one package, the search can be done in parallel.

Regards,
F.

@dra27
Copy link
Member

dra27 commented Oct 24, 2022

It's possibly doable with some existing commands, e.g. opam list dependency --coinstallable-with package.version --all-versions will give the list all versions of dependency of package.version which can be installed and the bounds could be extracted from that (and then repeat over the existing dependencies).

It's not (yet) totally clear what the feature looks like - is there some more context we could see?

@kit-ty-kate
Copy link
Member

kit-ty-kate commented Oct 24, 2022

Is what you want something like that?

#!/bin/bash

set -e

result=()

add() {
  local i=0
  local isset=false

  for line in "${result[@]}" ; do
    local name=$(echo "$line" | cut '-d ' -f1)

    if test "$name" = "$1" ; then
      result[$i]="$line $2"
      isset=true
    fi

    i=$(($i + 1))
  done

  if test "$isset" = "false" ; then
    result+=("$1 $2")
  fi
}

deps=$(opam list --required-by "$1" --all-versions -s)

last=
lastv=
for pkg in $deps ; do
  name=$(echo "$pkg" | cut -d. -f1)
  version=$(echo "$pkg" | cut -d. -f2-)

  if test "$name" != "$last" ; then
    if test "$last" != "" ; then
      add "$last" "$lastv"
    fi

    add "$name" "$version"
  fi

  last=$name
  lastv=$version
done

if test "$last" != "" ; then
  add "$last" "$lastv"
fi

for line in "${result[@]}" ; do
  name=$(echo "$line" | cut '-d ' -f1)
  lower=$(echo "$line" | cut '-d ' -f2)
  upper=$(echo "$line" | cut '-d ' -f3)

  if test "$lower" = "$upper" ; then
    constraint="{= \"$lower\"}"
  else
    constraint="{>= \"$lower\" & <= \"$upper\"}"
  fi

  echo "\"$name\" $constraint"
done

(to call with ./script.sh <your package>)

@UnixJunkie
Copy link
Contributor Author

UnixJunkie commented Oct 25, 2022

@dra27 the context is just you want to add a new version (or a new opam package) in opam-repository.
To do so nowadays, you need to specify at least a lower-bound version for all (or at least several) of those dependencies.
@kate I will give it a try. Maybe such script should be hosted somewhere under version control.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants