From f14c6dee76d6a7f81d4f432420721eae0aa9692f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven!=20Ragnar=C3=B6k?= Date: Fri, 9 Aug 2024 17:09:23 -0700 Subject: [PATCH] Fix control flow after inverting the conditional. This is a fixup after two earlier changes inverted the conditional and reformatted an internal check. --- src/rosdep2/platforms/pip.py | 48 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/rosdep2/platforms/pip.py b/src/rosdep2/platforms/pip.py index ef3a1edfd..48fe4f231 100644 --- a/src/rosdep2/platforms/pip.py +++ b/src/rosdep2/platforms/pip.py @@ -93,32 +93,34 @@ def externally_managed_installable(): flagrantly named "break system packages" config option or environment variable. """ + + # This doesn't affect Python versions before 3.11 if sys.version_info < (3, 11): return True - if ( - 'PIP_BREAK_SYSTEM_PACKAGES' in os.environ and - os.environ['PIP_BREAK_SYSTEM_PACKAGES'].lower() in ('yes', '1', 'true') - ): - return True - # Check the same configuration directories as pip does per - # https://pip.pypa.io/en/stable/topics/configuration/ - pip_config = ConfigParser() - if 'XDG_CONFIG_DIRS' in os.environ: - for xdg_dir in os.environ['XDG_CONFIG_DIRS'].split(':'): - pip_config_file = Path(xdg_dir) / 'pip' / 'pip.conf' - pip_config.read(pip_config_file) - if pip_config['install']['break-system-packages']: - return True - - fallback_config = Path('/etc/pip.conf') - pip_config.read(fallback_config) - if pip_config['install']['break-system-packages']: - return True - # On Python 3.11 and later, when no explicit configuration is present, - # global pip installation will not work. - return False - else: + + if ( + 'PIP_BREAK_SYSTEM_PACKAGES' in os.environ and + os.environ['PIP_BREAK_SYSTEM_PACKAGES'].lower() in ('yes', '1', 'true') + ): + return True + + # Check the same configuration directories as pip does per + # https://pip.pypa.io/en/stable/topics/configuration/ + pip_config = ConfigParser() + if 'XDG_CONFIG_DIRS' in os.environ: + for xdg_dir in os.environ['XDG_CONFIG_DIRS'].split(':'): + pip_config_file = Path(xdg_dir) / 'pip' / 'pip.conf' + pip_config.read(pip_config_file) + if pip_config['install']['break-system-packages']: + return True + + fallback_config = Path('/etc/pip.conf') + pip_config.read(fallback_config) + if pip_config['install']['break-system-packages']: return True + # On Python 3.11 and later, when no explicit configuration is present, + # global pip installation will not work. + return False def is_cmd_available(cmd):