correct virtualenv creation
authorymh <ymh.work@gmail.com>
Thu, 14 Jun 2012 18:26:25 +0200
changeset 671 fc56b4c9e4f3
parent 670 5e2f25f59429
child 672 ff3cb137bad4
correct virtualenv creation
virtualenv/res/lib/lib_create_env.py
virtualenv/setup/res/res_create_env.py
virtualenv/sync/create_python_env.py
virtualenv/sync/res/res_create_env.py
virtualenv/web/create_python_env.py
virtualenv/web/res/res_create_env.py
--- a/virtualenv/res/lib/lib_create_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/res/lib/lib_create_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -11,7 +11,6 @@
 join = os.path.join
 system_str = platform.system()
 
-
 URLS = {
     #'': {'setup': '', 'url':'', 'local':''},
     'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.4/tarball/', 'local':"Django-1.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
@@ -29,8 +28,8 @@
     'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.7.5.tar.gz', 'local':"south-0.7.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
     'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'http://pypi.python.org/packages/source/d/django-guardian/django-guardian-1.0.3.tar.gz', 'local':"django-guardian-1.0.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
     'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'http://pypi.python.org/packages/source/s/sorl-thumbnail/sorl-thumbnail-11.12.tar.gz', 'local':"sorl-thumbnail-v10.12.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
-    'LIBJPEG': {'setup': None, 'url':'jpegsrc.v8d.tar.gz', 'local':'jpegsrc.v8d.tar.gz', 'install': {'method': install_libjpeg, 'option_str': None, 'dict_extra_env': None}},
-    'ZLIB': {'setup': None, 'url':'zlib-1.2.7.tar.gz', 'local':'zlib-1.2.7.tar.gz', 'install': {'method': install_zlib, 'option_str': None, 'dict_extra_env': None}},
+    'LIBJPEG': {'setup': None, 'url':'jpegsrc.v8d.tar.gz', 'local':'jpegsrc.v8d.tar.gz', 'install': {'method': 'install_libjpeg', 'option_str': None, 'dict_extra_env': None}},
+    'ZLIB': {'setup': None, 'url':'zlib-1.2.7.tar.gz', 'local':'zlib-1.2.7.tar.gz', 'install': {'method': 'install_zlib', 'option_str': None, 'dict_extra_env': None}},
     'PYCRYPTO': {'setup': 'pycrypto', 'url':'https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz', 'local':'pycrypto-2.6.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
     'SSH': {'setup': 'ssh', 'url':'http://pypi.python.org/packages/source/s/ssh/ssh-1.7.14.tar.gz#md5=4cdd0549ef4699bd67b96264d3b21427', 'local':'ssh-1.7.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
     'FABRIC': {'setup': 'fabric', 'url':'https://github.com/fabric/fabric/tarball/1.4.2', 'local':'fabric-1.4.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
@@ -39,7 +38,7 @@
 
 if system_str == 'Windows':
     URLS.update({
-        'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip', 'local':"psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip", 'install': {'method': install_psycopg2, 'option_str': None, 'dict_extra_env': None}},
+        'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip', 'local':"psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
         'JCC': {'setup': 'jcc', 'url': 'http://pylucene-win32-binary.googlecode.com/files/JCC-2.6-py2.6-win32.egg', 'local':"JCC-2.6-py2.6-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
         'PYLUCENE': {'setup': 'pylucene', 'url': 'http://pylucene-win32-binary.googlecode.com/files/lucene-3.0.2-py2.6-win32.egg', 'local':"lucene-3.0.2-py2.6-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.6.exe', 'local':"PIL-1.1.7.win32-py2.6.exe", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
@@ -48,7 +47,7 @@
 else:
     URLS.update({
         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz', 'local':"psycopg2-2.4.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
-        'PYLUCENE': {'setup': 'pylucene', 'url': 'http://mirrors.ircam.fr/pub/apache/lucene/pylucene/pylucene-3.6.0-2-src.tar.gz', 'local':"pylucene-3.6.0-2-src.tar.gz", 'install': {'method': install_pylucene, 'option_str': None, 'dict_extra_env': None}},
+        'PYLUCENE': {'setup': 'pylucene', 'url': 'http://mirrors.ircam.fr/pub/apache/lucene/pylucene/pylucene-3.6.0-2-src.tar.gz', 'local':"pylucene-3.6.0-2-src.tar.gz", 'install': {'method': 'install_pylucene', 'option_str': None, 'dict_extra_env': None}},
         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
         'LXML': {'setup': 'lxml', 'url':"lxml-2.3.4.tar.bz2", 'local':"lxml-2.3.4.tar.bz2", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.7.8', 'LIBXSLT_VERSION': '1.1.26', 'LIBICONV_VERSION': '1.13.1'}}},
     })
@@ -91,8 +90,7 @@
         '--type-install',
         metavar='type_install',
         dest='type_install',
-        default='local',
-        help='type install : local, url, setup')
+        help='type install : local, url, setup - default : local')
     parser.add_option(
         '--ignore-packages',
         metavar='ignore_packages',
@@ -100,10 +98,6 @@
         default=None,
         help='list of comma separated keys for package to ignore')
 
-def adjust_options(options, args):
-    pass
-
-
 def install_pylucene(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
     
     logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key])
@@ -249,7 +243,7 @@
     
     
 
-def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, urls=None):
+def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
     
     all_urls = URLS.copy()
     if urls is not None:
@@ -311,8 +305,10 @@
         ensure_dir(src_dir, logger)
         ensure_dir(tmp_dir, logger)
         system_str = platform.system()
-        
-        res_source_key = options.type_install
+                
+        res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
+        if res_source_key is None:
+            res_source_key = local
         
         ignore_packages = []
         
@@ -339,6 +335,8 @@
                 if key not in ignore_packages:
                     if callable(method):
                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
+                    elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
+                        globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
                     else:
                         normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
                             
@@ -351,17 +349,12 @@
         logger.notify('Run "%s Package" to install new packages that provide builds'
                       % join(script_dir, 'easy_install'))
     
+    def adjust_options(options, args):
+        if not options_to_add:
+            pass
+        for opt in options_to_add:
+            test_opt = opt.split('=',1)[0]
+            if not hasattr(options,test_opt) or getattr(options, test_opt) is None:                
+                setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
 
     return adjust_options, extend_parser, after_install
-
-def lib_add_options(options_to_add):
-    import sys
-    def check_option(str):
-        for opt in sys.argv:
-            if opt.startswith(str):
-                return true
-        return false
-    for opt in options_to_add:
-        test_opt = opt.split(['='])[0]
-        if not check_option(test_opt):
-            sys.argv.insert(len(sys.argv)-1, opt)
--- a/virtualenv/setup/res/res_create_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/setup/res/res_create_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -1,6 +1,6 @@
 import platform
 
-from lib_create_env import lib_generate_install_methods, install_pylucene, install_psycopg2, lib_add_options
+from lib_create_env import lib_generate_install_methods, install_pylucene, install_psycopg2
 
 system_str = platform.system()
 
@@ -8,9 +8,8 @@
 INSTALLS = [#(key,method, option_str, dict_extra_env)
 ]
 
-OPTIONS_TO_ADD = ['--no-site-packages','--clear', '--type-install=local', "--unzip-setuptools"]
+OPTIONS_TO_ADD = ['clear', 'type_install=local', "unzip-setuptools", "use_distribute"]
 
 def generate_install_methods(path_locations, src_base, Logger, call_subprocess):    
-    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS)
+    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS, OPTIONS_TO_ADD)
 
-add_options = lambda : lib_add_options(OPTIONS_TO_ADD)
\ No newline at end of file
--- a/virtualenv/sync/create_python_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/sync/create_python_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -30,9 +30,8 @@
 EXTRA_TEXT  = "import sys\n"
 EXTRA_TEXT += "sys.path.append('%s')\n" % (lib_path)
 EXTRA_TEXT += "sys.path.append('%s')\n" % (os.path.abspath(os.path.join(here,"res")).replace("\\","/"))
-EXTRA_TEXT += "from res_create_env import generate_install_methods, add_options\n"
+EXTRA_TEXT += "from res_create_env import generate_install_methods\n"
 EXTRA_TEXT += "adjust_options, extend_parser, after_install = generate_install_methods(path_locations, '%s', Logger, call_subprocess)\n" % (src_base)
-EXTRA_TEXT += "add_options()"
 
 
 def main():
--- a/virtualenv/sync/res/res_create_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/sync/res/res_create_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -1,6 +1,6 @@
 import platform
 
-from lib_create_env import lib_generate_install_methods, lib_add_options
+from lib_create_env import lib_generate_install_methods
 
 system_str = platform.system()
 
@@ -11,9 +11,8 @@
     'MERCURIAL',
 ]
 
-OPTIONS_TO_ADD = ['--no-site-packages','--clear', '--type-install=local', "--unzip-setuptools"]
+OPTIONS_TO_ADD = ['clear', 'type_install=local', "unzip_setuptools", "use_distribute"]
 
 def generate_install_methods(path_locations, src_base, Logger, call_subprocess):    
-    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS)
+    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS, OPTIONS_TO_ADD)
 
