From 9ebb7450d582c0073d1fcb193cbef1da057f0546 Mon Sep 17 00:00:00 2001 From: y-p Date: Mon, 3 Jun 2013 18:14:21 +0300 Subject: [PATCH 1/2] Add chdir parameter to pip --- library/packaging/pip | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/packaging/pip b/library/packaging/pip index ceffe923fb..fe128b58f6 100644 --- a/library/packaging/pip +++ b/library/packaging/pip @@ -91,6 +91,13 @@ options: required: false default: null version_added: "1.0" + chdir: + description: + - cd into this directory before running the command + version_added: "1.3" + required: false + default: null + examples: - code: "pip: name=flask" description: Install I(flask) python package. @@ -170,6 +177,7 @@ def main(): virtualenv_command=dict(default='virtualenv', required=False), use_mirrors=dict(default='yes', type='bool'), extra_args=dict(default=None, required=False), + chdir=dict(default=None, required=False), ), required_one_of=[['name', 'requirements']], mutually_exclusive=[['name', 'requirements']], @@ -182,6 +190,7 @@ def main(): requirements = module.params['requirements'] use_mirrors = module.params['use_mirrors'] extra_args = module.params['extra_args'] + chdir = module.params['chdir'] if state == 'latest' and version is not None: module.fail_json(msg='version is incompatible with state=latest') @@ -205,6 +214,8 @@ def main(): else: cmd = '%s %s' % (virtualenv, env) os.chdir(tempfile.gettempdir()) + if chdir: + os.chdir(chdir) rc, out_venv, err_venv = module.run_command(cmd) out += out_venv err += err_venv @@ -253,6 +264,8 @@ def main(): if module.check_mode: module.exit_json(changed=True) os.chdir(tempfile.gettempdir()) + if chdir: + os.chdir(chdir) rc, out_pip, err_pip = module.run_command(cmd) out += out_pip err += err_pip From 50666eac34a9e354705cd49109f53c4ab75590e9 Mon Sep 17 00:00:00 2001 From: y-p Date: Tue, 4 Jun 2013 03:01:42 +0300 Subject: [PATCH 2/2] Add is_local_path check to pip module, for skipping --use-mirrors --- library/packaging/pip | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/packaging/pip b/library/packaging/pip index fe128b58f6..4ae145eecd 100644 --- a/library/packaging/pip +++ b/library/packaging/pip @@ -239,6 +239,7 @@ def main(): # is_tar ends with .zip, .tar.gz, or .tar.bz2 is_vcs = False is_tar = False + is_local_path = False if name.endswith('.tar.gz') or name.endswith('.tar.bz2') or name.endswith('.zip'): is_tar = True elif name.startswith('svn+') or name.startswith('git+') or \ @@ -253,8 +254,11 @@ def main(): args_list.append('-e') # Ok, we will reconstruct the option string extra_args = ' '.join(args_list) + + if name.startswith(('.','/')): + is_local_path = True # for tarball or vcs source, applying --use-mirrors doesn't really make sense - is_package = is_vcs or is_tar # just a shortcut for bool + is_package = is_vcs or is_tar or is_local_path # just a shortcut for bool if not is_package and state != 'absent' and use_mirrors: cmd += ' --use-mirrors' cmd += ' %s' % _get_full_name(name, version)