Skip to content

Commit

Permalink
pip module - editable now applies to all packages
Browse files Browse the repository at this point in the history
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 <nirmal@nirmal.dev>
  • Loading branch information
nirmal-j-patel committed Feb 4, 2023
1 parent 379058e commit bb12409
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions 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.
21 changes: 10 additions & 11 deletions lib/ansible/modules/pip.py
Expand Up @@ -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,
)

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bb12409

Please sign in to comment.