-add_options = lambda : lib_add_options(OPTIONS_TO_ADD)
--- a/virtualenv/web/create_python_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/web/create_python_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -35,9 +35,8 @@
 EXTRA_TEXT  = "import sys\n"
 EXTRA_TEXT += "sys.path.append('%s')\n" % (lib_path)
 EXTRA_TEXT += "sys.path.append('%s')\n" % (os.path.abspath(os.path.join(here,"res")).replace("\\","/"))
-EXTRA_TEXT += "from res_create_env import generate_install_methods, add_options\n"
+EXTRA_TEXT += "from res_create_env import generate_install_methods\n"
 EXTRA_TEXT += "adjust_options, extend_parser, after_install = generate_install_methods(path_locations, '%s', Logger, call_subprocess)\n" % (src_base)
-EXTRA_TEXT += "add_options()"
 
 def main():
     python_version = ".".join(map(str,sys.version_info[0:2]))
--- a/virtualenv/web/res/res_create_env.py	Thu Jun 14 15:03:46 2012 +0200
+++ b/virtualenv/web/res/res_create_env.py	Thu Jun 14 18:26:25 2012 +0200
@@ -1,6 +1,6 @@
 import platform
 
-from lib_create_env import lib_generate_install_methods, lib_add_options
+from lib_create_env import lib_generate_install_methods
 
 system_str = platform.system()
 
@@ -29,11 +29,7 @@
 if system_str == 'Windows':
     INSTALLS.insert(0, 'JCC')
 
-OPTIONS_TO_ADD = ['--no-site-packages','--clear', '--type-install=local']
-if system_str == "Linux":
-    OPTIONS_TO_ADD.append("--unzip-setuptools")
+OPTIONS_TO_ADD = ['clear', 'type_install=local', 'unzip_setuptools', 'use_distribute']
 
 def generate_install_methods(path_locations, src_base, Logger, call_subprocess):    
-    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS)
-
-add_options = lambda : lib_add_options(OPTIONS_TO_ADD)
+    return lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, INSTALLS, OPTIONS_TO_ADD)