pkgx icon indicating copy to clipboard operation
pkgx copied to clipboard

`pkgx --provides`

Open felipecrs opened this issue 11 months ago • 27 comments

It would be great if pkgx allowed to query pkgs for their provides, for example:

$ pkgx --provides [email protected] --json=v1
{
  "provides": [
    {
      "project": "git-scm.org",
      "provides: ["bin/git"]
    }
  ]
}

Note it should not install [email protected], which happens without --provides. Also, the output should not contain the provides of the dependencies.

This would allow to drop the dependency on libpkgx in pkgm but would also allow me to write my own pkgm for shims using just bash.

What do you think?

felipecrs avatar Mar 12 '25 15:03 felipecrs

I want to make pkgq for this.

mxcl avatar Mar 12 '25 16:03 mxcl

Maybe that's overkill. 😅

It'd be a bummer having to download another binary just for this.

felipecrs avatar Mar 12 '25 16:03 felipecrs

Changed my mind, pkgx -q git would return an exit code, where pkgx -qv git would return git-scm.org or the path if installed and pkgx -qj git would return json.

mxcl avatar Mar 14 '25 16:03 mxcl

might suggest --query|-Q so it looks modal instead of operational. but it's a good idea.

jhheider avatar Mar 14 '25 16:03 jhheider

Yeah. -q is already --quiet.

felipecrs avatar Mar 14 '25 17:03 felipecrs

@mxcl, this allows for resolving a binary into a project name, which is great.

But it doesn't allow resolving a project name into binaries/provides, which still don't enable the use case I had in mind.

What do you think? Or maybe I'm missing something?

felipecrs avatar Mar 16 '25 15:03 felipecrs

Can you explain your usage? Your example was for pkgx -Q git not pkgx -Q git-scm.org

Edit: I see the need for “can you run this?” but deeper queries belong on the pkgq tool IMO. But interested in your usage needs in case I am missing something.

mxcl avatar Mar 16 '25 16:03 mxcl

My example was (adjusting --provides to --query):

$ pkgx --query [email protected] --json=v1
{
  "provides": [
    {
      "project": "git-scm.org",
      "provides: ["bin/git"]
    }
  ]
}

Where [email protected] would be whatever user has requested.

In this case, I was alluding the fact pkgx understands and resolves both [email protected] and [email protected].

I would then rely on pkgx --query to resolve whatever user requested into both the actual project name and a list of provides of such project.

felipecrs avatar Mar 16 '25 16:03 felipecrs

In order to understand better how to implement this I am wondering what are you trying to do with the data?

mxcl avatar Mar 16 '25 16:03 mxcl

Oh, I wrote it:

This would allow to drop the dependency on libpkgx in pkgm but would also allow me to write my own pkgm for shims using just bash.

felipecrs avatar Mar 16 '25 17:03 felipecrs

Thank you. But yeah. This would be pkgq IMO.

mxcl avatar Mar 16 '25 17:03 mxcl

Though I am ok with adding the --json response to what we have here with the full list of provides. But the input needs to be a program not a project. This aligns with the language of the pkgx cli format without adding a bunch of weird handling for “is this a program or something else, what does it mean if it's a project name or another alias” etc.

mxcl avatar Mar 16 '25 17:03 mxcl

Though I am ok with adding the --json response to what we have here with the full list of provides. But the input needs to be a program not a project. This aligns with the language of the pkgx cli format without adding a bunch of weird handling for “is this a program or something else, what does it mean if it's a project name or another alias” etc.

I was considering reusing whatever logic exists for when no command is provided:

$ pkgx +git

Where pkgx already resolves into environment variables.

felipecrs avatar Mar 16 '25 17:03 felipecrs

i could see some value:

$ pkgx -Q +git --json=v1 | pkgx jq .
{
  "PYTHONPATH": [
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/lib/python3.11/site-packages"
  ],
  "SSL_CERT_FILE": [
    "/Users/jacob/.pkgx/curl.se/ca-certs/v2024.7.2/ssl/cert.pem"
  ],
  "GIT_TEMPLATE_DIR": [
    "/Users/jacob/.pkgx/git-scm.org/v2.45.2/share/git-core/templates"
  ],
  "GIT_SSL_CAINFO": [
    "/Users/jacob/.pkgx/curl.se/ca-certs/v2024.7.2/ssl/cert.pem"
  ],
  "PATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/bin",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/bin",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/bin",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/bin",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/bin",
    "/Users/jacob/.pkgx/perl.org/v5.38.0/bin",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/bin",
    "/Users/jacob/.pkgx/git-scm.org/v2.45.2/bin"
  ],
  "CPATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/include",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/include",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/include",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/include",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/include",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/include",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/include"
  ],
  "LIBRARY_PATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/lib",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/lib",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/lib",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/lib",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/lib",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/lib",
    "/Users/jacob/.pkgx/perl.org/v5.38.0/lib",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/lib"
  ],
  "PKG_CONFIG_PATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/lib/pkgconfig",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/lib/pkgconfig",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/lib/pkgconfig",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/lib/pkgconfig",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/lib/pkgconfig",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/lib/pkgconfig"
  ],
  "XDG_DATA_DIRS": [
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/share",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/share",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/share",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/share",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/share",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/share",
    "/Users/jacob/.pkgx/git-scm.org/v2.45.2/share"
  ],
  "MANPATH": [
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/share/man",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/share/man",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/share/man",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/share/man",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/share/man",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/share/man:${MANPATH}",
    "/usr/share/man"
  ],
  "LD_LIBRARY_PATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/lib",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/lib",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/lib",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/lib",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/lib",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/lib",
    "/Users/jacob/.pkgx/perl.org/v5.38.0/lib",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/lib"
  ],
  "DYLD_FALLBACK_LIBRARY_PATH": [
    "/Users/jacob/.pkgx/openssl.org/v1.1.1w/lib",
    "/Users/jacob/.pkgx/gnome.org/libxml2/v2.13.3/lib",
    "/Users/jacob/.pkgx/tukaani.org/xz/v5.4.6/lib",
    "/Users/jacob/.pkgx/zlib.net/v1.3.1/lib",
    "/Users/jacob/.pkgx/gnu.org/gettext/v0.21.1/lib",
    "/Users/jacob/.pkgx/curl.se/v8.8.0/lib",
    "/Users/jacob/.pkgx/perl.org/v5.38.0/lib",
    "/Users/jacob/.pkgx/libexpat.github.io/v2.6.2/lib"
  ],
  "pkgs": {
    "git-scm.org": {
      "version": "2.45.2",
      "provides": [
        "bin/git",
        "bin/git-cvsserver",
        "bin/git-receive-pack",
        "bin/git-shell",
        "bin/git-upload-archive",
        "bin/git-upload-pack",
        "bin/scalar"
      ]
    },
    "openssl.org": {
      "version": "1.1.1w",
      "provides": [
        "bin/openssl",
        "bin/c_rehash"
      ]
    },
    "gnome.org/libxml2": {
      "version": "2.13.3",
      "provides": [
        "bin/xml2-config",
        "bin/xmlcatalog",
        "bin/xmllint"
      ]
    },
    "tukaani.org/xz": {
      "version": "5.4.6",
      "provides": [
        "bin/lzcat",
        "bin/lzcmp",
        "bin/lzdiff",
        "bin/lzegrep",
        "bin/lzfgrep",
        "bin/lzgrep",
        "bin/lzless",
        "bin/lzma",
        "bin/lzmadec",
        "bin/lzmainfo",
        "bin/lzmore",
        "bin/unlzma",
        "bin/unxz",
        "bin/xz",
        "bin/xzcat",
        "bin/xzcmp",
        "bin/xzdec",
        "bin/xzdiff",
        "bin/xzegrep",
        "bin/xzfgrep",
        "bin/xzgrep",
        "bin/xzless",
        "bin/xzmore"
      ]
    },
    "zlib.net": {
      "version": "1.3.1"
    },
    "gnu.org/gettext": {
      "version": "0.21.1",
      "provides": [
        "bin/autopoint",
        "bin/envsubst",
        "bin/gettext",
        "bin/gettext.sh",
        "bin/gettextize",
        "bin/msgattrib",
        "bin/msgcat",
        "bin/msgcmp",
        "bin/msgcomm",
        "bin/msgconv",
        "bin/msgen",
        "bin/msgexec",
        "bin/msgfilter",
        "bin/msgfmt",
        "bin/msggrep",
        "bin/msginit",
        "bin/msgmerge",
        "bin/msgunfmt",
        "bin/msguniq",
        "bin/ngettext",
        "bin/recode-sr-latin",
        "bin/xgettext"
      ]
    },
    "curl.se": {
      "version": "8.8.0",
      "provides": [
        "bin/curl",
        "bin/curl-config"
      ]
    },
    "perl.org": {
      "version": "5.38.0",
      "provides": [
        "bin/corelist",
        "bin/cpan",
        "bin/enc2xs",
        "bin/encguess",
        "bin/h2ph",
        "bin/h2xs",
        "bin/instmodsh",
        "bin/json_pp",
        "bin/libnetcfg",
        "bin/perl",
        "bin/perlbug",
        "bin/perldoc",
        "bin/perlivp",
        "bin/perlthanks",
        "bin/piconv",
        "bin/pl2pm",
        "bin/pod2html",
        "bin/pod2man",
        "bin/pod2text",
        "bin/pod2usage",
        "bin/podchecker",
        "bin/prove",
        "bin/ptar",
        "bin/ptardiff",
        "bin/ptargrep",
        "bin/shasum",
        "bin/splain",
        "bin/streamzip",
        "bin/xsubpp",
        "bin/zipdetails"
      ]
    },
    "libexpat.github.io": {
      "version": "2.6.2",
      "provides": [
        "bin/xmlwf"
      ]
    }
  }
}

