From 77dc4f3af090537f0c62a40e421684ede191cd76 Mon Sep 17 00:00:00 2001 From: Alex Kulbii Date: Fri, 15 May 2015 13:08:02 +0200 Subject: [PATCH 1/2] Added function to update easy-install.pth file --- virtualenv_tools.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/virtualenv_tools.py b/virtualenv_tools.py index f5671c1..1dc1cc1 100644 --- a/virtualenv_tools.py +++ b/virtualenv_tools.py @@ -183,9 +183,12 @@ def update_paths(base, new_path): print 'error: %s does not refer to a python installation' % base return False + easy_install_pth = os.path.join(base_lib_dir,lib_name,'site-packages','easy-install.pth') + update_scripts(bin_dir, new_path) update_pycs(lib_dir, new_path, lib_name) update_local(base, new_path) + update_pth_files(easy_install_pth, new_path) return True @@ -234,6 +237,28 @@ def reinitialize_virtualenv(path): args.append(path) subprocess.Popen(args, env=new_env).wait() +def update_pth_files(filename, new_path): + """Updates easy_install.pth files with new path + This file is created when we use 'editable' form of packages installation + We need to add path to src directory of virtualenv + """ + with open(filename) as f: + lines = list(f) + if not lines: + return + + # Assume that all lines that don't start with import are paths + # Assume that module name is located after last src/ directory in path + for number,line in enumerate(lines): + if not line.startswith('import'): + module_directory = line.split('src')[-1] + # Cut leading slash from path + module_directory = module_directory[1:] + lines[number] = os.path.join(new_path, 'src', module_directory) + + print 'S %s' % filename + with open(filename, 'w') as f: + f.writelines(lines) def main(): parser = optparse.OptionParser() From d7ef7e6d90692a6c50259a4f54a2d9a3f3a21558 Mon Sep 17 00:00:00 2001 From: Alex Kulbii Date: Fri, 15 May 2015 14:12:47 +0200 Subject: [PATCH 2/2] Added condition if pth file is absent --- virtualenv_tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virtualenv_tools.py b/virtualenv_tools.py index 1dc1cc1..bb01d27 100644 --- a/virtualenv_tools.py +++ b/virtualenv_tools.py @@ -188,7 +188,8 @@ def update_paths(base, new_path): update_scripts(bin_dir, new_path) update_pycs(lib_dir, new_path, lib_name) update_local(base, new_path) - update_pth_files(easy_install_pth, new_path) + if os.path.isfile(easy_install_pth): + update_pth_files(easy_install_pth, new_path) return True