def main(): if len(sys.argv) == 2: print virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=sys.argv[1]) else: print >>sys.stderr, "Specify the python version you want to use as"\ " first parameter (eg. 2.4)"
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.5') if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == text: print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close() text = virtualenv.create_bootstrap_script(HOMEDIR_TEXT, python_version='2.5') if os.path.exists(gae_script_name): f = open(gae_script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % gae_script_name if cur_text == text: print 'No update' else: print 'Script changed; updating...' f = open(gae_script_name, 'w') f.write(text) f.close()
def make_virtualenv(packages=[]): additional = textwrap.dedent(""" import sys, os, subprocess def after_install(options, home_dir): if sys.platform == 'win32': bin = 'Scripts' else: bin = 'bin' """) for package in packages: if hasattr(package, '__iter__'): additional += textwrap.dedent(""" # subprocess.call([join(home_dir, bin, 'easy_install'), '-f', '%s', '%s'], stdout=subprocess.PIPE) """ % (package[1], package[0])) else: additional += textwrap.dedent(""" # subprocess.call([join(home_dir, bin, 'easy_install'), '%s'], stdout=subprocess.PIPE) """ % package) output = virtualenv.create_bootstrap_script(additional) f = open(VENV_BOOTSTRAP_SCRIPT, 'w').write(output) subprocess.call(['python', VENV_BOOTSTRAP_SCRIPT, VENV_PATH])
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=None, system_site_packages=None, unzip_setuptools=False, distribute=None, index_url=None, no_index=False, find_links=None, prefer_easy_install=False): # configure package installation template install_cmd_options = [] if index_url: install_cmd_options.extend(['--index-url', index_url]) if no_index: install_cmd_options.extend(['--no-index']) if find_links: for link in find_links: install_cmd_options.extend( ['--find-links', link]) install_cmd_tmpl = (_easy_install_tmpl if prefer_easy_install else _pip_then_easy_install_tmpl) confd_install_cmd_tmpl = (install_cmd_tmpl % {'bin_dir_var': 'bin_dir', 'cmd_options': install_cmd_options}) # make copy to local scope to add paver to packages to install packages_to_install = packages_to_install[:] if install_paver: packages_to_install.insert(0, 'paver==%s' % setup_meta['version']) install_cmd = confd_install_cmd_tmpl % {'packages': packages_to_install} options = "" # if deprecated 'no_site_packages' was specified and 'system_site_packages' # wasn't, set it from that value if system_site_packages is None and no_site_packages is not None: system_site_packages = not no_site_packages if system_site_packages is not None: options += (" options.system_site_packages = %s\n" % bool(system_site_packages)) if unzip_setuptools: options += " options.unzip_setuptools = True\n" if distribute is not None: options += " options.use_distribute = %s\n" % bool(distribute) options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, install_cmd) if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.7') print 'Updating %s' % virtualenv_path # 把配置写回到virtualenv_path的默认配置文件中 with open(virtualenv_path, 'w') as f: f.write(text)
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=None, system_site_packages=None, unzip_setuptools=False, distribute=None, index_url=None, find_links=None): # configure easy install template easy_install_options = [] if index_url: easy_install_options.extend(["--index-url", index_url]) if find_links: easy_install_options.extend( ["--find-links", " ".join(find_links)]) easy_install_options = ( easy_install_options and "'%s', " % "', '".join(easy_install_options) or '') confd_easy_install_tmpl = (_easy_install_tmpl % ('bin_dir', easy_install_options)) if install_paver: paver_install = (confd_easy_install_tmpl % ('paver==%s' % setup_meta['version'])) else: paver_install = "" options = "" # if deprecated 'no_site_packages' was specified and 'system_site_packages' # wasn't, set it from that value if system_site_packages is None and no_site_packages is not None: system_site_packages = not no_site_packages if system_site_packages is not None: options += (" options.system_site_packages = %s\n" % bool(system_site_packages)) if unzip_setuptools: options += " options.unzip_setuptools = True\n" if distribute is not None: options += " options.use_distribute = %s\n" % bool(distribute) options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += confd_easy_install_tmpl % package if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def main(): '''runs create_boostrap_script functionality and spits out new virtualenv script''' bootstrap_script = virtualenv.create_bootstrap_script( EXTRA_TEXT, python_version=CONFIG.get('environment', 'python_version') ) result_script = CONFIG.get('bootstrap', 'result_script_name') result_path = CONFIG.get('bootstrap', 'result_path') result_abspath = None if '..' in result_path: pb.local.cwd.chdir(CURRENT_DIR) result_abspath = pb.path.local.LocalPath(result_path) else: result_abspath = pb.local.path(result_path) result_abspath.mkdir() bootstrap_path = result_abspath / result_script #Plumbum maps __div__ to join() result_abspath = pb.path.local.LocalPath(bootstrap_path) current_text = '' if result_abspath.is_file(): print('--PULLING EXISTING BOOTSTRAP SCRIPT--') with open(result_abspath, 'r') as filehandle: current_text = filehandle.read() else: print('--NO BOOTSTRAP FOUND--') if current_text == bootstrap_script: print('--NO UPDATE BOOTSTRAP SCRIPT--') else: print('--UPDATING BOOTSTRAP SCRIPT--') with open(result_abspath, 'w') as filehandle: filehandle.write(bootstrap_script)
def main(): '''runs create_boostrap_script functionality and spits out new virtualenv script''' bootstrap_script = virtualenv.create_bootstrap_script( EXTRA_TEXT, python_version=CONFIG.get('environment', 'python_version')) result_script = CONFIG.get('bootstrap', 'result_script_name') result_path = CONFIG.get('bootstrap', 'result_path') result_abspath = None if '..' in result_path: pb.local.cwd.chdir(CURRENT_DIR) result_abspath = pb.path.local.LocalPath(result_path) else: result_abspath = pb.local.path(result_path) result_abspath.mkdir() bootstrap_path = result_abspath / result_script #Plumbum maps __div__ to join() result_abspath = pb.path.local.LocalPath(bootstrap_path) current_text = '' if result_abspath.is_file(): print('--PULLING EXISTING BOOTSTRAP SCRIPT--') with open(result_abspath, 'r') as filehandle: current_text = filehandle.read() else: print('--NO BOOTSTRAP FOUND--') if current_text == bootstrap_script: print('--NO UPDATE BOOTSTRAP SCRIPT--') else: print('--UPDATING BOOTSTRAP SCRIPT--') with open(result_abspath, 'w') as filehandle: filehandle.write(bootstrap_script)
def main(): parser = OptionParser() parser.add_option('--prefix', dest='prefix', default=here, help='prefix for the location of the resulting script') text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.4') (options, args) = parser.parse_args() script_name = os.path.join(options.prefix, 'lavaflow-bootstrap.py') if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == 'text': print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def create_bootstrap_script(): content = "" content += requirements_definitions() info = "source bootstrap script: %r" % BOOTSTRAP_SOURCE print "read", info content += "\n\n# %s\n" % info f = file(BOOTSTRAP_SOURCE, "r") content += f.read() f.close() print "Create/Update %r" % BOOTSTRAP_SCRIPT output = virtualenv.create_bootstrap_script(content) # Add info lines output_lines = output.splitlines() generator_filepath = "/PyLucid_env/" + __file__.split("/PyLucid_env/")[1] output_lines.insert(2, "## Generated with %r" % generator_filepath) output_lines.insert(2, "## using: %r v%s" % (virtualenv.__file__, virtualenv.virtualenv_version)) output_lines.insert(2, "## python v%s" % sys.version.replace("\n", " ")) output = "\n".join(output_lines) #print output f = file(BOOTSTRAP_SCRIPT, 'w') f.write(output) f.close()
def audit(ver): """Checks that the given version is installable from PyPI in a new virtualenv.""" bootstrap_text = ''' def after_install(options, home_dir): for module_name in [{module_names}]: subprocess.check_output([ os.path.join(home_dir, 'bin', 'pip'), 'install', '{{module}}=={version}'.format( module=module_name ) ]) '''.format( module_names=', '.join([ '\'{module_name}\''.format(module_name=module_name) for module_name in MODULE_NAMES + LIBRARY_MODULES ]), version=ver, ) bootstrap_script = virtualenv.create_bootstrap_script(bootstrap_text) with tempfile.TemporaryDirectory() as venv_dir: with tempfile.NamedTemporaryFile('w') as bootstrap_script_file: bootstrap_script_file.write(bootstrap_script) args = ['python', bootstrap_script_file.name, venv_dir] click.echo(subprocess.check_output(args).decode('utf-8'))
def create_bootstrap_script(): content = "" content += requirements_definitions() info = "source bootstrap script: %r" % BOOTSTRAP_SOURCE print "read", info content += "\n\n# %s\n" % info f = file(BOOTSTRAP_SOURCE, "r") content += f.read() f.close() print "Create/Update %r" % BOOTSTRAP_SCRIPT output = virtualenv.create_bootstrap_script(content) # Add info lines output_lines = output.splitlines() output_lines.insert(2, "## Generate with %r" % __file__) output_lines.insert(2, "## using: %r v%s" % (virtualenv.__file__, virtualenv.virtualenv_version)) output_lines.insert(2, "## python v%s" % sys.version.replace("\n", " ")) output = "\n".join(output_lines) #print output f = file(BOOTSTRAP_SCRIPT, 'w') f.write(output) f.close()
def make_devkit(options): import virtualenv from urlgrabber.grabber import urlgrab from urlgrabber.progress import text_progress_meter (path("package") / "devkit" / "share").makedirs() pip_bundle("package/devkit/share/geonode-core.pybundle -r shared/devkit.requirements") script = virtualenv.create_bootstrap_script(""" import os, subprocess, zipfile def after_install(options, home_dir): if sys.platform == 'win32': bin = 'Scripts' else: bin = 'bin' installer_base = os.path.abspath(os.path.dirname(__file__)) def pip(*args): subprocess.call([os.path.join(home_dir, bin, "pip")] + list(args)) pip("install", os.path.join(installer_base, "share", "geonode-core.pybundle")) setup_jetty(source=os.path.join(installer_base, "share"), dest=os.path.join(home_dir, "share")) def setup_jetty(source, dest): jetty_zip = os.path.join(source, "jetty-distribution-7.0.2.v20100331.zip") jetty_dir = os.path.join(dest, "jetty-distribution-7.0.2.v20100331") zipfile.ZipFile(jetty_zip).extractall(dest) shutil.rmtree(os.path.join(jetty_dir, "contexts")) shutil.rmtree(os.path.join(jetty_dir, "webapps")) os.mkdir(os.path.join(jetty_dir, "contexts")) os.mkdir(os.path.join(jetty_dir, "webapps")) deployments = [ ('geoserver', 'geoserver-geonode-dev.war'), ('geonetwork', 'geonetwork.war'), ('media', 'geonode-client.zip') ] for context, archive in deployments: src = os.path.join(source, archive) dst = os.path.join(jetty_dir, "webapps", context) zipfile.ZipFile(src).extractall(dst) """) open((path("package")/"devkit"/"go-geonode.py"), 'w').write(script) urlgrab( "http://download.eclipse.org/jetty/7.0.2.v20100331/dist/jetty-distribution-7.0.2.v20100331.zip", "package/devkit/share/jetty-distribution-7.0.2.v20100331.zip", progress_obj = text_progress_meter() ) urlgrab( "http://pypi.python.org/packages/source/p/pip/pip-0.7.1.tar.gz", "package/devkit/share/pip-0.7.1.tar.gz", progress_obj = text_progress_meter() ) geoserver_target.copy("package/devkit/share") geonetwork_target.copy("package/devkit/share") geonode_client_target().copy("package/devkit/share")
def main(argv): with open('bootstrap.py') as f: output = create_bootstrap_script(f.read()) with open(INSTALL_SCRIPT, 'w') as f: f.write(output) os.chmod(INSTALL_SCRIPT, 0755) return 0
def generate(filename, version): path = version if "==" in version: path = version[: version.find("==")] output = virtualenv.create_bootstrap_script(textwrap.dedent(after_install % (path, version))) fp = open(filename, "w") fp.write(output) fp.close()
def generate(filename, version): path = version if '==' in version: path = version[:version.find('==')] output = virtualenv.create_bootstrap_script( textwrap.dedent(after_install % (path, version))) fp = open(filename, 'w') fp.write(output) fp.close()
def make_devkit(options): import virtualenv from urllib import urlretrieve (path("package") / "devkit" / "share").makedirs() pip_bundle( "package/devkit/share/geonode-core.pybundle -r shared/devkit.requirements" ) script = virtualenv.create_bootstrap_script(""" import os, subprocess, zipfile def after_install(options, home_dir): if sys.platform == 'win32': bin = 'Scripts' else: bin = 'bin' installer_base = os.path.abspath(os.path.dirname(__file__)) def pip(*args): subprocess.call([os.path.join(home_dir, bin, "pip")] + list(args)) pip("install", os.path.join(installer_base, "share", "geonode-core.pybundle")) setup_jetty(source=os.path.join(installer_base, "share"), dest=os.path.join(home_dir, "share")) def setup_jetty(source, dest): jetty_zip = os.path.join(source, "jetty-distribution-7.0.2.v20100331.zip") jetty_dir = os.path.join(dest, "jetty-distribution-7.0.2.v20100331") zipfile.ZipFile(jetty_zip).extractall(dest) shutil.rmtree(os.path.join(jetty_dir, "contexts")) shutil.rmtree(os.path.join(jetty_dir, "webapps")) os.mkdir(os.path.join(jetty_dir, "contexts")) os.mkdir(os.path.join(jetty_dir, "webapps")) deployments = [ ('geoserver', 'geoserver-geonode-dev.war'), ('geonetwork', 'geonetwork.war'), ('media', 'geonode-client.zip') ] for context, archive in deployments: src = os.path.join(source, archive) dst = os.path.join(jetty_dir, "webapps", context) zipfile.ZipFile(src).extractall(dst) """) open((path("package") / "devkit" / "go-geonode.py"), 'w').write(script) urlretrieve( "http://download.eclipse.org/jetty/7.0.2.v20100331/dist/jetty-distribution-7.0.2.v20100331.zip", "package/devkit/share/jetty-distribution-7.0.2.v20100331.zip") urlretrieve( "http://pypi.python.org/packages/source/p/pip/pip-0.7.1.tar.gz", "package/devkit/share/pip-0.7.1.tar.gz") geoserver_target.copy("package/devkit/share") geonetwork_target.copy("package/devkit/share") geonode_client_target().copy("package/devkit/share")
def create_bootstrap(self, dest): extra_text = (TERRARIUM_BOOTSTRAP_EXTRA_TEXT.format( requirements=self.requirements, virtualenv_log_level=self.args.virtualenv_log_level, pip_log_level=self.args.pip_log_level, )) output = create_bootstrap_script(extra_text) with open(dest, 'w') as f: f.write(output)
def create_bootstrap(self, dest): extra_text = (TERRARIUM_BOOTSTRAP_EXTRA_TEXT % { 'REQUIREMENTS': self.requirements, 'VENV_LOGGING': self.args.virtualenv_log_level, 'PIP_LOGGING': self.args.pip_log_level, }) output = create_bootstrap_script(extra_text) with open(dest, 'w') as f: f.write(output)
def create_bootstrap(self, dest): extra_text = ( TERRARIUM_BOOTSTRAP_EXTRA_TEXT % { 'REQUIREMENTS': self.requirements, 'LOGGING': logger.level, } ) output = create_bootstrap_script(extra_text) with open(dest, 'w') as f: f.write(output)
def main(args): bootstrapdir = '.' if len(args) > 1: if os.path.exists(args[1]): bootstrapdir = args[1] print 'Creating bootstrap file in: "'+bootstrapdir+'"' else: print 'Directory "'+args[1]+'" does not exist. Placing bootstrap in "'+os.path.abspath(bootstrapdir)+'" instead.' output = virtualenv.create_bootstrap_script(textwrap.dedent("""""")) f = open(bootstrapdir+'/bootstrap.py', 'w').write(output)
def create_bootstrap(self, dest): extra_text = ( TERRARIUM_BOOTSTRAP_EXTRA_TEXT.format( requirements=self.requirements, virtualenv_log_level=self.args.virtualenv_log_level, pip_log_level=self.args.pip_log_level, ) ) output = create_bootstrap_script(extra_text) with open(dest, 'w') as f: f.write(output)
def create_bootstrap(self, dest): extra_text = ( TERRARIUM_BOOTSTRAP_EXTRA_TEXT % { 'REQUIREMENTS': self.requirements, 'VENV_LOGGING': self.args.virtualenv_log_level, 'PIP_LOGGING': self.args.pip_log_level, } ) output = create_bootstrap_script(extra_text) with open(dest, 'w') as f: f.write(output)
def main(args): bootstrapdir = '.' if len(args) > 1: if os.path.exists(args[1]): bootstrapdir = args[1] print 'Creating bootstrap file in: "' + bootstrapdir + '"' else: print 'Directory "' + args[ 1] + '" does not exist. Placing bootstrap in "' + os.path.abspath( bootstrapdir) + '" instead.' output = virtualenv.create_bootstrap_script(textwrap.dedent("""""")) f = open(bootstrapdir + '/bootstrap.py', 'w').write(output)
def create_virtualenv_bootstrap_script(script_path, after_install_script_file): import virtualenv indented_customize_script = "" if after_install_script_file: customize_script_lines = open(after_install_script_file, "rb").readlines() indented_customize_script = "\n # customize process\n" + \ "\n".join([" " + line.rstrip() for line in customize_script_lines]).rstrip() + \ "\n" script = get_default_after_install_script() + indented_customize_script with open(script_path, "wb") as fp: fp.write(virtualenv.create_bootstrap_script(script))
def append_to_zip(self, bundle_path): """ Populate the bundle with necessary bootstrapping python """ with zipfile.ZipFile(bundle_path, mode='a') as bundle: for mod_name, spec in self.modules: mod = resolve(spec) if mod is not None: bundle.writestr(mod_name, inspect.getsource(mod)) else: #@@ needs negative test logger.error("%s does not return a module", spec) bundle.writestr('bootstrap.py', virtualenv.create_bootstrap_script(self.extra_text))
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=False, unzip_setuptools=False): if install_paver: paver_install = (_easy_install_template % ('bin_dir', 'paver==%s' % setup_meta['version'])) else: paver_install = "" options = "" if no_site_packages: options = " options.no_site_packages = True" if unzip_setuptools: if options: options += "\n" options += " options.unzip_setuptools = True" if options: options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += _easy_install_template % ('bin_dir', package) if paver_command_line: command_list = [] command_list.extend(paver_command_line.split(" ")) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr( command_list)[1:] extra_text += more_text bootstrap_contents = virtualenv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % (fn), write_script)
def bootstrap(dependencies, dir): extra = textwrap.dedent(""" import os, subprocess import urllib from tempfile import mkdtemp def extend_parser(optparse_parser): pass def adjust_options(options, args): pass def after_install(options, home_dir): easy_install = join(home_dir, 'bin', 'easy_install') """) for package in sorted(dependencies.keys()): if package == 'protobuf': continue extra += " if subprocess.call([easy_install, '%s==%s']) != 0:\n" % ( package, dependencies[package]) extra += " subprocess.call([easy_install, '%s'])\n" % package extra += " subprocess.call([easy_install, '.'], cwd='%s')\n" % ( os.path.join(dir, 'bootstrap_ms')) extra += " subprocess.call([easy_install, '.'], cwd='%s')\n" % ( os.path.join(dir, 'bootstrap_Sybase')) print virtualenv.create_bootstrap_script(extra)
def generate(filename, version): # what's commented out below comes from go-pylons.py #path = version #if '==' in version: # path = version[:version.find('==')] #output = virtualenv.create_bootstrap_script( # textwrap.dedent(after_install % (path, version))) output = virtualenv.create_bootstrap_script( textwrap.dedent(after_install % version)) fp = open(filename, 'w') fp.write(output) fp.close()
def create_bigjob_bootstrap_script(): output = virtualenv.create_bootstrap_script( textwrap.dedent( """ import os, subprocess def after_install(options, home_dir): etc = join(home_dir, 'etc') if not os.path.exists(etc): os.makedirs(etc) subprocess.call([join(home_dir, 'bin', 'easy_install'), 'bigjob']) """ ) ) return output
def append_to_zip(self, bundle_path): """ Populate the bundle with necessary bootstrapping python """ with zipfile.ZipFile(bundle_path, mode='a') as bundle: for mod_name, spec in self.modules: mod = resolve(spec) if mod is not None: bundle.writestr(mod_name, inspect.getsource(mod)) else: #@@ needs negative test logger.error("%s does not return a module", spec) bundle.writestr( 'bootstrap.py', virtualenv.create_bootstrap_script(self.extra_text))
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version="2.5") if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = "" print "Updating %s" % script_name if cur_text == "text": print "No update" else: print "Script changed; updating..." f = open(script_name, "w") f.write(text) f.close()
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version='2.4') if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == 'text': print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT) if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == 'text': print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def install_test(installer, name): root = path(tempfile.mkdtemp(prefix=name + '_')) # info( 'root='+ root) script = root / 'start_virtualenv' txt = """ def after_install(options, home_dir): assert not os.system('{installer} {name}') """.format( name=name, installer=root / 'testenv' / 'bin' / installer, ) script_text = virtualenv.create_bootstrap_script(textwrap.dedent(txt)) script.write_text(script_text) script.chmod(0755) sh('./start_virtualenv testenv --no-site-packages', cwd=root)
def main(): python_version = ".".join(map(str,sys.version_info[0:2])) text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == 'text': print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def main(): text = virtualenv.create_bootstrap_script(extra_text) if os.path.exists(script_name): print "bootstrap script already exists..." f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == text: print 'bootstrap function still the same, no update...' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def genBootstrap(options): """ Get the bootstrap file as a string """ devDir = os.path.abspath(RESOURCE('../dist')) dev = '"-HNone", "-f{devDir}",'.format(devDir=devDir) if options['develop'] else '' tpl = cleandoc(""" import subprocess def after_install(options, home_dir): args = [join(home_dir, 'bin', 'easy_install'), {developmentMode} {options[selectedDependencies]}] subprocess.call(args) """).format(options=options, developmentMode=dev) output = virtualenv.create_bootstrap_script(tpl) return output
def _create_bootstrap(script_name, packages_to_install, paver_command_line, install_paver=True, more_text="", dest_dir='.', no_site_packages=False, unzip_setuptools=False): if install_paver: paver_install = (_easy_install_tmpl % ('bin_dir', 'paver==%s' % setup_meta['version'])) else: paver_install = "" options = """ options.no_site_packages = %s if hasattr(options,"system_site_packages"): options.system_site_packages = %s """%(bool(no_site_packages),not bool(no_site_packages)) if unzip_setuptools: if options: options += "\n" options += " options.unzip_setuptools = True" if options: options += "\n" extra_text = """def adjust_options(options, args): args[:] = ['%s'] %s def after_install(options, home_dir): if sys.platform == 'win32': bin_dir = join(home_dir, 'Scripts') else: bin_dir = join(home_dir, 'bin') %s""" % (dest_dir, options, paver_install) for package in packages_to_install: extra_text += _easy_install_tmpl % ('bin_dir', package) if paver_command_line: command_list = list(paver_command_line.split()) extra_text += " subprocess.call([join(bin_dir, 'paver'),%s)" % repr(command_list)[1:] extra_text += more_text bootstrap_contents = venv.create_bootstrap_script(extra_text) fn = script_name debug("Bootstrap script extra text: " + extra_text) def write_script(): open(fn, "w").write(bootstrap_contents) dry("Write bootstrap script %s" % fn, write_script)
def test_bootstrap(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) extra_code = inspect.getsource(bootstrap) extra_code = textwrap.dedent(extra_code[extra_code.index("\n") + 1:]) output = virtualenv.create_bootstrap_script(extra_code) assert extra_code in output if six.PY2: output = output.decode() write_at = tmp_path / "blog-bootstrap.py" write_at.write_text(output) try: monkeypatch.chdir(tmp_path) cmd = [ sys.executable, str(write_at), "--no-download", "--no-pip", "--no-wheel", "--no-setuptools", "-ccc", "-qqq", "env", ] raw = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT) out = re.sub(r"pydev debugger: process \d+ is connecting\n\n", "", raw, re.M).strip().split("\n") _, _, _, bin_dir = virtualenv.path_locations(str(tmp_path / "env")) exe = os.path.realpath( os.path.join( bin_dir, "{}{}".format(virtualenv.EXPECTED_EXE, ".exe" if virtualenv.IS_WIN else ""))) assert out == [ "startup", "extend parser with count", "adjust options", "after install env with options 4", "exe at {}".format(exe), ] except subprocess.CalledProcessError as exception: assert not exception.returncode, exception.output
def main(): usage = "usage: %prog [options]" description = "Creates a Pinax boot script and uses version specific installer templates if given a release version." parser = OptionParser(usage, description=description) parser.add_option("-r", "--release", metavar='VERSION', dest='release', default=None, help='Release version of Pinax to bootstrap') parser.add_option("-v", "--verbose", action="store_true", dest="verbose") parser.add_option("-q", "--quiet", action="store_false", dest="verbose") (options, args) = parser.parse_args() here = dirname(abspath(__file__)) script_name = join(here, 'pinax-boot.py') installer = join(here, '_installer.py') # _installer.py if options.release: release_installer = join(here, 'installers', '%s.py' % options.release) # installers/0.7b1.py if exists(release_installer): installer = release_installer script_name = join(here, 'pinax-boot-%s.py' % options.release) # pinax-boot-0.7b1.py print "Using as template: %s" % installer extra_text = open(installer).read() text = virtualenv.create_bootstrap_script(extra_text) if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == text: print 'No update' else: if options.verbose: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def audit(version): # pylint: disable=redefined-outer-name """Checks that the given version is installable from PyPI in a new virtualenv.""" dmp = DagsterModulePublisher() for module in dmp.all_publishable_modules: res = requests.get( urllib.parse.urlunparse( ("https", "pypi.org", "/".join(["pypi", module.name, "json"]), None, None, None) ) ) module_json = res.json() assert ( version in module_json["releases"] ), "Version not available for module {module_name}, expected {expected}, released version is {received}".format( module_name=module, expected=version, received=module_json["info"]["version"] ) bootstrap_text = """ def after_install(options, home_dir): for module_name in [{module_names}]: subprocess.check_output([ os.path.join(home_dir, 'bin', 'pip'), 'install', '{{module}}=={version}'.format( module=module_name ) ]) """.format( module_names=", ".join( [ "'{module_name}'".format(module_name=module.name) for module in dmp.all_publishable_modules ] ), version=version, ) bootstrap_script = virtualenv.create_bootstrap_script(bootstrap_text) with tempfile.TemporaryDirectory() as venv_dir: with tempfile.NamedTemporaryFile("w") as bootstrap_script_file: bootstrap_script_file.write(bootstrap_script) args = [sys.executable, bootstrap_script_file.name, venv_dir] click.echo(subprocess.check_output(args).decode("utf-8"))
def audit(version): # pylint: disable=redefined-outer-name '''Checks that the given version is installable from PyPI in a new virtualenv.''' dmp = DagsterModulePublisher() for module in dmp.all_publishable_modules: res = requests.get( urllib.parse.urlunparse( ('https', 'pypi.org', '/'.join(['pypi', module.name, 'json']), None, None, None) ) ) module_json = res.json() assert ( version in module_json['releases'] ), 'Version not available for module {module_name}, expected {expected}, released version is {received}'.format( module_name=module, expected=version, received=module_json['info']['version'] ) bootstrap_text = ''' def after_install(options, home_dir): for module_name in [{module_names}]: subprocess.check_output([ os.path.join(home_dir, 'bin', 'pip'), 'install', '{{module}}=={version}'.format( module=module_name ) ]) '''.format( module_names=', '.join( [ '\'{module_name}\''.format(module_name=module.name) for module in dmp.all_publishable_modules ] ), version=version, ) bootstrap_script = virtualenv.create_bootstrap_script(bootstrap_text) with tempfile.TemporaryDirectory() as venv_dir: with tempfile.NamedTemporaryFile('w') as bootstrap_script_file: bootstrap_script_file.write(bootstrap_script) args = ['python', bootstrap_script_file.name, venv_dir] click.echo(subprocess.check_output(args).decode('utf-8'))
def main(): usage = "usage: %prog [options]" description = "Creates a Pinax boot script and uses version specific installer templates if given a release version." parser = OptionParser(usage, description=description) parser.add_option("-r", "--release", metavar='VERSION', dest='release', default=None, help='Release version of Pinax to bootstrap') parser.add_option("-v", "--verbose", action="store_true", dest="verbose") parser.add_option("-q", "--quiet", action="store_false", dest="verbose") (options, args) = parser.parse_args() here = dirname(abspath(__file__)) script_name = join(here, 'pinax-boot.py') installer = join(here, '_installer.py') # _installer.py if options.release: release_installer = join(here, 'installers', '%s.py' % options.release) # installers/<version>.py if exists(release_installer): installer = release_installer script_name = join(here, 'pinax-boot-%s.py' % options.release) # pinax-boot-<version>.py print "Using as template: %s" % installer extra_text = open(installer).read() text = virtualenv.create_bootstrap_script(extra_text) if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == text: print 'No update' else: if options.verbose: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def test_bootstrap(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) extra_code = inspect.getsource(bootstrap) extra_code = textwrap.dedent(extra_code[extra_code.index("\n") + 1 :]) output = virtualenv.create_bootstrap_script(extra_code) assert extra_code in output if six.PY2: output = output.decode() write_at = tmp_path / "blog-bootstrap.py" write_at.write_text(output) try: monkeypatch.chdir(tmp_path) cmd = [ sys.executable, str(write_at), "--no-download", "--no-pip", "--no-wheel", "--no-setuptools", "-ccc", "-qqq", "env", ] raw = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT) out = re.sub(r"pydev debugger: process \d+ is connecting\n\n", "", raw, re.M).strip().split("\n") _, _, _, bin_dir = virtualenv.path_locations(str(tmp_path / "env")) exe = os.path.realpath( os.path.join(bin_dir, "{}{}".format(virtualenv.EXPECTED_EXE, ".exe" if virtualenv.IS_WIN else "")) ) assert out == [ "startup", "extend parser with count", "adjust options", "after install env with options 4", "exe at {}".format(exe), ] except subprocess.CalledProcessError as exception: assert not exception.returncode, exception.output
def createVirtualEnv(pythonExecutable, environmentName): virtualEnvOptions = ['--distribute', '--no-site-packages'] (fd, envCreateScriptFileName) = tempfile.mkstemp() try: with file(envCreateScriptFileName, 'w') as envCreateScript: with file('venv-hooks.py', 'r') as hookFile: output = virtualenv.create_bootstrap_script(hookFile.read()) envCreateScript.write(output) envCreateScript.flush() cmdArgs = [pythonExecutable, envCreateScriptFileName] cmdArgs += virtualEnvOptions cmdArgs.append(environmentName) ret = subprocess.call(cmdArgs) if ret: sys.exit(ret) finally: os.unlink(envCreateScriptFileName)
def main(): text = virtualenv.create_bootstrap_script(EXTRA_TEXT) base_dir = os.path.dirname(os.path.realpath(__file__)) bootstrap_script = os.path.join(base_dir, 'venv_bootstrap.py') if (os.path.exists(bootstrap_script) is True): with open(bootstrap_script) as f: if (f.read() == text): print("Bootstrap script %s is up-to-date with this generator, needn't to be updated." % bootstrap_script) return else: print('Updating bootstrap script %s ...' % bootstrap_script) else: print('Generating bootstrap script %s ...' % bootstrap_script) with open(bootstrap_script, 'w') as f: f.write(text) os.chmod(bootstrap_script, os.stat(bootstrap_script).st_mode | 0o111) print('Bootstrap script is generated as %s successfully.' % bootstrap_script)
def main(): installer = os.path.join(here, '_installer.py') # _installer.py print "Using as template: %s" % installer EXTRA_TEXT = open(installer).read() text = virtualenv.create_bootstrap_script(EXTRA_TEXT) if os.path.exists(script_name): f = open(script_name) cur_text = f.read() f.close() else: cur_text = '' print 'Updating %s' % script_name if cur_text == text: print 'No update' else: print 'Script changed; updating...' f = open(script_name, 'w') f.write(text) f.close()
def get_virtualenv_script(): """ returns the path of the virtualenv.py script that is installed in the system. if it doesn't exist returns None. """ try: import virtualenv except ImportError: raise ImportError('No module named virtualenv') pkg = pkg_resources.get_distribution('virtualenv') output = virtualenv.create_bootstrap_script('import os') fpath = os.path.join(os.path.abspath('/tmp'),'tmpvenv.py') f = open(fpath, 'w').write(output) # script_path = os.path.join( pkg.location, 'virtualenv.py') if os.path.isfile( fpath ): return fpath else: return None
def bdist_windows(options): """Build a Windows wheel of pygeoprocessing against an early numpy ABI.""" import virtualenv # paver provides paver.virtual.bootstrap(), but this does not afford the # degree of control that we want and need with installing needed packages. # We therefore make our own bootstrapping function calls here. install_string = """ import os, subprocess, platform def after_install(options, home_dir): if platform.system() == 'Windows': bindir = 'Scripts' else: bindir = 'bin' subprocess.check_output([os.path.join(home_dir, bindir, 'easy_install'), 'numpy==1.6.1']) """ output = virtualenv.create_bootstrap_script( textwrap.dedent(install_string)) open(options.bdist_windows.bootstrap_file, 'w').write(output) paver.easy.sh(('{python} {bootstrap} {envname} ' '--system-site-packages --clear').format( python=sys.executable, envname=options.bdist_windows.envname, bootstrap=options.bdist_windows.bootstrap_file)) @paver.virtual.virtualenv(options.bdist_windows.envname) def _build_files(): upload_string = '' if options.bdist_windows.upload: upload_string = 'upload' paver.easy.sh('python setup.py sdist bdist_wheel {upload}'.format( upload=upload_string)) _build_files()
# runepacts is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #=============================================================================== import virtualenv, textwrap output = virtualenv.create_bootstrap_script( textwrap.dedent(""" import os, subprocess, shlex def after_install(options, home_dir): etc = join(home_dir, 'etc') if not os.path.exists(etc): os.makedirs(etc) pip = join(home_dir,'bin','pip') cmd = "%s install -I pandas" % pip subprocess.call(shlex.split(cmd)) cmd = "%s install -I numexpr" % pip subprocess.call(shlex.split(cmd)) """)) f = open('virtualenv-varv.py', 'w').write(output)
file_list_dir = [] for root, dirnames, filenames in os.walk(PACKAGE): for filename in filenames: f = os.path.join(root, filename) file_list_dir.append(install_lib_path + '/' + f) return file_list_dir if __name__ == "__main__": print "** Configuring the environment" # Create a virtualenv and install packages. ## Create a bootstrap script to install additional packages. bstrap_script = open(BOOTSTRAP_SCRIPT, 'w') bstrap_output = create_bootstrap_script( textwrap.dedent(BOOTSTRAP_BASE_SCRIPT)) bstrap_script.write(bstrap_output) bstrap_script.close() print "** Bootstrap script created" ## Create the virtualenv itself. import _bootstrap _bootstrap.create_environment(PACKAGE) _bootstrap.after_install(None, PACKAGE) init_file = open(PACKAGE + '/' + '__init__.py', 'w') init_file.close() print "** Virtual environment created" # Create the prerm debian script. prerm_fd = open('debian/%s.prerm' % PACKAGE_DEBIAN_NAME, 'w') file_list = FILE_LIST_VAR + '=$(cat <<EOF\n' + str(
output = virtualenv.create_bootstrap_script( textwrap.dedent(""" import os, subprocess, sys ZCBUILDOUT_VERSION='2.5.3' # This is the latest setuptools possible for now - # since 20.2 requires that all versions be PEP-440 compliant SETUPTOOLS_VERSION='20.1.1' PIP_VERSION='8.1.2' def extend_parser(parser): parser.add_option( '--buildout_version', dest='buildout_version', default=ZCBUILDOUT_VERSION, help='Optional specification of zc.buildout version to use when bootstrapping') parser.add_option( '--setuptools-version', dest='setuptools_version', default=SETUPTOOLS_VERSION, help='Optional specification of setuptools version to use when bootstrapping') def after_install(options, home_dir): if sys.platform == 'win32': bin = 'Scripts' else: bin = 'bin' # Install package example: #subprocess.call([join(home_dir, bin, 'easy_install'), # 'MyPackage']) # Run script example: #subprocess.call([join(home_dir, bin, 'my-package-script'), # 'setup', home_dir]) if not os.path.exists(os.path.join(home_dir, 'buildout.cfg')): shutil.copy(os.path.join(home_dir, 'buildout.cfg.example'), os.path.join(home_dir, 'buildout.cfg')) if os.path.exists('bootstrap-buildout.py'): logger.notify('') # newline logger.notify('Running buildout bootstrap') logger.notify('zc.buildout == ' + str(options.buildout_version)) logger.notify('setuptools == ' + str(options.setuptools_version)) subprocess.call([os.path.join(home_dir, bin, 'python'), 'bootstrap-buildout.py', '--buildout-version=' + options.buildout_version, '--setuptools-version=' + options.setuptools_version ]) logger.notify('') # newline # Fix InsecurePlatformWarning: subprocess.call([os.path.join(home_dir, bin, 'pip'), 'install', 'pyopenssl', 'ndg-httpsclient', 'pyasn1']) logger.notify('updating setuptools to ' + SETUPTOOLS_VERSION) subprocess.call([os.path.join(home_dir, bin, 'pip'), 'install', 'setuptools==' + SETUPTOOLS_VERSION]) subprocess.call([os.path.join(home_dir, bin, 'pip'), 'install', 'pip==' + PIP_VERSION]) def adjust_options(options, args): options.no_wheel = True """))
# # Copyright (c) 2012 Citrix Systems, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # import virtualenv, sys, os output = virtualenv.create_bootstrap_script( file(os.path.join(sys.argv[1], 'bootstrap.py'), 'r').read()) o = file(sys.argv[2], 'w') o.write(output) o.close()