def first_run_setup(): shell = supported_shell() if shell: if shell == 'fish': source_cmd = 'source (pew shell_config)' else: source_cmd = 'source $(pew shell_config)' rcpath = expandpath({ 'bash': '~/.bashrc', 'zsh': '~/.zshrc', 'fish': '~/.config/fish/config.fish' }[shell]) with rcpath.open('r+') as rcfile: if (source_cmd + '\n') not in rcfile.readlines(): choice = 'X' while choice not in ('y', '', 'n'): choice = input( "It seems that you're running pew for the first time\n" "do you want to modify %s to source completions and" " update your prompt? [y/N]\n> " % rcpath).lower() if choice == 'y': rcfile.write('\n# added by Pew\n%s\n' % source_cmd) print('Done') else: print( '\nOk, if you want to do it manually, just add\n %s\nat' ' the end of %s' % (source_cmd, rcpath)) print('\nWill now continue with the command:', *sys.argv[1:]) input('[enter]')
def cp_cmd(): """Duplicate the named virtualenv to make a new one.""" parser = argparse.ArgumentParser() parser.add_argument('source') parser.add_argument('target', nargs='?') parser.add_argument('-d', '--dont-activate', action='store_false', default=True, dest='activate', help="After \ creation, continue with the existing shell (don't \ activate the new environment).") args = parser.parse_args() source = expandpath(args.source) if not source.exists(): source = workon_home / args.source if not source.exists(): sys.exit('Please provide a valid virtualenv to copy') target_name = args.target or source.name target = workon_home / target_name if target.exists(): sys.exit('%s virtualenv already exists in %s.' % (target_name, workon_home)) print('Copying {0} in {1}'.format(source, target_name)) clone_virtualenv(str(source), str(target)) if args.activate: shell(target_name)
def cp_cmd(): """Duplicate the named virtualenv to make a new one.""" parser = argparse.ArgumentParser() parser.add_argument("source") parser.add_argument("target", nargs="?") parser.add_argument( "-d", "--dont-activate", action="store_false", default=True, dest="activate", help="After \ creation, continue with the existing shell (don't \ activate the new environment).", ) args = parser.parse_args() source = expandpath(args.source) if not source.exists(): source = workon_home / args.source if not source.exists(): sys.exit("Please provide a valid virtualenv to copy") target_name = args.target or source.name target = workon_home / target_name if target.exists(): sys.exit("%s virtualenv already exists in %s." % (target_name, workon_home)) print("Copying {0} in {1}".format(source, target_name)) clone_virtualenv(str(source), str(target)) if args.activate: shell(target_name)
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest path = (workon_home / envname).absolute() try: check_call([sys.executable, "-m", "virtualenv", str(path)] + rest) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', *packages)
def first_run_setup(): shell = supported_shell() if shell: if shell == 'fish': source_cmd = 'source (pew shell_config)' else: source_cmd = 'source $(pew shell_config)' rcpath = expandpath({'bash': '~/.bashrc' , 'zsh': '~/.zshrc' , 'fish': '~/.config/fish/config.fish'}[shell]) with rcpath.open('r+') as rcfile: if (source_cmd + '\n') not in rcfile.readlines(): choice = 'X' while choice not in ('y', '', 'n'): choice = input("It seems that you're running pew for the first time\n" "do you want to modify %s to source completions and" " update your prompt? [y/N]\n> " % rcpath).lower() if choice == 'y': rcfile.write('\n# added by Pew\n%s\n' % source_cmd) print('Done') else: print('\nOk, if you want to do it manually, just add\n %s\nat' ' the end of %s' % (source_cmd, rcpath)) print('\nWill now continue with the command:', *sys.argv[1:]) input('[enter]')
def fork_cmder(env, cwd): shell_cmd = ['cmd'] cmderrc_path = r'%CMDER_ROOT%\vendor\init.bat' if expandpath(cmderrc_path).exists(): shell_cmd += ['/k', cmderrc_path] if cwd: os.environ['CMDER_START'] = cwd fork_shell(env, shell_cmd, cwd)
def fork_bash(env, cwd): # bash is a special little snowflake, and prevent_path_errors cannot work there # https://github.com/berdario/pew/issues/58#issuecomment-102182346 with NamedTemporaryFile('w+') as rcfile: with expandpath('~/.bashrc').open() as bashrc: rcfile.write(bashrc.read()) rcfile.write('\nexport PATH=' + compute_path(env)) fork_shell(env, ['bash', '--rcfile', rcfile.name], cwd)
def fork_cmder(env, cwd): shell_cmd = ["cmd"] cmderrc_path = r"%CMDER_ROOT%\vendor\init.bat" if expandpath(cmderrc_path).exists(): shell_cmd += ["/k", cmderrc_path] if cwd: os.environ["CMDER_START"] = cwd fork_shell(env, shell_cmd, cwd)
def fork_cmder(env, cwd): shell_cmd = ['cmd'] escaped_cmder_root = os.environ['CMDER_ROOT'].replace(' ', '^ ') cmderrc_path = r'{0}\vendor\init.bat'.format(escaped_cmder_root) if expandpath(cmderrc_path).exists(): shell_cmd += ['/k', cmderrc_path] if cwd: os.environ['CMDER_START'] = cwd fork_shell(env, shell_cmd, cwd)
def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath('~/.virtualenvs') if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \ 'XDG_DATA_HOME' not in os.environ and not link.exists(): link.symlink_to(str(workon_home)) return True else: return False
def new_cmd(argv): """Create a new environment, in $WORKON_HOME.""" parser = mkvirtualenv_argparser() parser.add_argument('-a', dest='project', help='Provide a full path to a \ project directory to associate with the new environment.') parser.add_argument('envname') args, rest = parser.parse_known_args(argv) project = expandpath(args.project) if args.project else None mkvirtualenv(args.envname, args.python, args.packages, project, args.requirements, args.type, rest) if args.activate: shell(args.envname)
def fork_bash(env, cwd): # bash is a special little snowflake, and prevent_path_errors cannot work there # https://github.com/berdario/pew/issues/58#issuecomment-102182346 bashrcpath = expandpath('~/.bashrc') if bashrcpath.exists(): with NamedTemporaryFile('w+') as rcfile: with bashrcpath.open() as bashrc: rcfile.write(bashrc.read()) rcfile.write('\nexport PATH=' + compute_path(env)) rcfile.flush() fork_shell(env, ['bash', '--rcfile', rcfile.name], cwd) else: fork_shell(env, ['bash'], cwd)
def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath('~/.virtualenvs') if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \ 'XDG_DATA_HOME' not in os.environ and not link.exists(): try: workon_home.symlink_to(str(link)) except OSError as e: # FIXME on TravisCI, even if I check with `link.exists()`, this # exception can be raised and needs to be catched, maybe it's a race condition? if e.errno != 17: raise
def fork_bash(env, cwd): # bash is a special little snowflake, and prevent_path_errors cannot work there # https://github.com/berdario/pew/issues/58#issuecomment-102182346 bashrcpath = expandpath("~/.bashrc") if bashrcpath.exists(): with NamedTemporaryFile("w+") as rcfile: with bashrcpath.open() as bashrc: rcfile.write(bashrc.read()) rcfile.write('\nexport PATH="' + to_unicode(compute_path(env)) + '"') rcfile.flush() fork_shell(env, ["bash", "--rcfile", rcfile.name], cwd) else: fork_shell(env, ["bash"], cwd)
def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath("~/.virtualenvs") if ( os.name == "posix" and "WORKON_HOME" not in os.environ and "XDG_DATA_HOME" not in os.environ and not link.exists() ): link.symlink_to(str(workon_home)) return True else: return False
def new_cmd(argv): """Create a new environment, in $WORKON_HOME.""" parser = mkvirtualenv_argparser() parser.add_argument('-a', dest='project', help='Provide a full path to a \ project directory to associate with the new environment.') parser.add_argument('envname') args, rest = parser.parse_known_args(argv) project = expandpath(args.project) if args.project else None mkvirtualenv(args.envname, args.python, args.packages, project, args.requirements, rest) if args.activate: shell(args.envname)
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, "pip", "install", "-r", str(expandpath(requirements))) if packages: inve(envname, "pip", "install", *packages)
def new_cmd(): """Create a new environment, in $WORKON_HOME.""" parser = mkvirtualenv_argparser() parser.add_argument( "-a", dest="project", help="Provide a full path to a \ project directory to associate with the new environment.", ) parser.add_argument("envname") args, rest = parser.parse_known_args() project = expandpath(args.project) if args.project else None mkvirtualenv(args.envname, args.python, args.packages, project, args.requirements, rest) if args.activate: shell(args.envname)
def copy_virtualenv_project(source, target): source = expandpath(source) if not source.exists(): source = workon_home / source if not source.exists(): sys.exit("Please provide a valid virtualenv to copy") target_name = target or source.name target = workon_home / target_name if target.exists(): sys.exit("%s virtualenv already exists in %s." % (target_name, workon_home)) print("Copying {0} in {1}".format(source, target_name)) clone_virtualenv(str(source), str(target)) return target_name
def first_run_setup(): shell = supported_shell() if shell: if shell == "fish": source_cmd = "source (pew shell_config)" else: source_cmd = "source $(pew shell_config)" rcpath = expandpath({"bash": "~/.bashrc", "zsh": "~/.zshrc", "fish": "~/.config/fish/config.fish"}[shell]) if rcpath.exists(): update_config_file(rcpath, source_cmd) else: print( "It seems that you're running pew for the first time\n" "If you want source shell competions and update your prompt, " "Add the following line to your shell config file:\n %s" % source_cmd ) print("\nWill now continue with the command:", *sys.argv[1:]) input("[enter]")
def first_run_setup(): shell = supported_shell() if shell: if shell == 'fish': source_cmd = 'source (pew shell_config)' else: source_cmd = 'source $(pew shell_config)' rcpath = expandpath({'bash': '~/.bashrc' , 'zsh': '~/.zshrc' , 'fish': '~/.config/fish/config.fish'}[shell]) if rcpath.exists(): update_config_file(rcpath, source_cmd) else: print("It seems that you're running pew for the first time\n" "If you want source shell competions and update your prompt, " "Add the following line to your shell config file:\n %s" % source_cmd) print('\nWill now continue with the command:', *sys.argv[1:]) input('[enter]')
def copy_virtualenv_project(source, target): source = expandpath(source) if not source.exists(): source = workon_home / source if not source.exists(): sys.exit('Please provide a valid virtualenv to copy') target_name = target or source.name target = workon_home / target_name if target.exists(): sys.exit('%s virtualenv already exists in %s.' % (target_name, workon_home)) print('Copying {0} in {1}'.format(source, target_name)) clone_virtualenv(str(source), str(target)) return target_name
def first_run_setup(): shell = supported_shell() if shell: if shell == 'fish': source_cmd = 'source (pew shell_config)' else: source_cmd = 'source "$(pew shell_config)"' rcpath = expandpath({'bash': '~/.bashrc' , 'zsh': '~/.zshrc' , 'fish': '~/.config/fish/config.fish'}[shell]) if rcpath.exists(): update_config_file(rcpath, source_cmd) else: print("It seems that you're running pew for the first time\n" "If you want source shell competions and update your prompt, " "Add the following line to your shell config file:\n %s" % source_cmd) print('\nWill now continue with the command:', *sys.argv[1:]) input('[enter]')
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, pytype='cpython', rest=[]): if python: version_path = locate_python_by_version(python, pytype) if version_path: python = version_path rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) except (CalledProcessError, KeyboardInterrupt): rmvirtualenvs([envname]) raise else: if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages)
def mkvirtualenv(envname, python=None, packages=[], project=None, requirements=None, rest=[]): if python: rest = ["--python=%s" % python] + rest try: check_call(["virtualenv", envname] + rest, cwd=str(workon_home)) if project: setvirtualenvproject(envname, project.absolute()) if requirements: inve(envname, 'pip', 'install', '--allow-all-external', '-r', str(expandpath(requirements))) if packages: inve(envname, 'pip', 'install', '--allow-all-external', *packages) except CalledProcessError: rmvirtualenvs([envname]) raise
def get_workon_home(): return expandpath(os.environ.get('WORKON_HOME', default_home))
InstallCommand = ListPythons = LocatePython = \ lambda : sys.exit('Command not supported on this platform') from pew import __version__ from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir, check_path, temp_environ, NamedTemporaryFile, to_unicode) from pew._print_utils import print_virtualenvs if sys.version_info[0] == 2: input = raw_input err = partial(print, file=sys.stderr) workon_home = expandpath( os.environ.get('WORKON_HOME', os.path.join(os.environ.get('XDG_DATA_HOME', '~/.local/share'), 'virtualenvs'))) def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath('~/.virtualenvs') if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \ 'XDG_DATA_HOME' not in os.environ and not link.exists(): link.symlink_to(str(workon_home)) return True else: return False
from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir, check_path, temp_environ, NamedTemporaryFile, to_unicode) from pew._print_utils import print_virtualenvs if sys.version_info[0] == 2: input = raw_input err = partial(print, file=sys.stderr) if windows: default_home = '~/.virtualenvs' else: default_home = os.path.join( os.environ.get('XDG_DATA_HOME', '~/.local/share'), 'virtualenvs') workon_home = expandpath( os.environ.get('WORKON_HOME', default_home)) def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath('~/.virtualenvs') if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \ 'XDG_DATA_HOME' not in os.environ and not link.exists(): link.symlink_to(str(workon_home)) return True else: return False pew_site = Path(__file__).parent
else: # Pythonz does not support windows InstallCommand = ListPythons = LocatePython = \ lambda : sys.exit('Command not supported on this platform') from pew import __version__ from pew._utils import (check_call, invoke, expandpath, own, env_bin_dir, check_path, temp_environ) from pew._print_utils import print_virtualenvs if sys.version_info[0] == 2: input = raw_input workon_home = expandpath( os.environ.get( 'WORKON_HOME', os.path.join(os.environ.get('XDG_DATA_HOME', '~/.local/share'), 'virtualenvs'))) def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath('~/.virtualenvs') if os.name == 'posix' and 'WORKON_HOME' not in os.environ and \ 'XDG_DATA_HOME' not in os.environ and not link.exists(): link.symlink_to(str(workon_home)) return True else: return False
temp_environ, NamedTemporaryFile, to_unicode, ) from pew._print_utils import print_virtualenvs if sys.version_info[0] == 2: input = raw_input err = partial(print, file=sys.stderr) if windows: default_home = "~/.virtualenvs" else: default_home = os.path.join(os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs") workon_home = expandpath(os.environ.get("WORKON_HOME", default_home)) def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath("~/.virtualenvs") if ( os.name == "posix" and "WORKON_HOME" not in os.environ and "XDG_DATA_HOME" not in os.environ and not link.exists() ): link.symlink_to(str(workon_home)) return True else:
from pew import __version__ from pew._utils import check_call, invoke, expandpath, own, env_bin_dir, check_path, temp_environ from pew._print_utils import print_virtualenvs windows = sys.platform == "win32" def update_args_dict(): global args args = dict(enumerate(sys.argv)) update_args_dict() workon_home = expandpath( os.environ.get("WORKON_HOME", os.path.join(os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs")) ) def makedirs_and_symlink_if_needed(workon_home): if not workon_home.exists() and own(workon_home): workon_home.mkdir(parents=True) link = expandpath("~/.virtualenvs") if ( os.name == "posix" and "WORKON_HOME" not in os.environ and "XDG_DATA_HOME" not in os.environ and not link.exists() ): try: workon_home.symlink_to(str(link))