Skip to content

Fix ros2cli + rosidl_cli auto-completion - #206

Closed
rhaschke wants to merge 3 commits into
RoboStack:mainfrom
rhaschke:main
Closed

Fix ros2cli + rosidl_cli auto-completion#206
rhaschke wants to merge 3 commits into
RoboStack:mainfrom
rhaschke:main

Conversation

@rhaschke

Copy link
Copy Markdown

@rhaschke
rhaschke marked this pull request as draft April 18, 2026 09:02
@rhaschke

rhaschke commented Apr 18, 2026

Copy link
Copy Markdown
Author

The backport from ros-humble doesn't actually work for me 😞. pixi's configured shell-hook is simply wrong:

$ pixi shell-hook -e jazzy
...
source /vol/robostack/.pixi/envs/jazzy/share/bash-completion/completions/*
...

The source command just considers the first file argument. It cannot be used to source multiple files at once!

However, I don't understand, why sourcing $CONDA_PREFIX/setup.sh in /vol/robostack/.pixi/envs/jazzy/etc/conda/activate.d/ros-jazzy-ros-workspace_activate.sh doesn't activate completion in first place. Enabling tracing (export AMENT_TRACE_SETUP_FILES=1) reveals that the corresponding command is correctly created (and evaluated):

# Package: ros2cli
# /vol/robostack/.pixi/envs/jazzy/share/ros2cli/package.dsv
AMENT_CURRENT_PREFIX="/vol/robostack/.pixi/envs/jazzy" _ament_prefix_sh_source_script "/vol/robostack/.pixi/envs/jazzy/share/ros2cli/environment/ros2-argcomplete.bash"

Is it possible that pixi's activation mechanism has changed and executes the activation scripts within a subshell? I'm using pixi 0.67.0.

@Tobias-Fischer

Copy link
Copy Markdown
Contributor

Cc @wolfv @ruben-arts

@rhaschke

rhaschke commented Apr 18, 2026

Copy link
Copy Markdown
Author

Manually sourcing .pixi/envs/jazzy/etc/conda/activate.d/ros-jazzy-ros-workspace_activate.sh enables completion as expected. So, this indeed seems to be a pixi issue.
eval "$(pixi shell-hook -e jazzy)" works as well.

In any case, the following change needs to be applied to that file:

- source $CONDA_PREFIX/setup.sh
+ source $CONDA_PREFIX/setup.bash

@rhaschke

Copy link
Copy Markdown
Author

Is this issue related: prefix-dev/pixi#2330?

@Tobias-Fischer

Copy link
Copy Markdown
Contributor

Hi @wolfv @ruben-arts @baszalmstra - you probably understand this better than me, could you please take a look?

@Tobias-Fischer

Copy link
Copy Markdown
Contributor

Quick ping @wolfv @ruben-arts @baszalmstra @traversaro

@zimmerman-pliant

zimmerman-pliant commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

A workaround for this in the interim seems to be the following:

sudo apt install python3-argcomplete

then in .bashrc

eval "$(register-python-argcomplete ros2)"
eval "$(register-python-argcomplete colcon)"

Would love this to work out of the box on Robostack installations, however.

@rhaschke

Copy link
Copy Markdown
Author

A workaround for this in the interim seems to be ...

Easier than manually registering all relevant programs, is to source:
.pixi/envs/<distro>/etc/conda/activate.d/ros-<distro>-ros-workspace_activate.sh

as suggested in #206 (comment)

@traversaro

traversaro commented Jun 19, 2026

Copy link
Copy Markdown
Member

Manually sourcing .pixi/envs/jazzy/etc/conda/activate.d/ros-jazzy-ros-workspace_activate.sh enables completion as expected. So, this indeed seems to be a pixi issue. eval "$(pixi shell-hook -e jazzy)" works as well.

In any case, the following change needs to be applied to that file:

- source $CONDA_PREFIX/setup.sh
+ source $CONDA_PREFIX/setup.bash

I think the problem is pixi is not actually executing the scripts in the shell, it executes the scripts, capture how they modified the environment, and then set the modification in the shell. So the autocomplete do not work, see prefix-dev/pixi#2366 . To be honest, I am not sure if this we can fix on the robostack side, or we need to fix something on pixi. fyi @ruben-arts @wolfv

@ruben-arts

Copy link
Copy Markdown
Contributor

Pixi doesn't leave bash functions in the environment after an activation (with pixi shell). For that to work you have to add them to the completions folder. The change in this PR makes sense as it would then support this workflow: https://rattler-build.prefix.dev/latest/system_integration/#installing-shell-completion-scripts

@rhaschke

rhaschke commented Sep 3, 2026

Copy link
Copy Markdown
Author

@ruben-arts: Thanks for the explanation.
However, this PR doesn't yet resolve the problem, because of pixi's configured shell-hook is wrong:

$ pixi shell-hook -e jazzy
...
source /vol/robostack/.pixi/envs/jazzy/share/bash-completion/completions/*
...

The source command just considers the first file argument only. It cannot be used to source multiple files at once!

@ruben-arts

Copy link
Copy Markdown
Contributor

@ruben-arts: Thanks for the explanation. However, this PR doesn't yet resolve the problem, because of pixi's configured shell-hook is wrong:

$ pixi shell-hook -e jazzy
...
source /vol/robostack/.pixi/envs/jazzy/share/bash-completion/completions/*
...

The source command just considers the first file argument only. It cannot be used to source multiple files at once!

Let me fix that in Pixi!

@ruben-arts

Copy link
Copy Markdown
Contributor

That was actually fixed in Pixi already, could you try with the latest version?

@ruben-arts

Copy link
Copy Markdown
Contributor

@ruben-arts

Copy link
Copy Markdown
Contributor

Thanks for your input, I've moved the changes to another branch (#287) as I wasn't allowed to commit to your branch. Closing this PR.

@ruben-arts ruben-arts closed this Sep 4, 2026
@rhaschke

rhaschke commented Sep 4, 2026

Copy link
Copy Markdown
Author

@ruben-arts: thanks for addressing this issue.
@traversaro: could you please merge the PRs for kilted + lyrical too (#206 (comment))?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

completion for ros2cli not working

5 participants