Open
Conversation
Member
Author
|
CI fails because we have to merge 4c471bf to drop Python 3.9 support. |
b98ea6a to
92df178
Compare
Running `init` more than once appended duplicate lines to the shell rc file and prompted the user to confirm, which required manually cleaning up old lines afterwards. This led to duplicates and made it tedious to update the shell instructions when we want to change them. Dedicated shell init files in `~/.aiida_project/` (`init.bash`, `init.zsh`) are now simply overwritten on re-run — no duplicates, no prompt. The `fish` shell already had a dedicated file approach, but was also appending instead of overwriting. The new `write_config` method on the `Shell` class overwrites the file and checks if it existed beforehand, which is used to inform the user whether this is the first init or a re-init. For bash and zsh, the `ensure_source_line` method adds a single `source` line to the rc file (`.bashrc`, `.zshrc`) inside a named block with a timestamp, making it machine-parseable for future tooling. Since the block is only added if not already present, and the init file is overwritten completely, the operation is idempotent and the confirmation prompt can be dropped. The shell config logic is consolidated onto the `Shell` model (`write_config`, `ensure_source_line`) and `ShellType` gains an `rc_file` property — keeping the knowledge of which shells need a source line in one place.
92df178 to
b89eef6
Compare
Rename `is_not_initialised()` to `is_initialised()`, which avoids double negation for checks that check if the config is initialised (`not is_not_initialised`). Move the error message out of `ProjectConfig.is_initialised()` and into command logic. This allows us to reuse the command in other contexts where we don't want to print an error.
Since `init` is now idempotent, updating is trivial — but the user has no way of knowing their config is outdated after an upgrade. Add a `version` to the `shell_fields.yaml` file, which is written to the dedicated shell source file as a `# version: N` header. The `is_outdated` property is added, which reads the version from the source file and is used in the callback of the CLI to check for an outdated shell config version. This check is skipped for the init command and in case if `aiida-project init` has not been run yet
Without tab completion, the user has to remember or look up project names when calling `cda`. Moreover, they would have to type them out completely (yuck!). Adding tab-completion is essential for any environment management tool. The completion logic reads the available projects from the `.aiida_projects/` directory at completion time, so it always reflects the current state without any Python process overhead. Each shell uses its native completion mechanism: bash uses `compgen`/`complete`, zsh uses `compadd`/`compdef`, and fish uses `complete -c cda -f`. Because zsh now needs shell-specific completion code, it can no longer share `init_lines` with bash via the YAML anchor and gets its own block. The completion logic ships as part of the same release that introduces versioning, so no version bump is needed. Co-Authored-By: Timo Reents <77727843+t-reents@users.noreply.github.com>
Co-Authored-By: Timo Reents <77727843+t-reents@users.noreply.github.com>
b89eef6 to
671fd94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #14
@t-reents originally I was planning to update your PR, but I noticed that you opened it from your fork's
mainbranch. I felt awkward about force pushing yourmain, so opened a new PR, hope that's ok! I added you as a co-author in the relevant commits.Besides adding tab-completion, I realised that we need some way to be able to update these shell scripts without the user having to remove and add them every time, that seemed really fragile and annoying. So in d648aaf makes sure we have a separate source file for each shell. But then how would users know to run init? They would need to know something changed. To track that, you need a version, hence 073cc15. 8353c59 was an improvement triggered while working on that.
So I went down a little rabbit hole. I hope it's not over-engineered. But frankly I think we're going to want to change these source files over time (also because I'm not an expert on shell scripting: the
cdachanges were partially vibe-coded for bash and zsh). I think this infrastructure will come in handy, and it doesn't add that much code to maintain.I also think we're writing too many files to
$HOME. So I would also move all our config files + environments into.aiida_project. But will think about / implement that after this PR is merged. Hopefully then we can limit the pain of these migrations to a single release.