now, none of that can't be done by inspecting the pantry, obviously, but providing an interface has value. though, as max mentions, an external tool would allow more flexible querying. think debian's original apt-get/apt-cache/etc tool group, versus the newer apt tool.

jhheider avatar Mar 16 '25 18:03 jhheider

Ah this makes sense. For clarity on my decision making process. I really care about intuitive, logical CLIs.

mxcl avatar Mar 19 '25 13:03 mxcl

@mxcl maybe you can reopen this issue then?

At the end of it, I hope this feature will allow pkgm to avoid depending on libpkgx/hooks.

felipecrs avatar Mar 21 '25 16:03 felipecrs

I'm going to release 2.5. I think what we have here is right—and whatever we add here—this will stay.

mxcl avatar Mar 24 '25 20:03 mxcl

@mxcl maybe you can rename the flag to --experimental-query, to give yourself a chance of iterating through it next versions.

felipecrs avatar Mar 24 '25 20:03 felipecrs

I realize with hindsight a “no net” flag in combination with pkgx +foo --json would have sufficed rather than adding a new mode. Sigh.

mxcl avatar Apr 02 '25 13:04 mxcl

"no net"? What do you mean by that?

felipecrs avatar Apr 02 '25 15:04 felipecrs

no networking

mxcl avatar Apr 02 '25 16:04 mxcl

lol. I don't understand what this has to do with this feature request. TBH I think we lost alignment on this feature request a while ago.

In case you still want to recover this "alignment", do you mind explaining a use case of what you are proposing? Or maybe even a use case of the existing --query flag?

felipecrs avatar Apr 02 '25 16:04 felipecrs

This feature doesn't do any networking, and thus as a result, it does not install anything. My proposal would thus prevent standard usage of pkgx doing the same and thus would provide what you want without a new feature flag.

Just thinking aloud, but I regret that now.

mxcl avatar Apr 02 '25 16:04 mxcl

Hm... but network would still be needed to update pantry and resolve things like ^3 or @latest (even if package is not going to be installed).

Unless you expect me to update pantry first, with pkgx --sync && pkgx --no-net --json +git@latest.

felipecrs avatar Apr 02 '25 17:04 felipecrs

Well, to be honest I would have expected pkgx --no-net --json +git@latest to fail if git is not already installed. That flag could be used to check whether some package is already installed or not.

felipecrs avatar Apr 02 '25 17:04 felipecrs

--query is not bad but doesn't return all the information I need. Maybe --resolve was more what I meant (like pkgx --resolve --json +git@latest).

But if you can enrich the output of --query --json to include the provides, that would also do the trick (while still retaining backwards compatibility).

felipecrs avatar Apr 02 '25 17:04 felipecrs

@mxcl can I try sending a PR for it?

felipecrs avatar May 19 '25 19:05 felipecrs