def main(args): parser = argparse.ArgumentParser() parser.add_argument( '--deps_file', action='append', help='Path to deps.pyl file (default: bootstrap/deps.pyl)') parser.add_argument( 'to_build', nargs='*', help='Names of packages to build. Defaults to all packages.') opts = parser.parse_args(args) if 'Ubuntu' in platform_tag() and ROOT.startswith('/usr/local/'): print >> sys.stderr, "\n".join([ "Due to a bug in Ubuntu's python distribution, build_deps.py does not", "work when run from under a path beginning with /usr/local/. Please ", "clone to a different path, and try again.", "", "Bug: https://github.com/pypa/virtualenv/issues/118" ]) return 1 deps_files = opts.deps_file or [os.path.join(ROOT, 'deps.pyl')] to_build = set(opts.to_build) build_env = os.path.join(ROOT, 'BUILD_ENV') print 'Parsing deps.pyl' deps = merge_deps(deps_files) bootstrap.activate_env(build_env, {'wheel': deps.pop('wheel')}) print 'Finding missing deps' missing_deps = {} for name, entry in deps.iteritems(): if to_build and name not in to_build: continue try: bootstrap.get_links({name: entry}) except bootstrap.NoWheelException: missing_deps[name] = entry if not missing_deps: print 'Nothing to process' return print 'Processing deps:' print_deps(missing_deps) for name, options in missing_deps.iteritems(): clear_wheelhouse() # TODO(iannucci): skip entries which already exist in gs if 'repo' in options and 'rev' in options: process_git(name, options['rev'], options['build'], options.get('build_options', ()), options['repo']) elif 'gs' in options: process_gs(name, options['gs'], options['build'], options.get('build_options', ())) else: raise Exception('Invalid options %r for %r' % (options, name)) push_wheelhouse()
def activate_env(env, deps, quiet=False): if hasattr(sys, 'real_prefix'): LOGGER.error('Already activated environment!') return if not quiet: print 'Activating environment: %r' % env assert isinstance(deps, dict) manifest_path = os.path.join(env, 'manifest.pyl') cur_deps = read_deps(manifest_path) if cur_deps != deps: if not quiet: print ' Removing old environment: %r' % cur_deps shutil.rmtree(env, ignore_errors=True) cur_deps = None if cur_deps is None: check_pydistutils() if not quiet: print ' Building new environment' # Add in bundled virtualenv lib sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'virtualenv')) import virtualenv # pylint: disable=F0401 virtualenv.create_environment( env, search_dirs=virtualenv.file_search_dirs()) if not quiet: print ' Activating environment' # Ensure hermeticity during activation. os.environ.pop('PYTHONPATH', None) bin_dir = 'Scripts' if sys.platform.startswith('win') else 'bin' activate_this = os.path.join(env, bin_dir, 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) if cur_deps is None: if not quiet: print ' Installing deps' print_deps(deps, indent=2, with_implicit=False) install(deps) virtualenv.make_environment_relocatable(env) with open(manifest_path, 'wb') as f: f.write(repr(deps) + '\n') # Create bin\python.bat on Windows to unify path where Python is found. if sys.platform.startswith('win'): bin_path = os.path.join(env, 'bin') if not os.path.isdir(bin_path): os.makedirs(bin_path) python_bat_path = os.path.join(bin_path, 'python.bat') if not os.path.isfile(python_bat_path): with open(python_bat_path, 'w') as python_bat_file: python_bat_file.write(PYTHON_BAT_WIN) if not quiet: print 'Done creating environment'
def activate_env(env, manifest, quiet=False): if not quiet: print 'Activating environment: %r' % env assert isinstance(manifest, dict) manifest_path = os.path.join(env, 'manifest.pyl') cur_manifest = read_python_literal(manifest_path) if cur_manifest != manifest: if not quiet: print ' Removing old environment: %r' % cur_manifest shutil.rmtree(env, ignore_errors=True) cur_manifest = None if cur_manifest is None: check_pydistutils() if not quiet: print ' Building new environment' # Add in bundled virtualenv lib sys.path.insert( 0, os.path.join(os.path.dirname(__file__), 'virtualenv-ext')) import virtualenv # pylint: disable=F0401 virtualenv.create_environment( env, search_dirs=virtualenv.file_search_dirs()) if not quiet: print ' Activating environment' # Ensure hermeticity during activation. os.environ.pop('PYTHONPATH', None) bin_dir = 'Scripts' if sys.platform.startswith('win') else 'bin' activate_this = os.path.join(env, bin_dir, 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) if cur_manifest is None: deps = manifest.get('deps', {}) if not quiet: print ' Installing deps' print_deps(deps, indent=2, with_implicit=False) install(deps) virtualenv.make_environment_relocatable(env) # Write the original deps (including metadata) as manifest. with open(manifest_path, 'wb') as f: f.write(repr(manifest) + '\n') # Create bin\python.bat on Windows to unify path where Python is found. if sys.platform.startswith('win'): bin_path = os.path.join(env, 'bin') if not os.path.isdir(bin_path): os.makedirs(bin_path) python_bat_path = os.path.join(bin_path, 'python.bat') if not os.path.isfile(python_bat_path): with open(python_bat_path, 'w') as python_bat_file: python_bat_file.write(PYTHON_BAT_WIN) if not quiet: print 'Done creating environment'
def activate_env(env, deps, quiet=False, run_within_virtualenv=False): if hasattr(sys, 'real_prefix'): if not run_within_virtualenv: LOGGER.error('Already activated environment!') return LOGGER.info('Discarding current VirtualEnv (--run-within-virtualenv)') sys.prefix = sys.real_prefix if not quiet: print 'Activating environment: %r' % env assert isinstance(deps, dict) manifest_path = os.path.join(env, 'manifest.pyl') cur_deps = read_deps(manifest_path) if cur_deps != deps: if not quiet: print ' Removing old environment: %r' % cur_deps shutil.rmtree(env, ignore_errors=True) cur_deps = None if cur_deps is None: check_pydistutils() if not quiet: print ' Building new environment' # Add in bundled virtualenv lib sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'virtualenv')) import virtualenv # pylint: disable=F0401 virtualenv.create_environment( env, search_dirs=virtualenv.file_search_dirs()) # Hack: On windows orig-prefix.txt contains the hardcoded path # "E:\b\depot_tools\python276_bin", but some systems have depot_tools # installed on C:\ instead, so fiddle site.py to try loading it from there # as well. if sys.platform.startswith('win'): site_py_path = os.path.join(env, 'Lib\\site.py') with open(site_py_path) as fh: site_py = fh.read() m = re.search(r'( +)sys\.real_prefix = .*', site_py) replacement = ( '%(indent)sif (sys.real_prefix.startswith("E:\\\\") and\n' '%(indent)s not os.path.exists(sys.real_prefix)):\n' '%(indent)s cand = "C:\\\\setup" + sys.real_prefix[4:]\n' '%(indent)s if os.path.exists(cand):\n' '%(indent)s sys.real_prefix = cand\n' '%(indent)s else:\n' '%(indent)s sys.real_prefix = "C" + sys.real_prefix' '[1:]\n' % { 'indent': m.group(1) }) site_py = site_py[:m. end(0)] + '\n' + replacement + site_py[m.end(0):] with open(site_py_path, 'w') as fh: fh.write(site_py) if not quiet: print ' Activating environment' # Ensure hermeticity during activation. os.environ.pop('PYTHONPATH', None) bin_dir = 'Scripts' if sys.platform.startswith('win') else 'bin' activate_this = os.path.join(env, bin_dir, 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) if cur_deps is None: if not quiet: print ' Installing deps' print_deps(deps, indent=2, with_implicit=False) install(deps) virtualenv.make_environment_relocatable(env) with open(manifest_path, 'wb') as f: f.write(repr(deps) + '\n') # Create bin\python.bat on Windows to unify path where Python is found. if sys.platform.startswith('win'): bin_path = os.path.join(env, 'bin') if not os.path.isdir(bin_path): os.makedirs(bin_path) python_bat_path = os.path.join(bin_path, 'python.bat') if not os.path.isfile(python_bat_path): with open(python_bat_path, 'w') as python_bat_file: python_bat_file.write(PYTHON_BAT_WIN) if not quiet: print 'Done creating environment'