Skip to content

Show overrides in kup list <PKG> --inputs#148

Open
dkcumming wants to merge 1 commit intomasterfrom
dc/list-overrides
Open

Show overrides in kup list <PKG> --inputs#148
dkcumming wants to merge 1 commit intomasterfrom
dc/list-overrides

Conversation

@dkcumming
Copy link
Copy Markdown

@dkcumming dkcumming commented Mar 29, 2026

This PR includes a note when a dependency is overridden in the input graph printed with kup list <PKG> --inputs

Without override

zncv@zncv-Prime-16-NP60SND kup$ kup list k --inputs
Inputs:
├── haskell-backend - github:runtimeverification/haskell-backend (bf7eaa5)
│   └── rv-nix-tools - follows rv-nix-tools
├── llvm-backend - github:runtimeverification/llvm-backend (618f530)
│   ├── immer-src - github:runtimeverification/immer (4b0914f)
│   └── rv-nix-tools - github:runtimeverification/rv-nix-tools (854d4f0)
└── rv-nix-tools - github:runtimeverification/rv-nix-tools (854d4f0)

With override

zncv@zncv-Prime-16-NP60SND kup$ kup list k --inputs
Inputs:
├── haskell-backend - github:runtimeverification/haskell-backend (bf7eaa5) (override:
│   ../haskell-backend)
│   └── rv-nix-tools - follows rv-nix-tools
├── llvm-backend - github:runtimeverification/llvm-backend (618f530)
│   ├── immer-src - github:runtimeverification/immer (4b0914f)
│   └── rv-nix-tools - github:runtimeverification/rv-nix-tools (854d4f0)
└── rv-nix-tools - github:runtimeverification/rv-nix-tools (854d4f0)
zncv@zncv-Prime-16-NP60SND kup$ tmux capture-pane -p -S -75 | xclip -selection clipboard

@dkcumming
Copy link
Copy Markdown
Author

@juliankuners @tothtamas28 Full disclosure, claude did write this. I have read over it and feel it makes sense but of course, easy to make a mistake

@anvacaru
Copy link
Copy Markdown
Contributor

I think that the snippets are inverted in the PR description

Comment on lines +117 to +122
OVERRIDES_FILE = os.path.join(BaseDirectory.save_config_path('kup'), 'overrides.json')


def load_overrides() -> dict[str, list[list[str]]]:
"""Load persisted override info for all packages."""
if os.path.exists(OVERRIDES_FILE):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pathlib instead. Also, pathlib allows directly reading and writing the file contents without with open().

installed_packages: list[str] = []
pinned_package_cache: dict[str, str] = {}

OVERRIDES_FILE = os.path.join(BaseDirectory.save_config_path('kup'), 'overrides.json')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the second place where BaseDirectory.save_config_path('kup') is being used. Please make this an outer scope final variable that ensures that save_config_path is always called with the same directory name.

"""Load persisted override info for all packages."""
if os.path.exists(OVERRIDES_FILE):
with open(OVERRIDES_FILE) as f:
return json.loads(f.read())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use dataclasses or pydantic instead of json->dict parsing. Having dict[str, list[list[str]]] as a type, e.g., is non-verbose.

inputs = get_package_metadata(listed_package)
rich.print(package_metadata_tree(inputs, show_status=show_status))
pkg_overrides = load_overrides().get(package_name, [])
override_map = {ov[0]: ov[1] for ov in pkg_overrides} if pkg_overrides else {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a json struct instead of a json list for theses two values.

Comment on lines +649 to +651
all_overrides = load_overrides()
if all_overrides.pop(package_name, None) is not None:
save_overrides(all_overrides)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packages can also be uninstalled from outside kup using nix. Therefore, this state can go out of sync. Instead, check whether a nix derivation hash matches the respective hash in the override state. This also needs to be added to the state.

# Persist override info so `kup list --inputs` can display it
all_overrides = load_overrides()
if package_overrides:
all_overrides[package_name.base] = package_overrides
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This saves the relative override path used during install in the override state, e.g., ../haskell-backend. However, the relative address requires a starting point to be useful.

Copy link
Copy Markdown
Contributor

@juliankuners juliankuners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants