From bb12409d61d736a9a7450e7ae6ad66ace8153200 Mon Sep 17 00:00:00 2001 From: Nirmal Patel Date: Fri, 10 Jun 2022 12:11:12 -0400 Subject: [PATCH] pip module - editable now applies to all packages When editable is set to true, -e flag should be passed to all packages. This change passes -e flag before each package name. However, if a requirements file is used, then editable flag raises errors. Therefore, editable and requirements are now mutually exclusive. Fixes #77755 Signed-off-by: Nirmal Patel --- .../77755-pip-module-editable-flag-fix.yml | 4 ++++ lib/ansible/modules/pip.py | 21 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/77755-pip-module-editable-flag-fix.yml diff --git a/changelogs/fragments/77755-pip-module-editable-flag-fix.yml b/changelogs/fragments/77755-pip-module-editable-flag-fix.yml new file mode 100644 index 00000000000..2e532167359 --- /dev/null +++ b/changelogs/fragments/77755-pip-module-editable-flag-fix.yml @@ -0,0 +1,4 @@ +bugfixes: + - pip - when editable set to true, '-e' flag is passed before each package. + When requirments file is used, editable flag does not pass '-e' to avoid + errors. diff --git a/lib/ansible/modules/pip.py b/lib/ansible/modules/pip.py index 15c8c4420aa..d1942f1ea87 100644 --- a/lib/ansible/modules/pip.py +++ b/lib/ansible/modules/pip.py @@ -655,7 +655,11 @@ def main(): umask=dict(type='str'), ), required_one_of=[['name', 'requirements']], - mutually_exclusive=[['name', 'requirements'], ['executable', 'virtualenv']], + mutually_exclusive=[ + ['name', 'requirements'], + ['executable', 'virtualenv'], + ['editable', 'requirements'], + ], supports_check_mode=True, ) @@ -671,6 +675,7 @@ def main(): chdir = module.params['chdir'] umask = module.params['umask'] env = module.params['virtualenv'] + editable = module.params['editable'] venv_created = False if env and chdir: @@ -742,20 +747,14 @@ def main(): # if the version specifier is provided by version, append that into the package packages[0] = Package(to_native(packages[0]), version) - if module.params['editable']: - args_list = [] # used if extra_args is not used at all - if extra_args: - args_list = extra_args.split(' ') - if '-e' not in args_list: - args_list.append('-e') - # Ok, we will reconstruct the option string - extra_args = ' '.join(args_list) - if extra_args: cmd.extend(shlex.split(extra_args)) if name: - cmd.extend(to_native(p) for p in packages) + for p in packages: + if editable: + cmd.append('-e') + cmd.append(to_native(p)) elif requirements: cmd.extend(['-r', requirements]) else: