Skip to content

feat: Autocompletion on pixi #271

Closed
Closed

Description

@EliaCereda

Pixi has implemented support for shell autocompletion scripts a few weeks ago in (prefix-dev/pixi#3219 and prefix-dev/pixi#2366)

To take advantage of this feature, a package needs to install autocompletion files in one of these directories depending on the user's shell:

  • share/bash-completion/completions
  • share/zsh/site-functions
  • share/fish/vendor_completions.d

I tested this with both Bash and Zsh on macOS, using the attached scripts (unzip in the root of your pixi workspace) and it's working great. What's missing is just RoboStack installing these files automatically as part of the distribution.

Is this the correct repo to discuss how to possibly get this merged? We encountered this as part of a university course on ROS we are teaching, so we'd really benefit from a fix. I can send a pull request after we define how you'd like to approach this.

Thank you!

ros-autocompletion.zip

Activity

  1. Tobias-Fischer commented on Mar 27, 2025

    @Tobias-Fischer
    Contributor

    A question for @wolfv I think how to best achieve this

  2. Tobias-Fischer commented on Mar 27, 2025

    @Tobias-Fischer
    Contributor

    PS: which uni / course do you teach?

  3. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    I guess also @ruben-arts may be interested.

  4. EliaCereda commented on Mar 27, 2025

    @EliaCereda
    ContributorAuthor

    It's Robotics in the Master in AI at USI (Lugano, Switzerland), https://search.usi.ch/en/courses/35270726/robotics

    Thanks to Pixi we've been able to migrate from a cumbersome VM that we used to prepare and distribute to students, to a single set of instructions that they can follow themselves to setup a native environment in macOS / Ubuntu / Windows. It's a great improvement!

  5. ruben-arts commented on Mar 27, 2025

    @ruben-arts
    Contributor

    That's great to hear @EliaCereda, exactly what we are designing pixi for!

    The quickest way would be to add these scripts to the colcon and the package the ros2 cli comes from. It's also pretty normal to create a separate package like colcon-completions which you would version similarly to colcon. This way, a user can decide to install the completions.

    The extra package has my preference but might not be worth the work as these environments are huge anyway.

  6. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    I am bit confused on how this works anyhow. I have a bit of experience with feedstock providing autocomplete scripts (see https://github.com/conda-forge/yarp-feedstock, even if it is not clear how that works from the feedstock as the installation is handled by CMake), but I am not sure how the proposed one works.

    In particular if the autocomplete script is:

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

    who installs the register-python-argcomplete executable? Python? In that case, for colcon we can add it in https://github.com/conda-forge/colcon-core-feedstock/blob/main/recipe/meta.yaml, that already installs the colcon entry point, but to follow @ruben-arts suggestions we would need to turn that in a multi-output recipe. @ruben-arts do you have any example feedstock implementing that?

    Just to understand, what is the reason not to just add the autocomplete script in the main package? The increase time spent in the activation scripts, or people not wanting autocomplete for some reason?

  7. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    On the colcon side I found https://github.com/colcon/colcon-argcomplete, that is packaged in https://github.com/conda-forge/colcon-argcomplete-feedstock, have you tried if just installing colcon-argcomplete works fine? (in that case, a possible action is just to document that this needs to be installed for autocompletion).

  8. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    On the colcon side I found https://github.com/colcon/colcon-argcomplete, that is packaged in https://github.com/conda-forge/colcon-argcomplete-feedstock, have you tried if just installing colcon-argcomplete works fine? (in that case, a possible action is just to document that this needs to be installed for autocompletion).

    By looking at the installed files ( https://conda-metadata-app.streamlit.app/?q=conda-forge%2Fnoarch%2Fcolcon-argcomplete-0.3.3-pyhd8ed1ab_1.conda ) I guess it does not work out of the box, we probably need to install some scripts in share/bash-completion/completions and share/zsh/site-functions that call the existing scripts, and verify if they do not conflict with then the same script is called as part of the colcon workspace activation.

  9. traversaro commented on Mar 27, 2025

    @traversaro
    Member
  10. EliaCereda commented on Mar 27, 2025

    @EliaCereda
    ContributorAuthor

    I haven't looked deep into how it works, the register-python-argcomplete commands are from this answer: https://robotics.stackexchange.com/a/100987

    There should be a cleaner way of doing this. Installing ROS from Ubuntu APT does indeed install autocompletion by default, but I could not find how that is setup exactly

  11. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    There should be a cleaner way of doing this. Installing ROS from Ubuntu APT does indeed install autocompletion by default, but I could not find how that is setup exactly

    Is ROS autocompletion on by default, or just after sourcing the setup.sh ? I would be surprised if it works even without sourcing the setup.sh of the ROS installation. What about colcon instead?

  12. EliaCereda commented on Mar 27, 2025

    @EliaCereda
    ContributorAuthor

    No, it's enabled by the setup.sh. This doesn't work in Pixi because I think it executes the setup.sh in a sub-shell which collects what environment variables are set and then only sets those in the actual user shell. This is true for both the setup.sh of the ROS distribution and for any setup.sh that are added as activation scripts in the pixi.toml.

  13. traversaro commented on Mar 27, 2025

    @traversaro
    Member

    Ah, hence the need for actually installing the scripts in share/bash-completion/completions.

  14. EliaCereda commented on Mar 31, 2025

    @EliaCereda
    ContributorAuthor

    I just spent a bit more time looking at what ROS actually does to enable autocompletion.

    The sequence for a normal ROS installation is:

    • The user sources the setup.sh for a given workspace
    • setup.sh runs source local_setup.sh for the current workspace and all underlying workspaces
    • Each local_setup.sh runs _local_setup_util.py to collect the activation commands of all installed packages
    • Activation commands are loaded from share/<package name/package.dsv if it exists, otherwise default to share/<package name/local_setup.{sh,bash,zsh}
    • local_setup.sh evals the output of _local_setup_util.py to run the commands inside the user's shell

    Here's the output I get from _local_setup_util.py on my system:

    AMENT_CURRENT_PREFIX="/<path>/.pixi/envs/default" _ament_prefix_sh_source_script "/<path>/.pixi/envs/default/share/ros2cli/environment/ros2-argcomplete.zsh"
    AMENT_CURRENT_PREFIX="/<path>/.pixi/envs/default" _ament_prefix_sh_source_script "/<path>/.pixi/envs/default/share/ros_environment/environment/0.ros_distro_check.sh"
    export ROS_DISTRO="humble"
    # export ROS_LOCALHOST_ONLY="0"
    export ROS_PYTHON_VERSION="3"
    export ROS_VERSION="2"
    AMENT_CURRENT_PREFIX="/<path>/.pixi/envs/default" _ament_prefix_sh_source_script "/<path>/.pixi/envs/default/share/rosidl_cli/environment/rosidl-argcomplete.zsh"

    _ament_prefix_sh_source_script is defined in local_setup.sh, it just sources the file if it exists, and ignores it otherwise.

    Out of those commands, ros2-argcomplete.sh doesn't do anything except calling register-python-argcomplete:

    if type register-python-argcomplete3 > /dev/null 2>&1; then
      eval "$(register-python-argcomplete3 ros2)"
    elif type register-python-argcomplete > /dev/null 2>&1; then
      eval "$(register-python-argcomplete ros2)"
    fi

    So it seems to me we have two problems here:

    • When launching a pixi shell, Pixi sources the setup.sh with its custom system that preserves environment variables but not other shell customization (such as autocompletion). This breaks the assumption of ROS packages that they'll have their activation scripts sourced directly from the user shell.
    • Even if I source the setup.sh inside a pixi shell manually, it doesn't seem to enable the autocompletion correctly. Running eval "$(register-python-argcomplete ros2)" directly works instead.

    The latter might be the same problem from the StackOverflow answer I linked above (I haven't investigated further)

    I haven't looked deep into how it works, the register-python-argcomplete commands are from this answer:
    https://robotics.stackexchange.com/a/100987

    The former however appears to me as a fundamental problem in the way Pixi handles activation scripts. Do you have ideas for how ROS should fit in your design?

  15. traversaro commented on Mar 31, 2025

    @traversaro
    Member

    Thanks for the in-detail analysis. From my point of view, the simple solution for this is:

    • Modify/patch the colcon-argcomplete conda-forge recipe to install its argcomplete script in the folders supported by pixi. In this case, also just copying the files in the build.sh script is doable.
    • Modify/patch the ros-humble-ros2cli robostack package to install its argcomplete script in the folders supported by pixi. In this case, modifying the build.sh is more tricky as that is generated by vinca, an easier option may be to do a simple patch to the CMakeLists.txt of ros2cli to install them in the correct place.

    My only doubt is for @ruben-arts , i.e. quoting my earlier comment:

    Just to understand, what is the reason not to just add the autocomplete script in the main package? The increase time spent in the activation scripts, or people not wanting autocomplete for some reason?

    Unless there is a compelling reason do to that, I would avoid the complexity of adding an output for the recipe just for the autocomplete script, that especially for robostack packages is really far from trivial.

  16. wolfv commented on Mar 31, 2025

    @wolfv
    Member

    I think it's fine to add the autocompletion script to the main output.

    They will only be sourced when running pixi shell, so pixi run would not have a performance hit.

    And for pixi shell it's a nice-to-have feature in my opinion :)

  17. traversaro commented on Mar 31, 2025

    @traversaro
    Member

    Ah, one additional note, probably we may want to patch:

    to simply be eval "$(register-python-argcomplete colcon)" and eval "$(register-python-argcomplete ros2). As far as I can see, register-python-argcomplete3 was never packaged in conda-forge, so the only case in which register-python-argcomplete3 exists is on old Ubuntu distros, and preferring register-python-argcomplete3 over register-python-argcomplete will mean that the apt python is used in place of the conda/pixi python, resulting in wrong autocompletes.

  18. traversaro commented on Mar 31, 2025

    @traversaro
    Member

    So we also get rid of the need to have different scripts of zsh and bash.

  19. EliaCereda commented on Mar 31, 2025

    @EliaCereda
    ContributorAuthor

    I went ahead and tried to patch ros2cli and rosidl_cli to install their autocompletion scripts in the proper locations. Is anything else needed for these patches to be picked up by the build system?

  20. traversaro commented on Mar 31, 2025

    @traversaro
    Member

    I went ahead and tried to patch ros2cli and rosidl_cli to install their autocompletion scripts in the proper locations. Is anything else needed for these patches to be picked up by the build system?

    Yes, but I will comment in the PR, thanks for looking into this!

  21. traversaro commented on Apr 10, 2025

    @traversaro
    Member

    This should have been fixed by prefix-dev/pixi#3506, @EliaCereda did you checked if everything works as expected? Thanks!

  22. EliaCereda commented on Apr 10, 2025

    @EliaCereda
    ContributorAuthor

    I tried briefly yesterday but it didn't seem to work, I still need to investigate. ros2cli is installing the files but autocompletion is not activated, while rosidl-cli doesn't install the file at all.

    Do you have any idea why for the latter?

  23. traversaro commented on Apr 10, 2025

    @traversaro
    Member

    This is interesting. Can you report a conda list or pixi list ? So we verify that indeed the build number of the packages is indeed _9 (the version that should include our patches), see https://anaconda.org/robostack-humble/ros-humble-ros2cli/files and https://anaconda.org/robostack-humble/ros-humble-rosidl-cli/files . You can even enforce this in your pixi file if you want, with:

    ros-humble-ros2cli = { version = "*", build = "*_9" }
    ros-humble-rosidl-cli = { version = "*", build = "*_9" }
    
  24. wolfv commented on Apr 10, 2025

    @wolfv
    Member

    Please let me know if there is an issue in the pixi side of things :)

  25. 2lian commented on Nov 22, 2025

    @2lian

    Hi there!

    Is this supposed to be working? because it is not working for me despite using the latest versions of the packages.

    pixi list -e humble | grep cli
    
    Environment: humble
    jupyter_client                                     8.6.3               pyhd8ed1ab_1             103.8 KiB   conda  https://prefix.dev/conda-forge/
    nbclient                                           0.10.2              pyhd8ed1ab_0             27.4 KiB    conda  https://prefix.dev/conda-forge/
    prometheus_client                                  0.23.1              pyhd8ed1ab_0             53.3 KiB    conda  https://prefix.dev/conda-forge/
    pulseaudio-client                                  17.0                h9a6aba3_3               733.2 KiB   conda  https://prefix.dev/conda-forge/
    ros-humble-ros2cli                                 0.18.12             np126py311hbc2a38a_13    72.7 KiB    conda  https://prefix.dev/robostack-humble/
    ros-humble-ros2cli-common-extensions               0.1.1               np126py311hbc2a38a_13    25.4 KiB    conda  https://prefix.dev/robostack-humble/
    ros-humble-rosidl-cli                              3.1.6               np126py311hbc2a38a_13    38.1 KiB    conda  https://prefix.dev/robostack-humble/
    websocket-client                                   1.9.0               pyhd8ed1ab_0             60 KiB      conda  https://prefix.dev/conda-forge/
    

    What I don't exactly understand either is that when I pixi shell then eval "$(register-python-argcomplete colcon); eval "$(register-python-argcomplete ros2)", then it works fine. However I cannot automatically source those commands in my pixi.toml like so:

    [feature.humble.activation]
    scripts = [
    "workspace/install-humble/setup.bash",
    "scripts/ros_autocomplete.bash",
    ]
    
  26. kyrie2to11 commented on Jan 29, 2026

    @kyrie2to11

    Hi there!

    Is this supposed to be working? because it is not working for me despite using the latest versions of the packages.

    pixi list -e humble | grep cli
    
    Environment: humble
    jupyter_client                                     8.6.3               pyhd8ed1ab_1             103.8 KiB   conda  https://prefix.dev/conda-forge/
    nbclient                                           0.10.2              pyhd8ed1ab_0             27.4 KiB    conda  https://prefix.dev/conda-forge/
    prometheus_client                                  0.23.1              pyhd8ed1ab_0             53.3 KiB    conda  https://prefix.dev/conda-forge/
    pulseaudio-client                                  17.0                h9a6aba3_3               733.2 KiB   conda  https://prefix.dev/conda-forge/
    ros-humble-ros2cli                                 0.18.12             np126py311hbc2a38a_13    72.7 KiB    conda  https://prefix.dev/robostack-humble/
    ros-humble-ros2cli-common-extensions               0.1.1               np126py311hbc2a38a_13    25.4 KiB    conda  https://prefix.dev/robostack-humble/
    ros-humble-rosidl-cli                              3.1.6               np126py311hbc2a38a_13    38.1 KiB    conda  https://prefix.dev/robostack-humble/
    websocket-client                                   1.9.0               pyhd8ed1ab_0             60 KiB      conda  https://prefix.dev/conda-forge/
    

    What I don't exactly understand either is that when I pixi shell then eval "$(register-python-argcomplete colcon); eval "$(register-python-argcomplete ros2)", then it works fine. However I cannot automatically source those commands in my pixi.toml like so:

    [feature.humble.activation]
    scripts = [
    "workspace/install-humble/setup.bash",
    "scripts/ros_autocomplete.bash",
    ]
    

    Same problem—any elegant workaround these days? Thanks!

    jarvis@ThinkPad-P1-Gen-6:~/projects/iRail-Truck/ros2bookcode$ pixi --version
    pixi 0.63.2
  27. Tobias-Fischer commented on Oct 18, 2026

    @Tobias-Fischer
    Contributor

    Fixed for ros2 (and rosidl) in the RoboStack monorepo, RoboStack/robostack, where all ROS 2 distributions are now built by RoboStack/robostack#70: the bash and zsh completions are now installed where the shells pick them up automatically, including in pixi environments. For humble, it ships with the rebuild in RoboStack/robostack#62, so it reaches users once that's merged and uploaded; the published ros2cli doesn't have it yet. colcon completion, also asked about here, comes from conda-forge's colcon-argcomplete, not RoboStack.

    🤖 Claude (AI assistant), on behalf of @Tobias-Fischer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions