-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for pip configuration when an externally managed environment is…
… detected. (#979) * Raise an error when an externally managed environment is detected. rosdep is designed to treat pip like an alternative system-level package manager. Deviating from this approach is not easily achievable without a significant rethinking of how pip packages are managed. In the meantime, we can at least instruct users how to restore the prior functionality. Rather than inject the environment variable / config on behalf of the user, this change instructs them to make the necessary config changes themself, keeping them informed of the change their making to the system's new default. * Fix typos and punctuation. Co-authored-by: Christophe Bedard <[email protected]> * Use tuple rather than list literal. Co-authored-by: Christophe Bedard <[email protected]> * Consolidate version check. * Pass necessary environment variable via sudo. * Update test to expect sudo --preserve-env for pip. * flake8 cleanup * Run pip tests with PIP_BREAK_SYSTEM_PACKAGES=1. * Add documentation for pip configuration. * Add doc link to error output. * Use inline monospace font to refer to rosdep the cli tool. * Briefly note that sudo configuration could prevent this from working. * Recommend a specific config file to use and format user config as a warning. * Fix errors in config checker. The fallback configuration was over-indented and would never be checked. * Change formatting of rosdep. Use monospace formatting when referring to the `rosdep` command / executable name and simply 'rosdep' when referring to the project. The preferred capitalization of rosdep is rosdep not Rosdep or ROSdep (and certainly not ROSDep). * Complete a sentence I stopped writing. * Add period to end of sentence. Co-authored-by: Christophe Bedard <[email protected]> * Add period to end of sentence. Co-authored-by: Christophe Bedard <[email protected]> * Invert conditional for an earlier return. Co-authored-by: Christophe Bedard <[email protected]> * Edit text for clarity and typos. Co-authored-by: Christophe Bedard <[email protected]> * Reflow conditional for easier reading. * Fix control flow after inverting the conditional. This is a fixup after two earlier changes inverted the conditional and reformatted an internal check. * Add test to confirm that get_install_command handles externally managed environments. * Use ConfigParser.getboolean to check config value. Using the dict access method will raise a KeyError when the config file is present but this section or value is missing. --------- Co-authored-by: Christophe Bedard <[email protected]>
- Loading branch information
1 parent
2214f6a
commit 55f5b39
Showing
4 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ Contents | |
sources_list | ||
developers_guide | ||
rosdep2_api | ||
pip_and_pep_668 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Pip installation after PEP 668 | ||
============================== | ||
|
||
`PEP-668`_ introduced `externally managed environments <externally-managed-environments>`_ to Python packaging. | ||
|
||
rosdep is designed to use pip as an alternative system package manager, rosdep installation of pip packages requires installing packages globally as root. | ||
Starting with Python 3.11, `PEP-668`_ compliance requires you to allow pip to install alongside externally managed packages using the ``break-system-packages`` option. | ||
|
||
There are multiple ways to configure pip so that rosdep will succeed. | ||
|
||
|
||
Configure using environment variable | ||
------------------------------------ | ||
|
||
This is the way that we recommend configuring pip for rosdep usage. | ||
We recommend configuring pip using the system environment. | ||
Setting environment variables in your login profile, ``PIP_BREAK_SYSTEM_PACKAGES`` in your environment. | ||
The value of the environment variable can be any of ``1``, ``yes``, or ``true``. | ||
The string values are not case sensitive. | ||
|
||
rosdep is designed to use ``sudo`` in order to gain root privileges for installation when not run as root. | ||
If your system's sudo configuration prohibits the passing of environment variables use the :ref:`pip.conf <configure-using-pip.conf>` method below. | ||
|
||
|
||
.. _configure-using-pip.conf: | ||
|
||
Configure using pip.conf | ||
------------------------ | ||
|
||
`Pip configuration files <pip-configuration>`_ can be used to set the desired behavior. | ||
Pip checks for global configuration files in ``XDG_CONFIG_DIRS``, as well as ``/etc/pip.conf``. | ||
For details on ``XDG_CONFIG_DIRS`` refer to the `XDG base directories specification <xdg-base-dirs>`_. | ||
If you're unsure which configuration file is in use by your system, ``/etc/pip.conf`` seems like the most generic. | ||
|
||
.. code-block:: ini | ||
[install] | ||
break-system-packages = true | ||
.. warning:: Creating a pip.conf in your user account's ``XDG_CONFIG_HOME`` (e.g. ``~/.config/pip/pip.conf``) does not appear to be sufficent when installing packages globally. | ||
|
||
|
||
Configuring for CI setup | ||
------------------------ | ||
|
||
Either environment variables or configuration files can be used with your CI system. | ||
Which one you choose will depend on how your CI environment is configured. | ||
Perhaps the most straightforward will be to set the environent variable in the shell or script execution context before invoking ``rosdep``. | ||
|
||
.. code-block:: bash | ||
sudo rosdep init | ||
rosdep update | ||
PIP_BREAK_SYSTEM_PACKAGES=1 rosdep install -r rolling --from-paths src/ | ||
If ``rosdep`` is invoked by internal processes in your CI and you need to set the configuration without having direct control over how ``rosdep install`` is run, setting the environment variable globally would also work. | ||
|
||
.. code-block:: bash | ||
export PIP_BREAK_SYSTEM_PACKAGES=1 | ||
./path/to/ci-script.sh | ||
If you cannot set environment variables but you can create configuration files, you can set ``/etc/pip.conf`` with the necessary configuration. | ||
|
||
.. code-block:: bash | ||
printf "[install]\nbreak-system-packages = true\n" | sudo tee -a /etc/pip.conf | ||
.. _PEP-668: https://peps.python.org/pep-0668/ | ||
.. _pip-configuration: https://pip.pypa.io/en/stable/topics/configuration/ | ||
.. _externally-managed-environments: https://packaging.python.org/en/latest/specifications/externally-managed-environments/ | ||
.. _xdg-base-dirs: https://specifications.freedesktop.org/basedir-spec/latest/ |
This file contains 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
This file contains 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