def __getitem__(self, name): """Get information about a virtual environment. Parameters ---------- name : str or Ellipsis Virtual environment name or absolute path. If ... is given, return the current one (throws a KeyError if there isn't one). """ if name is ...: env_paths = [builtins.__xonsh_env__['VIRTUAL_ENV']] elif isinstance(name, PathLike): env_paths = [fspath(name)] else: if not self._check_reserved(name): # Don't allow a venv that could be a venv special dir raise KeyError() env_paths = [] if os.path.isdir(name): env_paths += [name] env_paths += [os.path.join(self.venvdir, name)] for ep in env_paths: ve = _mkvenv(ep) # Actually check if this is an actual venv or just a organizational directory # eg, if 'spam/eggs' is a venv, reject 'spam' if not os.path.exists(ve.bin): continue return ve else: raise KeyError()
def __getitem__(self, name): """Get information about a virtual environment. Parameters ---------- name : str or Ellipsis Virtual environment name or absolute path. If ... is given, return the current one (throws a KeyError if there isn't one). """ if name is ...: env_paths = [builtins.__xonsh_env__['VIRTUAL_ENV']] elif isinstance(name, PathLike): env_paths = [fspath(name)] else: if not self._check_reserved(name): # Don't allow a venv that could be a venv special dir raise KeyError() env_paths = [] if os.path.isdir(name): env_paths += [name] env_paths += [os.path.join(self.venvdir, name)] for ep in env_paths: ve = _mkvenv(ep) # Actually check if this is an actual venv or just a organizational directory # eg, if 'spam/eggs' is a venv, reject 'spam' if not os.path.exists(ve.bin): continue return ve else: raise KeyError()
def create(self, name, *, system_site_packages=False, symlinks=False, with_pip=True): """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``. Parameters ---------- name : str Virtual environment name system_site_packages : bool If True, the system (global) site-packages dir is available to created environments. symlinks : bool If True, attempt to symlink rather than copy files into virtual environment. with_pip : bool If True, ensure pip is installed in the virtual environment. (Default is True) """ # NOTE: clear=True is the same as delete then create. # NOTE: upgrade=True is its own method if isinstance(name, PathLike): env_path = fspath(name) else: env_path = os.path.join(self.venvdir, name) if not self._check_reserved(env_path): raise ValueError("venv can't contain reserved names ({})".format(', '.join(_subdir_names()))) venv.create( env_path, system_site_packages=system_site_packages, symlinks=symlinks, with_pip=with_pip) events.vox_on_create.fire(name=name)
def create(self, name, *, system_site_packages=False, symlinks=False, with_pip=True): """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``. Parameters ---------- name : str Virtual environment name system_site_packages : bool If True, the system (global) site-packages dir is available to created environments. symlinks : bool If True, attempt to symlink rather than copy files into virtual environment. with_pip : bool If True, ensure pip is installed in the virtual environment. (Default is True) """ # NOTE: clear=True is the same as delete then create. # NOTE: upgrade=True is its own method if isinstance(name, PathLike): env_path = fspath(name) else: env_path = os.path.join(self.venvdir, name) if not self._check_reserved(env_path): raise ValueError("venv can't contain reserved names ({})".format(', '.join(_subdir_names()))) venv.create( env_path, system_site_packages=system_site_packages, symlinks=symlinks, with_pip=with_pip) events.vox_on_create.fire(name=name)