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

ENH,REQ: dnf install --json #1799

Open
westurner opened this issue Oct 25, 2024 · 4 comments
Open

ENH,REQ: dnf install --json #1799

westurner opened this issue Oct 25, 2024 · 4 comments
Labels
Priority: LOW RFE Request For Enhancement (as opposed to a bug) Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take

Comments

@westurner
Copy link

westurner commented Oct 25, 2024

ENH,REQ,STORY: Users can show the (space-indented (by default) or JSON) recursive list of packages that will be installed with a CLI option to dnf install like --pkgtrees or --deplist and also --json

# TC1: In order to install vim-enhanced in a ~devcontainer,
#      install all of these packages *without installing X (libX*)* and tracker-miners, etc:

# setUp() {
#   # echo "FROM fedora-toolbox:41" >> Dockerfile
#
#   dnf install -y toolbox
#   toolbox create -i fedora-toolbox:41 -n dnftest && toolbox enter dnftest
# 
#   dnf install -y distrobox
#   distrobox create -i fedora-toolbox:41 -n dnftest && distrobox enter dnftest 
# }

pkgs="vim-enhanced powerline-fonts fzf python3-virtualenv ruff black python3-pyflakes python3-flake8 python3-lsp-server python3-jupyter-lsp"
sudo dnf install $pkgs
# ...
# Transaction Summary:
# Installing:      343 packages
# Upgrading:         2 packages
# Replacing:         2 packages


## To determine which pkgspec passed to dnf install is resulting in X being installed:
for pkg in $pkgs; do (set -x; dnf install --assumeno "${pkg}"); done
#  Downsides:
#  - $pkgs is not correctly quoted; it probably should be `IFS=" " read args; for arg in "${args[@]}"`
#  - This simulates installing each package independently, not all at once
#  - This has to open and close the database for each command invocation


dnf repoquery --help | grep queryformat


## To *approximate* dnf install with repoquery --qf="depends, requires, suggests, supplements"
for pkg in $pkgs; do (set -x; dnf repoquery --queryformat='## Depends\n%{depends}## Requires\n%{requires}## Suggests\n%{suggests}## Supplements\n%{supplements}\n' "${pkg}"); done
#  Downsides:
#  - this isn't JSON, you must parse the pkgspecs, are they?
#  - this doesn't optionally list the 'suggests' and 'supplements' only if those flags were passed


# Ideally, there would be simple cli opt like --tree or --deplist
# that shows the (space-indented or json) recursive list of packages that will be installed;
# something like:

dnf install --show-recursive-dependency-list-first [ --json [-o <dnf.log.json>]] 

dfn install --deplist --json [-o <dnf.log.json>]] 

dnf install --deplist
dnf install --json     # could imply --deplist  # or whatever the opt should be called
@westurner
Copy link
Author

westurner commented Oct 25, 2024

Here's how to read the trasaction json files with the dnf history command in dnf4:

@m-blaha
Copy link
Member

m-blaha commented Oct 31, 2024

Do I understand correctly that the new switch is intended to print the transaction table in a machine-readable format? One challenge with the install command is that it’s somewhat interactive, requiring user confirmation for the transaction that will be executed. This proposal could work if paired with the --assumeno option, but it may feel awkward if the user has to confirm a transaction presented in JSON format.

Also, keep in mind that a transaction initiated by package installation might include not only dependency installations but also upgrades or downgrades of dependent packages, and potentially even removal of conflicting packages (if the --allowerasing option is used).

You can also create your own simple script tailored for your use-case using dnf5 API. For example:

#!/usr/bin/python3

import libdnf5

# Initialize 
base = libdnf5.base.Base()
base.load_config()
base.setup()

repo_sack = base.get_repo_sack()
repo_sack.create_repos_from_system_configuration()
repo_sack.load_repos()

# Create a goal, which is a class that allows to add items for resolving into
# a transaction.
goal = libdnf5.base.Goal(base)

# Add package specs for installation into the goal.
for pkgspec in ["vim-enhanced", "powerline-fonts", "fzf", "python3-virtualenv", "ruff"]:
    goal.add_rpm_install(pkgspec)

# Resolve the goal, create a transaction object.
transaction = goal.resolve()

# Now you can iterate the resolved transaction and print it in desired format
print("Resolved transaction:")
for tspkg in transaction.get_transaction_packages():
    print(tspkg.get_package().get_nevra(), ": ",
          libdnf5.base.transaction.transaction_item_action_to_string(tspkg.get_action()))

@m-blaha m-blaha added RFE Request For Enhancement (as opposed to a bug) Priority: LOW Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take labels Oct 31, 2024
@westurner
Copy link
Author

westurner commented Nov 1, 2024 via email

@jan-kolarik
Copy link
Member

Related: #867.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: LOW RFE Request For Enhancement (as opposed to a bug) Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
None yet
Development

No branches or pull requests

3 participants