dotfiles.venv package¶
Objectives¶
dotfiles.venv.venv_ipyconfig (venv_ipyconfig.py):
Set variables for standard Virtualenv paths in the environment dict (“Venv Paths”)
Define IPython aliases (
%aliases)Serialize variables and aliases to:
IPython configuration (variables, aliases)
Bash/ZSH configuration (variables, aliases, functions):
venv.py -e --bash # venv --print-bash --from-environ venv.py dotfiles --bash # venv --print-bash --wh=~/-wrk/-ve27 --ve=dotfiles
JSON (variables, aliases) [
--print]:venv.py -e --json venv.py dotfiles --json
dotfiles.venv.venv_ipymagics (venv_ipymagics.py):
- Configure IPython
%magiccommandsds– print dotfiles_statuscd*– CdAliases for Venv Paths (e.g.%cdhelp,%cdp,%cdwh,%cdv,%cds,%cdw)
Configuration¶
Shell¶
:ref:`dotfiles` configuration`
# TODO:
source ${__DOTFILES}/scripts/venv.sh
source ${__VENV}/scripts/venv.sh
build-venv.sh:
cat venv_core.sh > venv.sh
cat venv_cdaliases >> venv.sh
source ${__DOTFILES}/etc/bash/10-bashrc.venv.sh # venv(), workon_venv
source ${__DOTFILES}/scripts/venv.sh # cdaliases, work
etc/bash/10-bashrc.venv.sh is sourced by
etc/bash/00-bashrc.before.sh, which is sourced by ~/.bashrc
(a symlink to ${__DOTFILES}/etc/.bashrc created by
bootstrap_dotfiles.sh -S).
IPython¶
To configure IPython with venv, venv_ipyconfig.py
must be symlinked into ~/.ipython/profile_default/ipython_config.py
and, optionally, for CdAliases,
venv_ipymagics.py must be symlinked
into e.g. ~/.ipython/profile_default/startup/20-venv_ipymagics.py):
# symlink paths relative to ${__DOTFILES}
__DOTFILES="~/-dotfiles"
# working directory (path to the dotfiles repository)
_WRD=${WORKON_HOME}/dotfiles/src/dotfiles
# MANUALLY INSTALL for each IPython profile
IPY_PROFILE="profile_default"
ln -s ${__DOTFILES}/scripts/venv_ipyconfig.py \
~/.ipython/${IPY_PROFILE}/ipython_config.py
ln -s ${__DOTFILES}/scripts/venv_ipymagics.py \
~/.ipython/${IPY_PROFILE}/startup/20-venv_ipymagics.py
Submodules¶
dotfiles.venv.ipython_config module¶
-
dotfiles.venv.ipython_config.in_venv_ipyconfig()[source]¶ Returns: True if get_ipythonis inglobals()Return type: bool
-
dotfiles.venv.ipython_config.logevent(event, obj=None, logger=<Logger venv (WARNING)>, level=10, func=None, lineno=None, modpath=None, show_modpath=None, wrap=False, splitlines=True)[source]¶ Parameters: - event (str) – an event key
- obj (thing) – thing to serialize and log
- logger (logging.Logger) – logger to log to
- level (int) – logging loglevel to log (event, obj)
- wrap (bool) – Add header and footer <event> tags (default: False)
- splitlines (bool) – split by newlines and emit one log message per line
Returns: (event:str, output:str)
Return type: tuple
-
exception
dotfiles.venv.ipython_config.StepConfigException[source]¶ Bases:
dotfiles.venv.ipython_config.StepException,dotfiles.venv.ipython_config.ConfigException
-
dotfiles.venv.ipython_config.prepend_comment_char(strblock, commentchar='##')[source]¶ Parameters: - strblock (str) – string to split by newlines and prepend
- prefix (str) – comment string prefix (one space will be added)
Yields: str – lines prefixed with prefix
-
dotfiles.venv.ipython_config.get_pyver(pyverstr=None)[source]¶ Parameters: pyver (str) – “major.minor” e.g. 2.7or3.4(default:sys.version_info[:2])Returns: python2.7,python.34Return type: str
-
dotfiles.venv.ipython_config.get_WORKON_HOME_default(env=None, from_environ=False, default='-ve27', **kwargs)[source]¶ Keyword Arguments: - env (dict) – Env dict to read from (default: None)
- from_environ (bool) – read WORKON_HOME from os.environ
- default (str) – default WORKON_HOME dirname
- __WRK (str) –
Returns: path to a
WORKON_HOMEdirectoryReturn type: str
-
class
dotfiles.venv.ipython_config.VenvJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder-
default(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
dotfiles.venv.ipython_config.CmdAlias(cmdstr)[source]¶ Bases:
object
-
class
dotfiles.venv.ipython_config.IpyAlias(cmdstr, name=None, complfuncstr=None)[source]¶ Bases:
dotfiles.venv.ipython_config.CmdAliasAn IPython alias command string which expands to a shell function
aliasname() { ... }and handles positional args%sand%lReferences
- TODO: IPython docs
-
class
dotfiles.venv.ipython_config.CdAlias(pathvar, name=None, aliases=None)[source]¶ Bases:
dotfiles.venv.ipython_config.CmdAliasA CmdAlias for
cdchange directory functions with venv paths (e.g. $_WRD) for Bash, ZSH, IPython, Vim.- venv.sh bash functions with tab-completion (cdwrd, cdw, cdw<tab>)
- venv_ipymagics.py: ipython magics (%cdwrd, cdwrd, cdw)
- venv.vim: vim functions (:Cdwrd)
-
VENV_IPYMAGICS_FILE_HEADER= '\n#!/usr/bin/env ipython\n# dotfiles.venv.venv_ipymagics\nfrom __future__ import print_function\n"""\nIPython ``%magic`` commands\n\n* ``cd`` aliases\n* ``ds`` (``dotfiles_status``)\n* ``dr`` (``dotfiles_reload``)\n\nInstallation\n--------------\n.. code-block:: bash\n\n __DOTFILES="${HOME}/-dotfiles"\n ipython_profile="profile_default"\n ln -s ${__DOTFILES}/etc/ipython/venv_ipymagics.py \\\n ~/.ipython/${ipython_profile}/startup/venv_ipymagics.py\n"""\nimport os\nimport sys\ntry:\n from IPython.core.magic import (Magics, magics_class, line_magic)\nexcept ImportError:\n print("ImportError: IPython")\n # Mock IPython for building docs\n Magics = object\n magics_class = lambda cls, *args, **kwargs: cls\n line_magic = lambda func, *args, **kwargs: func\n\nif sys.version_info.major == 2:\n str = unicode\n\ndef ipymagic_quote(_str):\n return str(_str)\n\n@magics_class\nclass VenvMagics(Magics):\n def cd(self, envvar, line):\n """\n Change directory\n\n Args:\n envvar (str): os.environ variable name\n line (str): path to append to envvar\n """\n prefix = os.environ.get(envvar, "")\n _dstpath = line.lstrip(os.path.sep)\n path = os.path.join(prefix, _dstpath)\n cmd = ("cd %s" % ipymagic_quote(path))\n print("%" + cmd, file=sys.stderr)\n return self.shell.magic(cmd)'¶
-
VENV_IPYMAGIC_METHOD_TEMPLATE= '\n @line_magic\n def {ipy_func_name}(self, line):\n """{ipy_func_name} -- cd ${pathvar}/${{@}}"""\n return self.cd(\'{pathvar}\', line)'¶
-
VENV_IPYMAGICS_FOOTER= '\n @line_magic\n def cdhelp(self, line):\n """cdhelp() -- list cd commands"""\n for cdfunc in dir(self):\n if cdfunc.startswith(\'cd\') and cdfunc not in (\'cdhelp\',\'cd\'):\n docstr = getattr(self, cdfunc).__doc__.split(\'--\',1)[-1].strip()\n print("%%%-16s -- %s" % (cdfunc, docstr))\n\n @staticmethod\n def _dotfiles_status():\n """\n Print ``dotfiles_status``: venv variables\n """\n env_vars = [\n \'HOSTNAME\',\n \'USER\',\n \'PROJECT_HOME\',\n \'CONDA_ROOT\',\n \'CONDA_ENVS_PATH\',\n \'WORKON_HOME\',\n \'VIRTUAL_ENV_NAME\',\n \'VIRTUAL_ENV\',\n \'_USRLOG\',\n \'_TERM_ID\',\n \'_SRC\',\n \'_APP\',\n \'_WRD\',\n \'PATH\',\n \'__DOTFILES\',\n ]\n environ = dict((var, os.environ.get(var)) for var in env_vars)\n environ[\'HOSTNAME\'] = __import__(\'socket\').gethostname()\n for var in env_vars:\n print(\'{}="{}"\'.format(var, "%s" % environ.get(var,\'\')))\n\n @line_magic\n def dotfiles_status(self, line):\n """dotfiles_status() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @line_magic\n def ds(self, line):\n """ds() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @staticmethod\n def _dotfiles_reload():\n """_dotfiles_reload() -- print NotImplemented"""\n print("NotImplemented: dotfiles_reload()")\n\n @line_magic\n def dotfiles_reload(self, line):\n """dotfiles_reload() -- print NotImplemented"""\n return self._dotfiles_reload()\n\n @line_magic\n def dr(self, line):\n """dr() -- print NotImplemented [dotfiles_reload()]"""\n return self._dotfiles_reload()\n\n\ndef main():\n """\n Register VenvMagics with IPython\n """\n import IPython\n ip = IPython.get_ipython()\n ip.register_magics(VenvMagics)\n\n\nif __name__ == "__main__":\n main()\n'¶
-
to_ipython_method()[source]¶ Keyword Arguments: include_completions (bool) – generate inline Bash completions Returns: ipython method block Return type: str
-
VIM_HEADER_TEMPLATE= '\n" ### venv.vim\n" # Src: https://github.com/westurner/venv.vim\n\n" "g:venv_list_only_dirs -- 1 -- 0 to list files in Cd* commands\n\nlet g:venv_list_only_dirs = 1\n\nfunction! Cd_help()\n" :Cdhelp -- list venv.vim cdalias commands\n :verbose command Cd\nendfunction\ncommand! -nargs=0 Cdhelp call Cd_help()\n\nfunction! ListDirsOrFiles(path, ArgLead, ...)\n let dirsonly = ((a:0>0) ? 1 : g:venv_list_only_dirs)\n let _glob = \'\' . a:ArgLead . ((g:venv_list_only_dirs>1) ? \'*/\' : \'*\')\n execute \'lcd\' a:path\n if dirsonly ==? 1\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:]\')\n elseif dirsonly ==? 0\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:] . (isdirectory(v:val) ? "/" : "")\')\n endif\n execute \'lcd -\'\n return output\nendfunction\n\nfunction! Cdhere(...)\n" :Cdhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n" :CDhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'cd\' _path\n pwd\nendfunction\nfunction! Compl_Cdhere(ArgLead, ...)\n return ListDirsOrFiles(expand(\'%:p:h\'), a:ArgLead, 1)\nendfor\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Cdhere call Cdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere CDhere call Cdhere(<f-args>)\n\nfunction! Lcdhere(...)\n" :Lcdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n" :LCdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'lcd\' _path\n pwd\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Lcdhere call Lcdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere LCdhere call Lcdhere(<f-args>)\n\n\nfunction! Cd___VAR_(varname, cmd, ...)\n" Cd___VAR_() -- cd expand(\'$\' . a:varname)/$1\n let _VARNAME = a:varname\n let _VAR_=expand(_VARNAME)\n if _VARNAME ==? _VAR_\n echoerr _VARNAME . " is not set"\n return\n endif\n let pathname = join([_VAR_, (a:0>0) ? a:1 : ""], "/")\n execute a:cmd pathname\n pwd\nendfunction\n\n'¶
-
VIM_CD_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- cd ${pathvar}/$1\n call Cd___VAR_(\'${pathvar}\', \'{vim_cd_func}\', (a:0>0)? a:1 : "")\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 1)\nendfunction\n'¶
-
VIM_CD_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- cd ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
VIM_EDIT_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- e ${pathvar}/$1\n let _path=expand("${pathvar}") . ((a:0>0)? "/" . a:1 : "")\n execute \'{vim_edit_func}\' _path\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 0)\nendfunction\n'¶
-
VIM_EDIT_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- e ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
vim_cmd_name¶ Returns: str: e.g “Cdwrd”
-
vim_cmd_names¶ Returns: list: self.vim_cmd_name + self.aliases.title()
-
BASH_CDALIAS_HEADER= '#!/bin/sh\n## venv.sh\n# generated from $(venv --print-bash --prefix=/)\n\n'¶
-
BASH_FUNCTION_TEMPLATE= '{bash_func_name} () {{\n # {bash_func_name:16} -- cd ${pathvar} /$@\n [ -z "${pathvar}" ] && echo "{pathvar} is not set" && return 1\n cd "${pathvar}"${{@:+"/${{@}}"}}\n}}\n{bash_compl_name} () {{\n local cur="$2";\n COMPREPLY=($({bash_func_name} && compgen -d -- "${{cur}}" ))\n}}\n'¶
-
BASH_ALIAS_TEMPLATE= '{cmd_name} () {{\n # {cmd_name:16} -- cd ${pathvar}\n {bash_func_name} $@\n}}\n'¶
-
BASH_COMPLETION_TEMPLATE= 'complete -o default -o nospace -F {bash_compl_name} {cmd_name}\n'¶
-
bash_func_name¶ Returns: str: e.g. “cdwrd”
-
bash_func_names¶ Returns: list: self.bash_func_name + self.aliases
-
class
dotfiles.venv.ipython_config.Step(func=None, **kwargs)[source]¶ Bases:
objectA build task step which builds or transforms an
Env, by callingstep.build(env=env, **step.conf)-
name¶ Returns: str: a name for this Step
-
build_print_kwargs_env(env=None, **kwargs)[source]¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
DEFAULT_FUNC(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.ipython_config.PrintEnvStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.ipython_config.StepPrint env and kwargs to stdout
-
stdout= <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>¶
-
stderr= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.ipython_config.PrintEnvStderrStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.ipython_config.PrintEnvStepPrint env and kwargs to stderr
-
stdout= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
-
class
dotfiles.venv.ipython_config.StepBuilder(**kwargs)[source]¶ Bases:
objectA class for building a sequence of steps which modify env
-
name¶
-
debug¶ Returns: str: self.conf.get(‘debug’)
-
show_diffs¶ Returns: str: self.conf.get(‘show_diffs’)
-
add_step(func, **kwargs)[source]¶ Add a step to
self.stepsParameters: - func (Step or function or str) –
func(env=None, **kwargs) - kwargs (dict) – kwargs for Step.conf
Keyword Arguments: name (str) – function name (default: None)
Returns: Step object appended to self.steps
Return type: Step- func (Step or function or str) –
-
build_iter(env=None, show_diffs=True, debug=False)[source]¶ Build a generator of (Step, Env) tuples from the functional composition of StepBuilder.steps given an initial
Env(or None).# pseudocode env_previous = Env() for step in self.steps: (step, env) = step.build(env=env_previous.copy(),**conf) env_previous=env
Keyword Arguments: - env (Env) – initial Env (default: None)
- show_diffs (bool) – show difflib.ndiffs of Envs between steps
- debug (bool) –
Yields: tuple – (
Step,Env)
-
-
dotfiles.venv.ipython_config.lookup_from_kwargs_env(kwargs, env, attr, default=None)[source]¶ __getitem__ from kwargs, env, or default.
Parameters: - kwargs (dict) – kwargs dict
- env (Env) –
Envdict - attr (str) – attribute name
- default (obj) – default value to return if not found in kwargs or env
Returns: kwargs.get(attr, env.get(attr, default))
Return type: obj
-
dotfiles.venv.ipython_config.build_dotfiles_env(env=None, **kwargs)[source]¶ Configure dotfiles base environment (HOME, __WRK, __SRC, __DOTFILES)
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - HOME (str) – home path (
$HOME,~) - __WRK (str) – workspace path (
$__WRK,~/-wrk) - __SRC (str) – path to source repos (
$__WRK/-src) - __DOTFILES (str) – current dotfiles path (
~/-dotfiles)
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- HOME
- __WRK
- __SRC
- __DOTFILES
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.ipython_config.build_virtualenvwrapper_env(env=None, **kwargs)[source]¶ Set WORKON_HOME to WORKON_HOME or WORKON_HOME_DEFAULT
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - __WRK (str) – workspace path (
$__WRK,~/-wrk) - WORKON_HOME_DEFAULT (str) – variable name (default:
WORKON_HOME__py27) - WORKON_HOME__* (str) – path to a WORKON_HOME set
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- WORKON_HOME__py27=’${__WRK}/-ve27’
- WORKON_HOME__py34=’${__WRK}/-ve34’
- WORKON_HOME__*=kwargs.get(WORKON_HOME__*)
- WORKON_HOME_DEFAULT=’WORKON_HOME_py27’
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.ipython_config.build_conda_env(env=None, **kwargs)[source]¶ Configure conda27 (2.7) and conda (3.4) with condaenvs in
-wrk/-ce27and-wrk/ce34.Other Parameters: - __WRK (str) – workspace root (
$__WRK,~/-wrk) - CONDA_ROOT__py27 (str) – path to conda27 root environment
- CONDA_ENVS__py27 (str) – path to conda27 envs (e.g. WORKON_HOME)
- CONDA_ROOT__py34 (str) – path to conda34 root environment
- CONDA_ENVS__py34 (str) – path to conda34 envs (e.g. WORKON_HOME)
Keyword Arguments: env (Env dict) –
dotfiles.venv.venv_ipyconfig.EnvReturns: Return type: env (Env dict)
- __WRK (str) – workspace root (
-
dotfiles.venv.ipython_config.build_conda_cfg_env(env=None, **kwargs)[source]¶ Configure conda for a specific environment TODO build_venv_config
Parameters: env (Env dict) – dotfiles.venv.venv_ipyconfig.EnvReturns: dotfiles.venv.venv_ipyconfig.EnvReturn type: env (Env dict)
-
dotfiles.venv.ipython_config.build_venv_paths_full_env(env=None, pyver=None, **kwargs)[source]¶ Set variables for standard paths in the environment
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env(default: None (Env())) - VENVPREFIX (str) – venv prefix path (default: None (VIRTUAL_ENV))
- VENVSTR (str) – name of a VIRTUAL_ENV in WORKON_HOME or path to a VIRTUAL_ENV (default: None)
- VIRTUAL_ENV (str) – path to a VIRTUAL_ENV (default: None)
Returns: Return type: env (Env dict)
Raises: StepConfigException – When not any(( VIRTUAL_ENV, VENVPREFIX, VENVSTR, VENVSTRAPP))
References
- env (Env dict) –
-
dotfiles.venv.ipython_config.build_venv_paths_cdalias_env(env=None, **kwargs)[source]¶ Build CdAliases for standard paths
Keyword Arguments: env (Env dict) – EnvReturns: Envwith.aliasesextended.Return type: env (Env dict) Note
These do not work in IPython as they run in a subshell. See:
dotfiles.venv.venv_ipymagics.
-
dotfiles.venv.ipython_config.build_user_aliases_env(env=None, dont_reflect=False, VIRTUAL_ENV=None, _SRC=None, _ETC=None, _CFG=None, PROJECT_FILES=None, **kwargs)[source]¶ Configure env variables and return an OrderedDict of aliases
Parameters: dont_reflect (bool) – Whether to always create aliases and functions referencing $_WRDeven if$_WRDdoesn’t exist. (default: False)Returns: dict of aliases Return type: OrderedDict
-
dotfiles.venv.ipython_config.build_usrlog_env(env=None, _TERM_ID=None, shell='bash', prefix=None, USER=None, HOSTNAME=None, lookup_hostname=False, **kwargs)[source]¶ Build environment variables and configuration like usrlog.sh
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - _TERM_ID (str) – terminal identifier string
- shell (str) – shell name (“bash”, “zsh”)
- prefix (str) – a path prefix (e.g.
$VIRTUAL_ENVor$PREFIX) - USER (str) – system username (
$USER) forHISTTIMEFORMAT - HOSTNAME (str) – system hostname (
HOSTNAME) forHISTTIMEFORMAT - lookup_hostname (bool) – if True,
HOSTNAMEis None, and not env.get(‘HOSTNAME’), try to readHOSTNAMEfromos.environand thensocket.gethostname().
Returns: Return type: env (Env dict)
Note
Like
usrlog.sh, whenHISTTIMEFORMATis set,USERandHOSTNAMEmust be evaluated.(When
USERandHOSTNAMEchange,HISTTIMEFORMATis not updated, and the .history file will contain only the most recent USER and HOSTNAME settings, which are not necessarily the actual USER and HOSTNAME.)TODO: could/should instead (also) write USER and HOSTNAME to -usrlog.log.
- env (Env dict) –
-
dotfiles.venv.ipython_config.build_venv_activate_env(env=None, VENVSTR=None, VENVSTRAPP=None, from_environ=False, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, **kwargs)[source]¶
-
class
dotfiles.venv.ipython_config.Env(*args, **kwargs)[source]¶ Bases:
objectOrderedDict of variables for/from
os.environ.-
osenviron_keys_classic= ('VIMBIN', 'GVIMBIN', 'MVIMBIN', 'GUIVIMBIN', 'VIMCONF', 'EDITOR', 'EDITOR_', 'PAGER', '__WRK', '__DOTFILES', 'PROJECT_HOME', 'WORKON_HOME', 'WORKON_HOME__py27', 'WORKON_HOME__py34', 'VENVPREFIX', 'VENVSTR', 'VENVSTRAPP', '_APP', 'VIRTUAL_ENV_NAME', 'VIRTUAL_ENV', '_SRC', '_ETC', '_BIN', '_CFG', '_LIB', '_LOG', '_MNT', '_OPT', '_PYLIB', '_PYSITE', '_SRV', '_VAR', '_WRD', '_WRD_SETUPY', '_WWW', '__SRC', '__DOCSWWW', '_USRLOG', '__USRLOG', '_TERM_ID', '_TERM_URI')¶
-
osenviron_keys= {'CONDA_ENVS_PATH': '${__WRK}/-ce27', 'CONDA_ENVS__py27': '${__WRK}/-ce27', 'CONDA_ENVS__py34': '${__WRK}/-ce34', 'CONDA_ENVS__py35': '${__WRK}/-ce35', 'CONDA_ENVS__py36': '${__WRK}/-ce36', 'CONDA_ENVS__py37': '${__WRK}/-ce37', 'CONDA_ROOT': '${__WRK}/-conda27', 'CONDA_ROOT__py27': '${__WRK}/-conda27', 'CONDA_ROOT__py34': '${__WRK}/-conda34', 'CONDA_ROOT__py35': '${__WRK}/-conda35', 'CONDA_ROOT__py36': '${__WRK}/-conda36', 'CONDA_ROOT__py37': '${__WRK}/-conda37', 'PROJECT_HOME': '${__WRK}', 'VENVPREFIX': '${VIRTUAL_ENV}', 'VENVSTR': 'dotfiles', 'VENVSTRAPP': 'dotfiles', 'VIRTUAL_ENV': '${WORKON_HOME}/${VIRTUAL_ENV_NAME}', 'VIRTUAL_ENV_NAME': 'dotfiles', 'WORKON_HOME': '${__WRK}/-ve27', 'WORKON_HOME_DEFAULT': 'WORKON_HOME__py37', 'WORKON_HOME__py27': '${__WRK}/-ve27', 'WORKON_HOME__py34': '${__WRK}/-ve34', 'WORKON_HOME__py35': '${__WRK}/-ve35', 'WORKON_HOME__py36': '${__WRK}/-ve36', 'WORKON_HOME__py37': '${__WRK}/-ve37', '_APP': 'dotfiles', '_BIN': '${VIRTUAL_ENV}/bin', '_ETC': '${VIRTUAL_ENV}/etc', '_ETCOPT': '${_ETC}/opt', '_HOME': '${VIRTUAL_ENV}/home', '_LIB': '${VIRTUAL_ENV}/lib', '_LOG': '${_VAR}/log', '_MEDIA': '${VIRTUAL_ENV}/media', '_MNT': '${VIRTUAL_ENV}/mnt', '_OPT': '${VIRTUAL_ENV}/opt', '_PYLIB': '${_LIB}/python2.7', '_PYSITE': '${_PYLIB}/site-packages', '_ROOT': '${VIRTUAL_ENV}/root', '_SBIN': '${VIRTUAL_ENV}/sbin', '_SRC': '${VIRTUAL_ENV}/src', '_SRV': '${VIRTUAL_ENV}/srv', '_TMP': '${VIRTUAL_ENV}/tmp', '_USR': '${VIRTUAL_ENV}/usr', '_USRBIN': '${VIRTUAL_ENV}/usr/bin', '_USRINCLUDE': '${VIRTUAL_ENV}/usr/include', '_USRLIB': '${VIRTUAL_ENV}/usr/lib', '_USRLOCAL': '${VIRTUAL_ENV}/usr/local', '_USRLOCALBIN': '${VIRTUAL_ENV}/usr/local/bin', '_USRSBIN': '${VIRTUAL_ENV}/usr/sbin', '_USRSHARE': '${VIRTUAL_ENV}/usr/share', '_USRSRC': '${VIRTUAL_ENV}/usr/src', '_VAR': '${VIRTUAL_ENV}/var', '_VARCACHE': '${_VAR}/cache', '_VARLIB': '${_VAR}/lib', '_VARLOCK': '${_VAR}/lock', '_VARMAIL': '${_VAR}/mail', '_VAROPT': '${_VAR}/opt', '_VARRUN': '${_VAR}/run', '_VARSPOOL': '${_VAR}/spool', '_VARTMP': '${_VAR}/tmp', '_WRD': '${_SRC}/dotfiles', '_WWW': '${_VAR}/www', '__DOTFILES': '${HOME}/-dotfiles', '__SRC': '${__WRK}/-src', '__WRK': '${HOME}/-wrk'}¶
-
name¶
-
classmethod
from_environ(environ, verbose=False)[source]¶ Build an
Envfrom a dict (e.g.os.environ)Parameters: - environ (dict) – a dict with variable name keys and values
- verbose (bool) – whether to be verbose about dict merging
Returns: an Env environment built from the given environ dict
Return type:
-
compress_paths(path_, keys=None, keyname=None)[source]¶ Given an arbitrary string, replace absolute paths (starting with ‘/’) with the longest matching Env path variables.
Parameters: path (str) – a path string Returns: path string containing ${VARNAME}variablesReturn type: str
-
-
dotfiles.venv.ipython_config.shell_quote(var)[source]¶ Escape single quotes and add double quotes around a given variable.
Parameters: _str (str) – string to add quotes to Returns: string wrapped in quotes Return type: str Warning
This is not safe for untrusted input and only valid in this context (
os.environ).
-
dotfiles.venv.ipython_config.shell_varquote(str_)[source]¶ Add doublequotes and shell variable brackets to a string
Parameters: str (str) – string to varquote (e.g. VIRTUAL_ENV)Returns: “${VIRTUAL_ENV}” Return type: str
-
class
dotfiles.venv.ipython_config.Venv(VENVSTR=None, VENVSTRAPP=None, _Venv__WRK=None, _Venv__DOTFILES=None, WORKON_HOME=None, VIRTUAL_ENV_NAME=None, VENVPREFIX=None, VIRTUAL_ENV=None, _SRC=None, _APP=None, _WRD=None, env=None, from_environ=False, open_editors=False, open_terminals=False, dont_reflect=True, debug=False, show_diffs=False, **kwargs)[source]¶ Bases:
objectA virtual environment configuration generator
-
build(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, from_environ=False, dont_reflect=True, debug=False, show_diffs=False, build_user_aliases=False, build_userlog_env=False)[source]¶ Build
VenvStepswithStepBuilder
-
static
parse_VENVSTR(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, _Venv__WRK=None, WORKON_HOME=None, from_environ=False, **kwargs)[source]¶ Get the path to a virtualenv given a
VENVSTRKeyword Arguments: - env (Env) –
- VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) –
- VENVPREFIX (str) –
- WORKON_HOME (str) –
- from_environ (bool) – whether to try and read from
os.environ["VIRTUAL_ENV"]
Returns: a path to a virtualenv (for
$VIRTUAL_ENV)Return type: str
-
aliases¶ Returns: OrderedDict: self.env.aliases
-
classmethod
workon(env=None, VENVSTR=None, VENVSTRAPP=None, **kwargs)[source]¶ Parameters: - VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) – e.g.
dotfilesordotfiles/docs - kwargs (dict) – kwargs to pass to Venv (see
Venv.__init__)
Returns: an intialized
VenvReturn type: - VENVSTR (str) – a path to a virtualenv containing
-
configure_ipython(*args, **kwargs)[source]¶ Configure IPython with
Venv._configure_ipythonanduser_aliasesfromself.aliases.items().Parameters: - args (list) – args for
Venv._configure_ipython - kwargs (dict) – kwargs for
Venv._configure_ipython.
- args (list) – args for
-
generate_bash_env(shell_keyword='export ', shell_quotefunc=<function shell_quote>, include_paths=True, include_aliases=True, include_cdaliases=False, **kwargs)[source]¶ Generate a
source-able script for the environment variables, aliases, and functions defined by the currentVenv.Keyword Arguments: - shell_keyword (str) – shell variable def (default: “export “)
- include_paths (bool) – Include environ vars in output (default: True)
- include_aliases (bool) – Include aliases in output (default: True)
- include_cdaliases (bool) – Include cdaliases in output (default: False)
- compress_paths (bool) – Compress paths to $VAR (default=False)
Yields: str – block of bash script
-
generate_bash_cdalias()[source]¶ Generate a
source-able script for cdalias functionsYields: str – block of bash script
-
generate_vim_cdalias()[source]¶ Generate a
source-able vimscript for vimYields: str – block of vim script
-
generate_venv_ipymagics()[source]¶ Generate an
venv_ipymagics.pyfile for IPythonYields: str – block of Python code
-
project_files¶
-
PROJECT_FILES¶
-
system(cmd=None)[source]¶ Call
os.systemwith the given command stringParameters: cmd (string) – command string to call
os.systemwithRaises: - Exception – if
cmdis None - NotImplementedError – if
cmdis a tuple
- Exception – if
-
to_json(indent=None)[source]¶ Parameters: indent (int) – number of spaces with which to indent JSON output Returns: json.dumps(self.to_dict()) Return type: str
-
-
dotfiles.venv.ipython_config.ipython_main()[source]¶ Configure IPython with
Venv:py:method:`configure_ipython` (:py:method:`_configure_ipython`).
-
dotfiles.venv.ipython_config.ipython_imports()[source]¶ Default imports for IPython (currently unused)
-
class
dotfiles.venv.ipython_config.VenvTestUtils[source]¶ Bases:
objectTest fixtures for TestCases and examples
-
class
dotfiles.venv.ipython_config.Test_001_lookup(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.ipython_config.Test_100_Env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.ipython_config.Test_200_StepBuilder(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.ipython_config.Test_250_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.ipython_config.Test_300_venv_build_env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCasetest each build step independently
kwargs = {} env = env.copy() buildfunc = build_virtualenvwrapper_env new_env = buildfunc(env=env, **kwargs)
-
class
dotfiles.venv.ipython_config.Test_500_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.ipython_config.Test_900_Venv_main(methodName='runTest')[source]¶ Bases:
dotfiles.venv.ipython_config.VenvTestCase,unittest.case.TestCase
-
dotfiles.venv.ipython_config.build_venv_arg_parser()[source]¶ Returns: options for the commandline interface Return type: optparse.OptionParser
dotfiles.venv.ipython_magics module¶
-
dotfiles.venv.ipython_magics.magics_class(cls, *args, **kwargs)¶
-
dotfiles.venv.ipython_magics.line_magic(func, *args, **kwargs)¶
dotfiles.venv.venv module¶
-
dotfiles.venv.venv.in_venv_ipyconfig()[source]¶ Returns: True if get_ipythonis inglobals()Return type: bool
-
dotfiles.venv.venv.logevent(event, obj=None, logger=<Logger venv (WARNING)>, level=10, func=None, lineno=None, modpath=None, show_modpath=None, wrap=False, splitlines=True)[source]¶ Parameters: - event (str) – an event key
- obj (thing) – thing to serialize and log
- logger (logging.Logger) – logger to log to
- level (int) – logging loglevel to log (event, obj)
- wrap (bool) – Add header and footer <event> tags (default: False)
- splitlines (bool) – split by newlines and emit one log message per line
Returns: (event:str, output:str)
Return type: tuple
-
exception
dotfiles.venv.venv.StepConfigException[source]¶ Bases:
dotfiles.venv.venv.StepException,dotfiles.venv.venv.ConfigException
-
dotfiles.venv.venv.prepend_comment_char(strblock, commentchar='##')[source]¶ Parameters: - strblock (str) – string to split by newlines and prepend
- prefix (str) – comment string prefix (one space will be added)
Yields: str – lines prefixed with prefix
-
dotfiles.venv.venv.get_pyver(pyverstr=None)[source]¶ Parameters: pyver (str) – “major.minor” e.g. 2.7or3.4(default:sys.version_info[:2])Returns: python2.7,python.34Return type: str
-
dotfiles.venv.venv.get_WORKON_HOME_default(env=None, from_environ=False, default='-ve27', **kwargs)[source]¶ Keyword Arguments: - env (dict) – Env dict to read from (default: None)
- from_environ (bool) – read WORKON_HOME from os.environ
- default (str) – default WORKON_HOME dirname
- __WRK (str) –
Returns: path to a
WORKON_HOMEdirectoryReturn type: str
-
class
dotfiles.venv.venv.VenvJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder-
default(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
dotfiles.venv.venv.CmdAlias(cmdstr)[source]¶ Bases:
object
-
class
dotfiles.venv.venv.IpyAlias(cmdstr, name=None, complfuncstr=None)[source]¶ Bases:
dotfiles.venv.venv.CmdAliasAn IPython alias command string which expands to a shell function
aliasname() { ... }and handles positional args%sand%lReferences
- TODO: IPython docs
-
class
dotfiles.venv.venv.CdAlias(pathvar, name=None, aliases=None)[source]¶ Bases:
dotfiles.venv.venv.CmdAliasA CmdAlias for
cdchange directory functions with venv paths (e.g. $_WRD) for Bash, ZSH, IPython, Vim.- venv.sh bash functions with tab-completion (cdwrd, cdw, cdw<tab>)
- venv_ipymagics.py: ipython magics (%cdwrd, cdwrd, cdw)
- venv.vim: vim functions (:Cdwrd)
-
VENV_IPYMAGICS_FILE_HEADER= '\n#!/usr/bin/env ipython\n# dotfiles.venv.venv_ipymagics\nfrom __future__ import print_function\n"""\nIPython ``%magic`` commands\n\n* ``cd`` aliases\n* ``ds`` (``dotfiles_status``)\n* ``dr`` (``dotfiles_reload``)\n\nInstallation\n--------------\n.. code-block:: bash\n\n __DOTFILES="${HOME}/-dotfiles"\n ipython_profile="profile_default"\n ln -s ${__DOTFILES}/etc/ipython/venv_ipymagics.py \\\n ~/.ipython/${ipython_profile}/startup/venv_ipymagics.py\n"""\nimport os\nimport sys\ntry:\n from IPython.core.magic import (Magics, magics_class, line_magic)\nexcept ImportError:\n print("ImportError: IPython")\n # Mock IPython for building docs\n Magics = object\n magics_class = lambda cls, *args, **kwargs: cls\n line_magic = lambda func, *args, **kwargs: func\n\nif sys.version_info.major == 2:\n str = unicode\n\ndef ipymagic_quote(_str):\n return str(_str)\n\n@magics_class\nclass VenvMagics(Magics):\n def cd(self, envvar, line):\n """\n Change directory\n\n Args:\n envvar (str): os.environ variable name\n line (str): path to append to envvar\n """\n prefix = os.environ.get(envvar, "")\n _dstpath = line.lstrip(os.path.sep)\n path = os.path.join(prefix, _dstpath)\n cmd = ("cd %s" % ipymagic_quote(path))\n print("%" + cmd, file=sys.stderr)\n return self.shell.magic(cmd)'¶
-
VENV_IPYMAGIC_METHOD_TEMPLATE= '\n @line_magic\n def {ipy_func_name}(self, line):\n """{ipy_func_name} -- cd ${pathvar}/${{@}}"""\n return self.cd(\'{pathvar}\', line)'¶
-
VENV_IPYMAGICS_FOOTER= '\n @line_magic\n def cdhelp(self, line):\n """cdhelp() -- list cd commands"""\n for cdfunc in dir(self):\n if cdfunc.startswith(\'cd\') and cdfunc not in (\'cdhelp\',\'cd\'):\n docstr = getattr(self, cdfunc).__doc__.split(\'--\',1)[-1].strip()\n print("%%%-16s -- %s" % (cdfunc, docstr))\n\n @staticmethod\n def _dotfiles_status():\n """\n Print ``dotfiles_status``: venv variables\n """\n env_vars = [\n \'HOSTNAME\',\n \'USER\',\n \'PROJECT_HOME\',\n \'CONDA_ROOT\',\n \'CONDA_ENVS_PATH\',\n \'WORKON_HOME\',\n \'VIRTUAL_ENV_NAME\',\n \'VIRTUAL_ENV\',\n \'_USRLOG\',\n \'_TERM_ID\',\n \'_SRC\',\n \'_APP\',\n \'_WRD\',\n \'PATH\',\n \'__DOTFILES\',\n ]\n environ = dict((var, os.environ.get(var)) for var in env_vars)\n environ[\'HOSTNAME\'] = __import__(\'socket\').gethostname()\n for var in env_vars:\n print(\'{}="{}"\'.format(var, "%s" % environ.get(var,\'\')))\n\n @line_magic\n def dotfiles_status(self, line):\n """dotfiles_status() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @line_magic\n def ds(self, line):\n """ds() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @staticmethod\n def _dotfiles_reload():\n """_dotfiles_reload() -- print NotImplemented"""\n print("NotImplemented: dotfiles_reload()")\n\n @line_magic\n def dotfiles_reload(self, line):\n """dotfiles_reload() -- print NotImplemented"""\n return self._dotfiles_reload()\n\n @line_magic\n def dr(self, line):\n """dr() -- print NotImplemented [dotfiles_reload()]"""\n return self._dotfiles_reload()\n\n\ndef main():\n """\n Register VenvMagics with IPython\n """\n import IPython\n ip = IPython.get_ipython()\n ip.register_magics(VenvMagics)\n\n\nif __name__ == "__main__":\n main()\n'¶
-
to_ipython_method()[source]¶ Keyword Arguments: include_completions (bool) – generate inline Bash completions Returns: ipython method block Return type: str
-
VIM_HEADER_TEMPLATE= '\n" ### venv.vim\n" # Src: https://github.com/westurner/venv.vim\n\n" "g:venv_list_only_dirs -- 1 -- 0 to list files in Cd* commands\n\nlet g:venv_list_only_dirs = 1\n\nfunction! Cd_help()\n" :Cdhelp -- list venv.vim cdalias commands\n :verbose command Cd\nendfunction\ncommand! -nargs=0 Cdhelp call Cd_help()\n\nfunction! ListDirsOrFiles(path, ArgLead, ...)\n let dirsonly = ((a:0>0) ? 1 : g:venv_list_only_dirs)\n let _glob = \'\' . a:ArgLead . ((g:venv_list_only_dirs>1) ? \'*/\' : \'*\')\n execute \'lcd\' a:path\n if dirsonly ==? 1\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:]\')\n elseif dirsonly ==? 0\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:] . (isdirectory(v:val) ? "/" : "")\')\n endif\n execute \'lcd -\'\n return output\nendfunction\n\nfunction! Cdhere(...)\n" :Cdhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n" :CDhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'cd\' _path\n pwd\nendfunction\nfunction! Compl_Cdhere(ArgLead, ...)\n return ListDirsOrFiles(expand(\'%:p:h\'), a:ArgLead, 1)\nendfor\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Cdhere call Cdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere CDhere call Cdhere(<f-args>)\n\nfunction! Lcdhere(...)\n" :Lcdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n" :LCdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'lcd\' _path\n pwd\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Lcdhere call Lcdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere LCdhere call Lcdhere(<f-args>)\n\n\nfunction! Cd___VAR_(varname, cmd, ...)\n" Cd___VAR_() -- cd expand(\'$\' . a:varname)/$1\n let _VARNAME = a:varname\n let _VAR_=expand(_VARNAME)\n if _VARNAME ==? _VAR_\n echoerr _VARNAME . " is not set"\n return\n endif\n let pathname = join([_VAR_, (a:0>0) ? a:1 : ""], "/")\n execute a:cmd pathname\n pwd\nendfunction\n\n'¶
-
VIM_CD_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- cd ${pathvar}/$1\n call Cd___VAR_(\'${pathvar}\', \'{vim_cd_func}\', (a:0>0)? a:1 : "")\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 1)\nendfunction\n'¶
-
VIM_CD_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- cd ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
VIM_EDIT_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- e ${pathvar}/$1\n let _path=expand("${pathvar}") . ((a:0>0)? "/" . a:1 : "")\n execute \'{vim_edit_func}\' _path\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 0)\nendfunction\n'¶
-
VIM_EDIT_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- e ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
vim_cmd_name¶ Returns: str: e.g “Cdwrd”
-
vim_cmd_names¶ Returns: list: self.vim_cmd_name + self.aliases.title()
-
BASH_CDALIAS_HEADER= '#!/bin/sh\n## venv.sh\n# generated from $(venv --print-bash --prefix=/)\n\n'¶
-
BASH_FUNCTION_TEMPLATE= '{bash_func_name} () {{\n # {bash_func_name:16} -- cd ${pathvar} /$@\n [ -z "${pathvar}" ] && echo "{pathvar} is not set" && return 1\n cd "${pathvar}"${{@:+"/${{@}}"}}\n}}\n{bash_compl_name} () {{\n local cur="$2";\n COMPREPLY=($({bash_func_name} && compgen -d -- "${{cur}}" ))\n}}\n'¶
-
BASH_ALIAS_TEMPLATE= '{cmd_name} () {{\n # {cmd_name:16} -- cd ${pathvar}\n {bash_func_name} $@\n}}\n'¶
-
BASH_COMPLETION_TEMPLATE= 'complete -o default -o nospace -F {bash_compl_name} {cmd_name}\n'¶
-
bash_func_name¶ Returns: str: e.g. “cdwrd”
-
bash_func_names¶ Returns: list: self.bash_func_name + self.aliases
-
class
dotfiles.venv.venv.Step(func=None, **kwargs)[source]¶ Bases:
objectA build task step which builds or transforms an
Env, by callingstep.build(env=env, **step.conf)-
name¶ Returns: str: a name for this Step
-
build_print_kwargs_env(env=None, **kwargs)[source]¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
DEFAULT_FUNC(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.venv.PrintEnvStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.venv.StepPrint env and kwargs to stdout
-
stdout= <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>¶
-
stderr= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.venv.PrintEnvStderrStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.venv.PrintEnvStepPrint env and kwargs to stderr
-
stdout= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
-
class
dotfiles.venv.venv.StepBuilder(**kwargs)[source]¶ Bases:
objectA class for building a sequence of steps which modify env
-
name¶
-
debug¶ Returns: str: self.conf.get(‘debug’)
-
show_diffs¶ Returns: str: self.conf.get(‘show_diffs’)
-
add_step(func, **kwargs)[source]¶ Add a step to
self.stepsParameters: - func (Step or function or str) –
func(env=None, **kwargs) - kwargs (dict) – kwargs for Step.conf
Keyword Arguments: name (str) – function name (default: None)
Returns: Step object appended to self.steps
Return type: Step- func (Step or function or str) –
-
build_iter(env=None, show_diffs=True, debug=False)[source]¶ Build a generator of (Step, Env) tuples from the functional composition of StepBuilder.steps given an initial
Env(or None).# pseudocode env_previous = Env() for step in self.steps: (step, env) = step.build(env=env_previous.copy(),**conf) env_previous=env
Keyword Arguments: - env (Env) – initial Env (default: None)
- show_diffs (bool) – show difflib.ndiffs of Envs between steps
- debug (bool) –
Yields: tuple – (
Step,Env)
-
-
dotfiles.venv.venv.lookup_from_kwargs_env(kwargs, env, attr, default=None)[source]¶ __getitem__ from kwargs, env, or default.
Parameters: - kwargs (dict) – kwargs dict
- env (Env) –
Envdict - attr (str) – attribute name
- default (obj) – default value to return if not found in kwargs or env
Returns: kwargs.get(attr, env.get(attr, default))
Return type: obj
-
dotfiles.venv.venv.build_dotfiles_env(env=None, **kwargs)[source]¶ Configure dotfiles base environment (HOME, __WRK, __SRC, __DOTFILES)
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - HOME (str) – home path (
$HOME,~) - __WRK (str) – workspace path (
$__WRK,~/-wrk) - __SRC (str) – path to source repos (
$__WRK/-src) - __DOTFILES (str) – current dotfiles path (
~/-dotfiles)
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- HOME
- __WRK
- __SRC
- __DOTFILES
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.venv.build_virtualenvwrapper_env(env=None, **kwargs)[source]¶ Set WORKON_HOME to WORKON_HOME or WORKON_HOME_DEFAULT
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - __WRK (str) – workspace path (
$__WRK,~/-wrk) - WORKON_HOME_DEFAULT (str) – variable name (default:
WORKON_HOME__py27) - WORKON_HOME__* (str) – path to a WORKON_HOME set
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- WORKON_HOME__py27=’${__WRK}/-ve27’
- WORKON_HOME__py34=’${__WRK}/-ve34’
- WORKON_HOME__*=kwargs.get(WORKON_HOME__*)
- WORKON_HOME_DEFAULT=’WORKON_HOME_py27’
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.venv.build_conda_env(env=None, **kwargs)[source]¶ Configure conda27 (2.7) and conda (3.4) with condaenvs in
-wrk/-ce27and-wrk/ce34.Other Parameters: - __WRK (str) – workspace root (
$__WRK,~/-wrk) - CONDA_ROOT__py27 (str) – path to conda27 root environment
- CONDA_ENVS__py27 (str) – path to conda27 envs (e.g. WORKON_HOME)
- CONDA_ROOT__py34 (str) – path to conda34 root environment
- CONDA_ENVS__py34 (str) – path to conda34 envs (e.g. WORKON_HOME)
Keyword Arguments: env (Env dict) –
dotfiles.venv.venv_ipyconfig.EnvReturns: Return type: env (Env dict)
- __WRK (str) – workspace root (
-
dotfiles.venv.venv.build_conda_cfg_env(env=None, **kwargs)[source]¶ Configure conda for a specific environment TODO build_venv_config
Parameters: env (Env dict) – dotfiles.venv.venv_ipyconfig.EnvReturns: dotfiles.venv.venv_ipyconfig.EnvReturn type: env (Env dict)
-
dotfiles.venv.venv.build_venv_paths_full_env(env=None, pyver=None, **kwargs)[source]¶ Set variables for standard paths in the environment
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env(default: None (Env())) - VENVPREFIX (str) – venv prefix path (default: None (VIRTUAL_ENV))
- VENVSTR (str) – name of a VIRTUAL_ENV in WORKON_HOME or path to a VIRTUAL_ENV (default: None)
- VIRTUAL_ENV (str) – path to a VIRTUAL_ENV (default: None)
Returns: Return type: env (Env dict)
Raises: StepConfigException – When not any(( VIRTUAL_ENV, VENVPREFIX, VENVSTR, VENVSTRAPP))
References
- env (Env dict) –
-
dotfiles.venv.venv.build_venv_paths_cdalias_env(env=None, **kwargs)[source]¶ Build CdAliases for standard paths
Keyword Arguments: env (Env dict) – EnvReturns: Envwith.aliasesextended.Return type: env (Env dict) Note
These do not work in IPython as they run in a subshell. See:
dotfiles.venv.venv_ipymagics.
-
dotfiles.venv.venv.build_user_aliases_env(env=None, dont_reflect=False, VIRTUAL_ENV=None, _SRC=None, _ETC=None, _CFG=None, PROJECT_FILES=None, **kwargs)[source]¶ Configure env variables and return an OrderedDict of aliases
Parameters: dont_reflect (bool) – Whether to always create aliases and functions referencing $_WRDeven if$_WRDdoesn’t exist. (default: False)Returns: dict of aliases Return type: OrderedDict
-
dotfiles.venv.venv.build_usrlog_env(env=None, _TERM_ID=None, shell='bash', prefix=None, USER=None, HOSTNAME=None, lookup_hostname=False, **kwargs)[source]¶ Build environment variables and configuration like usrlog.sh
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - _TERM_ID (str) – terminal identifier string
- shell (str) – shell name (“bash”, “zsh”)
- prefix (str) – a path prefix (e.g.
$VIRTUAL_ENVor$PREFIX) - USER (str) – system username (
$USER) forHISTTIMEFORMAT - HOSTNAME (str) – system hostname (
HOSTNAME) forHISTTIMEFORMAT - lookup_hostname (bool) – if True,
HOSTNAMEis None, and not env.get(‘HOSTNAME’), try to readHOSTNAMEfromos.environand thensocket.gethostname().
Returns: Return type: env (Env dict)
Note
Like
usrlog.sh, whenHISTTIMEFORMATis set,USERandHOSTNAMEmust be evaluated.(When
USERandHOSTNAMEchange,HISTTIMEFORMATis not updated, and the .history file will contain only the most recent USER and HOSTNAME settings, which are not necessarily the actual USER and HOSTNAME.)TODO: could/should instead (also) write USER and HOSTNAME to -usrlog.log.
- env (Env dict) –
-
dotfiles.venv.venv.build_venv_activate_env(env=None, VENVSTR=None, VENVSTRAPP=None, from_environ=False, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, **kwargs)[source]¶
-
class
dotfiles.venv.venv.Env(*args, **kwargs)[source]¶ Bases:
objectOrderedDict of variables for/from
os.environ.-
osenviron_keys_classic= ('VIMBIN', 'GVIMBIN', 'MVIMBIN', 'GUIVIMBIN', 'VIMCONF', 'EDITOR', 'EDITOR_', 'PAGER', '__WRK', '__DOTFILES', 'PROJECT_HOME', 'WORKON_HOME', 'WORKON_HOME__py27', 'WORKON_HOME__py34', 'VENVPREFIX', 'VENVSTR', 'VENVSTRAPP', '_APP', 'VIRTUAL_ENV_NAME', 'VIRTUAL_ENV', '_SRC', '_ETC', '_BIN', '_CFG', '_LIB', '_LOG', '_MNT', '_OPT', '_PYLIB', '_PYSITE', '_SRV', '_VAR', '_WRD', '_WRD_SETUPY', '_WWW', '__SRC', '__DOCSWWW', '_USRLOG', '__USRLOG', '_TERM_ID', '_TERM_URI')¶
-
osenviron_keys= {'CONDA_ENVS_PATH': '${__WRK}/-ce27', 'CONDA_ENVS__py27': '${__WRK}/-ce27', 'CONDA_ENVS__py34': '${__WRK}/-ce34', 'CONDA_ENVS__py35': '${__WRK}/-ce35', 'CONDA_ENVS__py36': '${__WRK}/-ce36', 'CONDA_ENVS__py37': '${__WRK}/-ce37', 'CONDA_ROOT': '${__WRK}/-conda27', 'CONDA_ROOT__py27': '${__WRK}/-conda27', 'CONDA_ROOT__py34': '${__WRK}/-conda34', 'CONDA_ROOT__py35': '${__WRK}/-conda35', 'CONDA_ROOT__py36': '${__WRK}/-conda36', 'CONDA_ROOT__py37': '${__WRK}/-conda37', 'PROJECT_HOME': '${__WRK}', 'VENVPREFIX': '${VIRTUAL_ENV}', 'VENVSTR': 'dotfiles', 'VENVSTRAPP': 'dotfiles', 'VIRTUAL_ENV': '${WORKON_HOME}/${VIRTUAL_ENV_NAME}', 'VIRTUAL_ENV_NAME': 'dotfiles', 'WORKON_HOME': '${__WRK}/-ve27', 'WORKON_HOME_DEFAULT': 'WORKON_HOME__py37', 'WORKON_HOME__py27': '${__WRK}/-ve27', 'WORKON_HOME__py34': '${__WRK}/-ve34', 'WORKON_HOME__py35': '${__WRK}/-ve35', 'WORKON_HOME__py36': '${__WRK}/-ve36', 'WORKON_HOME__py37': '${__WRK}/-ve37', '_APP': 'dotfiles', '_BIN': '${VIRTUAL_ENV}/bin', '_ETC': '${VIRTUAL_ENV}/etc', '_ETCOPT': '${_ETC}/opt', '_HOME': '${VIRTUAL_ENV}/home', '_LIB': '${VIRTUAL_ENV}/lib', '_LOG': '${_VAR}/log', '_MEDIA': '${VIRTUAL_ENV}/media', '_MNT': '${VIRTUAL_ENV}/mnt', '_OPT': '${VIRTUAL_ENV}/opt', '_PYLIB': '${_LIB}/python2.7', '_PYSITE': '${_PYLIB}/site-packages', '_ROOT': '${VIRTUAL_ENV}/root', '_SBIN': '${VIRTUAL_ENV}/sbin', '_SRC': '${VIRTUAL_ENV}/src', '_SRV': '${VIRTUAL_ENV}/srv', '_TMP': '${VIRTUAL_ENV}/tmp', '_USR': '${VIRTUAL_ENV}/usr', '_USRBIN': '${VIRTUAL_ENV}/usr/bin', '_USRINCLUDE': '${VIRTUAL_ENV}/usr/include', '_USRLIB': '${VIRTUAL_ENV}/usr/lib', '_USRLOCAL': '${VIRTUAL_ENV}/usr/local', '_USRLOCALBIN': '${VIRTUAL_ENV}/usr/local/bin', '_USRSBIN': '${VIRTUAL_ENV}/usr/sbin', '_USRSHARE': '${VIRTUAL_ENV}/usr/share', '_USRSRC': '${VIRTUAL_ENV}/usr/src', '_VAR': '${VIRTUAL_ENV}/var', '_VARCACHE': '${_VAR}/cache', '_VARLIB': '${_VAR}/lib', '_VARLOCK': '${_VAR}/lock', '_VARMAIL': '${_VAR}/mail', '_VAROPT': '${_VAR}/opt', '_VARRUN': '${_VAR}/run', '_VARSPOOL': '${_VAR}/spool', '_VARTMP': '${_VAR}/tmp', '_WRD': '${_SRC}/dotfiles', '_WWW': '${_VAR}/www', '__DOTFILES': '${HOME}/-dotfiles', '__SRC': '${__WRK}/-src', '__WRK': '${HOME}/-wrk'}¶
-
name¶
-
classmethod
from_environ(environ, verbose=False)[source]¶ Build an
Envfrom a dict (e.g.os.environ)Parameters: - environ (dict) – a dict with variable name keys and values
- verbose (bool) – whether to be verbose about dict merging
Returns: an Env environment built from the given environ dict
Return type:
-
compress_paths(path_, keys=None, keyname=None)[source]¶ Given an arbitrary string, replace absolute paths (starting with ‘/’) with the longest matching Env path variables.
Parameters: path (str) – a path string Returns: path string containing ${VARNAME}variablesReturn type: str
-
-
dotfiles.venv.venv.shell_quote(var)[source]¶ Escape single quotes and add double quotes around a given variable.
Parameters: _str (str) – string to add quotes to Returns: string wrapped in quotes Return type: str Warning
This is not safe for untrusted input and only valid in this context (
os.environ).
-
dotfiles.venv.venv.shell_varquote(str_)[source]¶ Add doublequotes and shell variable brackets to a string
Parameters: str (str) – string to varquote (e.g. VIRTUAL_ENV)Returns: “${VIRTUAL_ENV}” Return type: str
-
class
dotfiles.venv.venv.Venv(VENVSTR=None, VENVSTRAPP=None, _Venv__WRK=None, _Venv__DOTFILES=None, WORKON_HOME=None, VIRTUAL_ENV_NAME=None, VENVPREFIX=None, VIRTUAL_ENV=None, _SRC=None, _APP=None, _WRD=None, env=None, from_environ=False, open_editors=False, open_terminals=False, dont_reflect=True, debug=False, show_diffs=False, **kwargs)[source]¶ Bases:
objectA virtual environment configuration generator
-
build(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, from_environ=False, dont_reflect=True, debug=False, show_diffs=False, build_user_aliases=False, build_userlog_env=False)[source]¶ Build
VenvStepswithStepBuilder
-
static
parse_VENVSTR(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, _Venv__WRK=None, WORKON_HOME=None, from_environ=False, **kwargs)[source]¶ Get the path to a virtualenv given a
VENVSTRKeyword Arguments: - env (Env) –
- VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) –
- VENVPREFIX (str) –
- WORKON_HOME (str) –
- from_environ (bool) – whether to try and read from
os.environ["VIRTUAL_ENV"]
Returns: a path to a virtualenv (for
$VIRTUAL_ENV)Return type: str
-
aliases¶ Returns: OrderedDict: self.env.aliases
-
classmethod
workon(env=None, VENVSTR=None, VENVSTRAPP=None, **kwargs)[source]¶ Parameters: - VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) – e.g.
dotfilesordotfiles/docs - kwargs (dict) – kwargs to pass to Venv (see
Venv.__init__)
Returns: an intialized
VenvReturn type: - VENVSTR (str) – a path to a virtualenv containing
-
configure_ipython(*args, **kwargs)[source]¶ Configure IPython with
Venv._configure_ipythonanduser_aliasesfromself.aliases.items().Parameters: - args (list) – args for
Venv._configure_ipython - kwargs (dict) – kwargs for
Venv._configure_ipython.
- args (list) – args for
-
generate_bash_env(shell_keyword='export ', shell_quotefunc=<function shell_quote>, include_paths=True, include_aliases=True, include_cdaliases=False, **kwargs)[source]¶ Generate a
source-able script for the environment variables, aliases, and functions defined by the currentVenv.Keyword Arguments: - shell_keyword (str) – shell variable def (default: “export “)
- include_paths (bool) – Include environ vars in output (default: True)
- include_aliases (bool) – Include aliases in output (default: True)
- include_cdaliases (bool) – Include cdaliases in output (default: False)
- compress_paths (bool) – Compress paths to $VAR (default=False)
Yields: str – block of bash script
-
generate_bash_cdalias()[source]¶ Generate a
source-able script for cdalias functionsYields: str – block of bash script
-
generate_vim_cdalias()[source]¶ Generate a
source-able vimscript for vimYields: str – block of vim script
-
generate_venv_ipymagics()[source]¶ Generate an
venv_ipymagics.pyfile for IPythonYields: str – block of Python code
-
project_files¶
-
PROJECT_FILES¶
-
system(cmd=None)[source]¶ Call
os.systemwith the given command stringParameters: cmd (string) – command string to call
os.systemwithRaises: - Exception – if
cmdis None - NotImplementedError – if
cmdis a tuple
- Exception – if
-
to_json(indent=None)[source]¶ Parameters: indent (int) – number of spaces with which to indent JSON output Returns: json.dumps(self.to_dict()) Return type: str
-
-
dotfiles.venv.venv.ipython_main()[source]¶ Configure IPython with
Venv:py:method:`configure_ipython` (:py:method:`_configure_ipython`).
-
class
dotfiles.venv.venv.VenvTestUtils[source]¶ Bases:
objectTest fixtures for TestCases and examples
-
class
dotfiles.venv.venv.Test_001_lookup(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv.Test_100_Env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv.Test_200_StepBuilder(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv.Test_250_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv.Test_300_venv_build_env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCasetest each build step independently
kwargs = {} env = env.copy() buildfunc = build_virtualenvwrapper_env new_env = buildfunc(env=env, **kwargs)
-
class
dotfiles.venv.venv.Test_500_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv.Test_900_Venv_main(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv.VenvTestCase,unittest.case.TestCase
-
dotfiles.venv.venv.build_venv_arg_parser()[source]¶ Returns: options for the commandline interface Return type: optparse.OptionParser
dotfiles.venv.venv_ipyconfig module¶
-
dotfiles.venv.venv_ipyconfig.in_venv_ipyconfig()[source]¶ Returns: True if get_ipythonis inglobals()Return type: bool
-
dotfiles.venv.venv_ipyconfig.logevent(event, obj=None, logger=<Logger venv (WARNING)>, level=10, func=None, lineno=None, modpath=None, show_modpath=None, wrap=False, splitlines=True)[source]¶ Parameters: - event (str) – an event key
- obj (thing) – thing to serialize and log
- logger (logging.Logger) – logger to log to
- level (int) – logging loglevel to log (event, obj)
- wrap (bool) – Add header and footer <event> tags (default: False)
- splitlines (bool) – split by newlines and emit one log message per line
Returns: (event:str, output:str)
Return type: tuple
-
exception
dotfiles.venv.venv_ipyconfig.StepConfigException[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.StepException,dotfiles.venv.venv_ipyconfig.ConfigException
-
dotfiles.venv.venv_ipyconfig.prepend_comment_char(strblock, commentchar='##')[source]¶ Parameters: - strblock (str) – string to split by newlines and prepend
- prefix (str) – comment string prefix (one space will be added)
Yields: str – lines prefixed with prefix
-
dotfiles.venv.venv_ipyconfig.get_pyver(pyverstr=None)[source]¶ Parameters: pyver (str) – “major.minor” e.g. 2.7or3.4(default:sys.version_info[:2])Returns: python2.7,python.34Return type: str
-
dotfiles.venv.venv_ipyconfig.get_WORKON_HOME_default(env=None, from_environ=False, default='-ve27', **kwargs)[source]¶ Keyword Arguments: - env (dict) – Env dict to read from (default: None)
- from_environ (bool) – read WORKON_HOME from os.environ
- default (str) – default WORKON_HOME dirname
- __WRK (str) –
Returns: path to a
WORKON_HOMEdirectoryReturn type: str
-
class
dotfiles.venv.venv_ipyconfig.VenvJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder-
default(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
dotfiles.venv.venv_ipyconfig.CmdAlias(cmdstr)[source]¶ Bases:
object
-
class
dotfiles.venv.venv_ipyconfig.IpyAlias(cmdstr, name=None, complfuncstr=None)[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.CmdAliasAn IPython alias command string which expands to a shell function
aliasname() { ... }and handles positional args%sand%lReferences
- TODO: IPython docs
-
class
dotfiles.venv.venv_ipyconfig.CdAlias(pathvar, name=None, aliases=None)[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.CmdAliasA CmdAlias for
cdchange directory functions with venv paths (e.g. $_WRD) for Bash, ZSH, IPython, Vim.- venv.sh bash functions with tab-completion (cdwrd, cdw, cdw<tab>)
- venv_ipymagics.py: ipython magics (%cdwrd, cdwrd, cdw)
- venv.vim: vim functions (:Cdwrd)
-
VENV_IPYMAGICS_FILE_HEADER= '\n#!/usr/bin/env ipython\n# dotfiles.venv.venv_ipymagics\nfrom __future__ import print_function\n"""\nIPython ``%magic`` commands\n\n* ``cd`` aliases\n* ``ds`` (``dotfiles_status``)\n* ``dr`` (``dotfiles_reload``)\n\nInstallation\n--------------\n.. code-block:: bash\n\n __DOTFILES="${HOME}/-dotfiles"\n ipython_profile="profile_default"\n ln -s ${__DOTFILES}/etc/ipython/venv_ipymagics.py \\\n ~/.ipython/${ipython_profile}/startup/venv_ipymagics.py\n"""\nimport os\nimport sys\ntry:\n from IPython.core.magic import (Magics, magics_class, line_magic)\nexcept ImportError:\n print("ImportError: IPython")\n # Mock IPython for building docs\n Magics = object\n magics_class = lambda cls, *args, **kwargs: cls\n line_magic = lambda func, *args, **kwargs: func\n\nif sys.version_info.major == 2:\n str = unicode\n\ndef ipymagic_quote(_str):\n return str(_str)\n\n@magics_class\nclass VenvMagics(Magics):\n def cd(self, envvar, line):\n """\n Change directory\n\n Args:\n envvar (str): os.environ variable name\n line (str): path to append to envvar\n """\n prefix = os.environ.get(envvar, "")\n _dstpath = line.lstrip(os.path.sep)\n path = os.path.join(prefix, _dstpath)\n cmd = ("cd %s" % ipymagic_quote(path))\n print("%" + cmd, file=sys.stderr)\n return self.shell.magic(cmd)'¶
-
VENV_IPYMAGIC_METHOD_TEMPLATE= '\n @line_magic\n def {ipy_func_name}(self, line):\n """{ipy_func_name} -- cd ${pathvar}/${{@}}"""\n return self.cd(\'{pathvar}\', line)'¶
-
VENV_IPYMAGICS_FOOTER= '\n @line_magic\n def cdhelp(self, line):\n """cdhelp() -- list cd commands"""\n for cdfunc in dir(self):\n if cdfunc.startswith(\'cd\') and cdfunc not in (\'cdhelp\',\'cd\'):\n docstr = getattr(self, cdfunc).__doc__.split(\'--\',1)[-1].strip()\n print("%%%-16s -- %s" % (cdfunc, docstr))\n\n @staticmethod\n def _dotfiles_status():\n """\n Print ``dotfiles_status``: venv variables\n """\n env_vars = [\n \'HOSTNAME\',\n \'USER\',\n \'PROJECT_HOME\',\n \'CONDA_ROOT\',\n \'CONDA_ENVS_PATH\',\n \'WORKON_HOME\',\n \'VIRTUAL_ENV_NAME\',\n \'VIRTUAL_ENV\',\n \'_USRLOG\',\n \'_TERM_ID\',\n \'_SRC\',\n \'_APP\',\n \'_WRD\',\n \'PATH\',\n \'__DOTFILES\',\n ]\n environ = dict((var, os.environ.get(var)) for var in env_vars)\n environ[\'HOSTNAME\'] = __import__(\'socket\').gethostname()\n for var in env_vars:\n print(\'{}="{}"\'.format(var, "%s" % environ.get(var,\'\')))\n\n @line_magic\n def dotfiles_status(self, line):\n """dotfiles_status() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @line_magic\n def ds(self, line):\n """ds() -- print dotfiles_status() ."""\n return self._dotfiles_status()\n\n @staticmethod\n def _dotfiles_reload():\n """_dotfiles_reload() -- print NotImplemented"""\n print("NotImplemented: dotfiles_reload()")\n\n @line_magic\n def dotfiles_reload(self, line):\n """dotfiles_reload() -- print NotImplemented"""\n return self._dotfiles_reload()\n\n @line_magic\n def dr(self, line):\n """dr() -- print NotImplemented [dotfiles_reload()]"""\n return self._dotfiles_reload()\n\n\ndef main():\n """\n Register VenvMagics with IPython\n """\n import IPython\n ip = IPython.get_ipython()\n ip.register_magics(VenvMagics)\n\n\nif __name__ == "__main__":\n main()\n'¶
-
to_ipython_method()[source]¶ Keyword Arguments: include_completions (bool) – generate inline Bash completions Returns: ipython method block Return type: str
-
VIM_HEADER_TEMPLATE= '\n" ### venv.vim\n" # Src: https://github.com/westurner/venv.vim\n\n" "g:venv_list_only_dirs -- 1 -- 0 to list files in Cd* commands\n\nlet g:venv_list_only_dirs = 1\n\nfunction! Cd_help()\n" :Cdhelp -- list venv.vim cdalias commands\n :verbose command Cd\nendfunction\ncommand! -nargs=0 Cdhelp call Cd_help()\n\nfunction! ListDirsOrFiles(path, ArgLead, ...)\n let dirsonly = ((a:0>0) ? 1 : g:venv_list_only_dirs)\n let _glob = \'\' . a:ArgLead . ((g:venv_list_only_dirs>1) ? \'*/\' : \'*\')\n execute \'lcd\' a:path\n if dirsonly ==? 1\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:]\')\n elseif dirsonly ==? 0\n let output = map(sort(globpath(\'.\', _glob, 0, 1), \'i\'), \'v:val[2:] . (isdirectory(v:val) ? "/" : "")\')\n endif\n execute \'lcd -\'\n return output\nendfunction\n\nfunction! Cdhere(...)\n" :Cdhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n" :CDhere -- cd to here (this dir, dirname(__file__)) [cd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'cd\' _path\n pwd\nendfunction\nfunction! Compl_Cdhere(ArgLead, ...)\n return ListDirsOrFiles(expand(\'%:p:h\'), a:ArgLead, 1)\nendfor\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Cdhere call Cdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere CDhere call Cdhere(<f-args>)\n\nfunction! Lcdhere(...)\n" :Lcdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n" :LCdhere -- lcd to here (this dir, dirname(__file__)) [lcd %:p:h]\n let _path = expand(\'%:p:h\') . ((a:0>0) ? (\'/\' . a:1) : \'\')\n execute \'lcd\' _path\n pwd\nendfunction\ncommand! -nargs=* -complete=customlist,Compl_Cdhere Lcdhere call Lcdhere(<f-args>)\ncommand! -nargs=* -complete=customlist,Compl_Cdhere LCdhere call Lcdhere(<f-args>)\n\n\nfunction! Cd___VAR_(varname, cmd, ...)\n" Cd___VAR_() -- cd expand(\'$\' . a:varname)/$1\n let _VARNAME = a:varname\n let _VAR_=expand(_VARNAME)\n if _VARNAME ==? _VAR_\n echoerr _VARNAME . " is not set"\n return\n endif\n let pathname = join([_VAR_, (a:0>0) ? a:1 : ""], "/")\n execute a:cmd pathname\n pwd\nendfunction\n\n'¶
-
VIM_CD_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- cd ${pathvar}/$1\n call Cd___VAR_(\'${pathvar}\', \'{vim_cd_func}\', (a:0>0)? a:1 : "")\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 1)\nendfunction\n'¶
-
VIM_CD_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- cd ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
VIM_EDIT_FUNCTION_TEMPLATE= '\nfunction! {vim_func_name}(...)\n" {vim_func_name}() -- e ${pathvar}/$1\n let _path=expand("${pathvar}") . ((a:0>0)? "/" . a:1 : "")\n execute \'{vim_edit_func}\' _path\nendfunction\nfunction! Compl_{vim_func_name}(ArgLead, ...)\n return ListDirsOrFiles(${pathvar}, a:ArgLead, 0)\nendfunction\n'¶
-
VIM_EDIT_COMMAND_TEMPLATE= '" :{cmd_name:<10} -- e ${pathvar}/$1\ncommand! -nargs=* -complete=customlist,Compl_{vim_func_name} {cmd_name} call {vim_func_name}(<f-args>)\n'¶
-
vim_cmd_name¶ Returns: str: e.g “Cdwrd”
-
vim_cmd_names¶ Returns: list: self.vim_cmd_name + self.aliases.title()
-
BASH_CDALIAS_HEADER= '#!/bin/sh\n## venv.sh\n# generated from $(venv --print-bash --prefix=/)\n\n'¶
-
BASH_FUNCTION_TEMPLATE= '{bash_func_name} () {{\n # {bash_func_name:16} -- cd ${pathvar} /$@\n [ -z "${pathvar}" ] && echo "{pathvar} is not set" && return 1\n cd "${pathvar}"${{@:+"/${{@}}"}}\n}}\n{bash_compl_name} () {{\n local cur="$2";\n COMPREPLY=($({bash_func_name} && compgen -d -- "${{cur}}" ))\n}}\n'¶
-
BASH_ALIAS_TEMPLATE= '{cmd_name} () {{\n # {cmd_name:16} -- cd ${pathvar}\n {bash_func_name} $@\n}}\n'¶
-
BASH_COMPLETION_TEMPLATE= 'complete -o default -o nospace -F {bash_compl_name} {cmd_name}\n'¶
-
bash_func_name¶ Returns: str: e.g. “cdwrd”
-
bash_func_names¶ Returns: list: self.bash_func_name + self.aliases
-
class
dotfiles.venv.venv_ipyconfig.Step(func=None, **kwargs)[source]¶ Bases:
objectA build task step which builds or transforms an
Env, by callingstep.build(env=env, **step.conf)-
name¶ Returns: str: a name for this Step
-
build_print_kwargs_env(env=None, **kwargs)[source]¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
DEFAULT_FUNC(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.venv_ipyconfig.PrintEnvStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.StepPrint env and kwargs to stdout
-
stdout= <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>¶
-
stderr= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
func(env=None, **kwargs)¶ Default
build_*_envStep.func function to printenvKeyword Arguments: - env (
Env) – Env object (default: None) - kwargs (dict) – kwargs dict
Returns: updated Env
Return type: Env- env (
-
-
class
dotfiles.venv.venv_ipyconfig.PrintEnvStderrStep(func=None, **kwargs)[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.PrintEnvStepPrint env and kwargs to stderr
-
stdout= <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>¶
-
-
class
dotfiles.venv.venv_ipyconfig.StepBuilder(**kwargs)[source]¶ Bases:
objectA class for building a sequence of steps which modify env
-
name¶
-
debug¶ Returns: str: self.conf.get(‘debug’)
-
show_diffs¶ Returns: str: self.conf.get(‘show_diffs’)
-
add_step(func, **kwargs)[source]¶ Add a step to
self.stepsParameters: - func (Step or function or str) –
func(env=None, **kwargs) - kwargs (dict) – kwargs for Step.conf
Keyword Arguments: name (str) – function name (default: None)
Returns: Step object appended to self.steps
Return type: Step- func (Step or function or str) –
-
build_iter(env=None, show_diffs=True, debug=False)[source]¶ Build a generator of (Step, Env) tuples from the functional composition of StepBuilder.steps given an initial
Env(or None).# pseudocode env_previous = Env() for step in self.steps: (step, env) = step.build(env=env_previous.copy(),**conf) env_previous=env
Keyword Arguments: - env (Env) – initial Env (default: None)
- show_diffs (bool) – show difflib.ndiffs of Envs between steps
- debug (bool) –
Yields: tuple – (
Step,Env)
-
-
dotfiles.venv.venv_ipyconfig.lookup_from_kwargs_env(kwargs, env, attr, default=None)[source]¶ __getitem__ from kwargs, env, or default.
Parameters: - kwargs (dict) – kwargs dict
- env (Env) –
Envdict - attr (str) – attribute name
- default (obj) – default value to return if not found in kwargs or env
Returns: kwargs.get(attr, env.get(attr, default))
Return type: obj
-
dotfiles.venv.venv_ipyconfig.build_dotfiles_env(env=None, **kwargs)[source]¶ Configure dotfiles base environment (HOME, __WRK, __SRC, __DOTFILES)
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - HOME (str) – home path (
$HOME,~) - __WRK (str) – workspace path (
$__WRK,~/-wrk) - __SRC (str) – path to source repos (
$__WRK/-src) - __DOTFILES (str) – current dotfiles path (
~/-dotfiles)
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- HOME
- __WRK
- __SRC
- __DOTFILES
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.venv_ipyconfig.build_virtualenvwrapper_env(env=None, **kwargs)[source]¶ Set WORKON_HOME to WORKON_HOME or WORKON_HOME_DEFAULT
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - __WRK (str) – workspace path (
$__WRK,~/-wrk) - WORKON_HOME_DEFAULT (str) – variable name (default:
WORKON_HOME__py27) - WORKON_HOME__* (str) – path to a WORKON_HOME set
Returns: dotfiles.venv.venv_ipyconfig.EnvSets:
- WORKON_HOME__py27=’${__WRK}/-ve27’
- WORKON_HOME__py34=’${__WRK}/-ve34’
- WORKON_HOME__*=kwargs.get(WORKON_HOME__*)
- WORKON_HOME_DEFAULT=’WORKON_HOME_py27’
Return type: env (Env dict)
- env (Env dict) –
-
dotfiles.venv.venv_ipyconfig.build_conda_env(env=None, **kwargs)[source]¶ Configure conda27 (2.7) and conda (3.4) with condaenvs in
-wrk/-ce27and-wrk/ce34.Other Parameters: - __WRK (str) – workspace root (
$__WRK,~/-wrk) - CONDA_ROOT__py27 (str) – path to conda27 root environment
- CONDA_ENVS__py27 (str) – path to conda27 envs (e.g. WORKON_HOME)
- CONDA_ROOT__py34 (str) – path to conda34 root environment
- CONDA_ENVS__py34 (str) – path to conda34 envs (e.g. WORKON_HOME)
Keyword Arguments: env (Env dict) –
dotfiles.venv.venv_ipyconfig.EnvReturns: Return type: env (Env dict)
- __WRK (str) – workspace root (
-
dotfiles.venv.venv_ipyconfig.build_conda_cfg_env(env=None, **kwargs)[source]¶ Configure conda for a specific environment TODO build_venv_config
Parameters: env (Env dict) – dotfiles.venv.venv_ipyconfig.EnvReturns: dotfiles.venv.venv_ipyconfig.EnvReturn type: env (Env dict)
-
dotfiles.venv.venv_ipyconfig.build_venv_paths_full_env(env=None, pyver=None, **kwargs)[source]¶ Set variables for standard paths in the environment
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env(default: None (Env())) - VENVPREFIX (str) – venv prefix path (default: None (VIRTUAL_ENV))
- VENVSTR (str) – name of a VIRTUAL_ENV in WORKON_HOME or path to a VIRTUAL_ENV (default: None)
- VIRTUAL_ENV (str) – path to a VIRTUAL_ENV (default: None)
Returns: Return type: env (Env dict)
Raises: StepConfigException – When not any(( VIRTUAL_ENV, VENVPREFIX, VENVSTR, VENVSTRAPP))
References
- env (Env dict) –
-
dotfiles.venv.venv_ipyconfig.build_venv_paths_cdalias_env(env=None, **kwargs)[source]¶ Build CdAliases for standard paths
Keyword Arguments: env (Env dict) – EnvReturns: Envwith.aliasesextended.Return type: env (Env dict) Note
These do not work in IPython as they run in a subshell. See:
dotfiles.venv.venv_ipymagics.
-
dotfiles.venv.venv_ipyconfig.build_user_aliases_env(env=None, dont_reflect=False, VIRTUAL_ENV=None, _SRC=None, _ETC=None, _CFG=None, PROJECT_FILES=None, **kwargs)[source]¶ Configure env variables and return an OrderedDict of aliases
Parameters: dont_reflect (bool) – Whether to always create aliases and functions referencing $_WRDeven if$_WRDdoesn’t exist. (default: False)Returns: dict of aliases Return type: OrderedDict
-
dotfiles.venv.venv_ipyconfig.build_usrlog_env(env=None, _TERM_ID=None, shell='bash', prefix=None, USER=None, HOSTNAME=None, lookup_hostname=False, **kwargs)[source]¶ Build environment variables and configuration like usrlog.sh
Keyword Arguments: - env (Env dict) –
dotfiles.venv.venv_ipyconfig.Env - _TERM_ID (str) – terminal identifier string
- shell (str) – shell name (“bash”, “zsh”)
- prefix (str) – a path prefix (e.g.
$VIRTUAL_ENVor$PREFIX) - USER (str) – system username (
$USER) forHISTTIMEFORMAT - HOSTNAME (str) – system hostname (
HOSTNAME) forHISTTIMEFORMAT - lookup_hostname (bool) – if True,
HOSTNAMEis None, and not env.get(‘HOSTNAME’), try to readHOSTNAMEfromos.environand thensocket.gethostname().
Returns: Return type: env (Env dict)
Note
Like
usrlog.sh, whenHISTTIMEFORMATis set,USERandHOSTNAMEmust be evaluated.(When
USERandHOSTNAMEchange,HISTTIMEFORMATis not updated, and the .history file will contain only the most recent USER and HOSTNAME settings, which are not necessarily the actual USER and HOSTNAME.)TODO: could/should instead (also) write USER and HOSTNAME to -usrlog.log.
- env (Env dict) –
-
dotfiles.venv.venv_ipyconfig.build_venv_activate_env(env=None, VENVSTR=None, VENVSTRAPP=None, from_environ=False, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, **kwargs)[source]¶
-
class
dotfiles.venv.venv_ipyconfig.Env(*args, **kwargs)[source]¶ Bases:
objectOrderedDict of variables for/from
os.environ.-
osenviron_keys_classic= ('VIMBIN', 'GVIMBIN', 'MVIMBIN', 'GUIVIMBIN', 'VIMCONF', 'EDITOR', 'EDITOR_', 'PAGER', '__WRK', '__DOTFILES', 'PROJECT_HOME', 'WORKON_HOME', 'WORKON_HOME__py27', 'WORKON_HOME__py34', 'VENVPREFIX', 'VENVSTR', 'VENVSTRAPP', '_APP', 'VIRTUAL_ENV_NAME', 'VIRTUAL_ENV', '_SRC', '_ETC', '_BIN', '_CFG', '_LIB', '_LOG', '_MNT', '_OPT', '_PYLIB', '_PYSITE', '_SRV', '_VAR', '_WRD', '_WRD_SETUPY', '_WWW', '__SRC', '__DOCSWWW', '_USRLOG', '__USRLOG', '_TERM_ID', '_TERM_URI')¶
-
osenviron_keys= {'CONDA_ENVS_PATH': '${__WRK}/-ce27', 'CONDA_ENVS__py27': '${__WRK}/-ce27', 'CONDA_ENVS__py34': '${__WRK}/-ce34', 'CONDA_ENVS__py35': '${__WRK}/-ce35', 'CONDA_ENVS__py36': '${__WRK}/-ce36', 'CONDA_ENVS__py37': '${__WRK}/-ce37', 'CONDA_ROOT': '${__WRK}/-conda27', 'CONDA_ROOT__py27': '${__WRK}/-conda27', 'CONDA_ROOT__py34': '${__WRK}/-conda34', 'CONDA_ROOT__py35': '${__WRK}/-conda35', 'CONDA_ROOT__py36': '${__WRK}/-conda36', 'CONDA_ROOT__py37': '${__WRK}/-conda37', 'PROJECT_HOME': '${__WRK}', 'VENVPREFIX': '${VIRTUAL_ENV}', 'VENVSTR': 'dotfiles', 'VENVSTRAPP': 'dotfiles', 'VIRTUAL_ENV': '${WORKON_HOME}/${VIRTUAL_ENV_NAME}', 'VIRTUAL_ENV_NAME': 'dotfiles', 'WORKON_HOME': '${__WRK}/-ve27', 'WORKON_HOME_DEFAULT': 'WORKON_HOME__py37', 'WORKON_HOME__py27': '${__WRK}/-ve27', 'WORKON_HOME__py34': '${__WRK}/-ve34', 'WORKON_HOME__py35': '${__WRK}/-ve35', 'WORKON_HOME__py36': '${__WRK}/-ve36', 'WORKON_HOME__py37': '${__WRK}/-ve37', '_APP': 'dotfiles', '_BIN': '${VIRTUAL_ENV}/bin', '_ETC': '${VIRTUAL_ENV}/etc', '_ETCOPT': '${_ETC}/opt', '_HOME': '${VIRTUAL_ENV}/home', '_LIB': '${VIRTUAL_ENV}/lib', '_LOG': '${_VAR}/log', '_MEDIA': '${VIRTUAL_ENV}/media', '_MNT': '${VIRTUAL_ENV}/mnt', '_OPT': '${VIRTUAL_ENV}/opt', '_PYLIB': '${_LIB}/python2.7', '_PYSITE': '${_PYLIB}/site-packages', '_ROOT': '${VIRTUAL_ENV}/root', '_SBIN': '${VIRTUAL_ENV}/sbin', '_SRC': '${VIRTUAL_ENV}/src', '_SRV': '${VIRTUAL_ENV}/srv', '_TMP': '${VIRTUAL_ENV}/tmp', '_USR': '${VIRTUAL_ENV}/usr', '_USRBIN': '${VIRTUAL_ENV}/usr/bin', '_USRINCLUDE': '${VIRTUAL_ENV}/usr/include', '_USRLIB': '${VIRTUAL_ENV}/usr/lib', '_USRLOCAL': '${VIRTUAL_ENV}/usr/local', '_USRLOCALBIN': '${VIRTUAL_ENV}/usr/local/bin', '_USRSBIN': '${VIRTUAL_ENV}/usr/sbin', '_USRSHARE': '${VIRTUAL_ENV}/usr/share', '_USRSRC': '${VIRTUAL_ENV}/usr/src', '_VAR': '${VIRTUAL_ENV}/var', '_VARCACHE': '${_VAR}/cache', '_VARLIB': '${_VAR}/lib', '_VARLOCK': '${_VAR}/lock', '_VARMAIL': '${_VAR}/mail', '_VAROPT': '${_VAR}/opt', '_VARRUN': '${_VAR}/run', '_VARSPOOL': '${_VAR}/spool', '_VARTMP': '${_VAR}/tmp', '_WRD': '${_SRC}/dotfiles', '_WWW': '${_VAR}/www', '__DOTFILES': '${HOME}/-dotfiles', '__SRC': '${__WRK}/-src', '__WRK': '${HOME}/-wrk'}¶
-
name¶
-
classmethod
from_environ(environ, verbose=False)[source]¶ Build an
Envfrom a dict (e.g.os.environ)Parameters: - environ (dict) – a dict with variable name keys and values
- verbose (bool) – whether to be verbose about dict merging
Returns: an Env environment built from the given environ dict
Return type:
-
compress_paths(path_, keys=None, keyname=None)[source]¶ Given an arbitrary string, replace absolute paths (starting with ‘/’) with the longest matching Env path variables.
Parameters: path (str) – a path string Returns: path string containing ${VARNAME}variablesReturn type: str
-
-
dotfiles.venv.venv_ipyconfig.shell_quote(var)[source]¶ Escape single quotes and add double quotes around a given variable.
Parameters: _str (str) – string to add quotes to Returns: string wrapped in quotes Return type: str Warning
This is not safe for untrusted input and only valid in this context (
os.environ).
-
dotfiles.venv.venv_ipyconfig.shell_varquote(str_)[source]¶ Add doublequotes and shell variable brackets to a string
Parameters: str (str) – string to varquote (e.g. VIRTUAL_ENV)Returns: “${VIRTUAL_ENV}” Return type: str
-
class
dotfiles.venv.venv_ipyconfig.Venv(VENVSTR=None, VENVSTRAPP=None, _Venv__WRK=None, _Venv__DOTFILES=None, WORKON_HOME=None, VIRTUAL_ENV_NAME=None, VENVPREFIX=None, VIRTUAL_ENV=None, _SRC=None, _APP=None, _WRD=None, env=None, from_environ=False, open_editors=False, open_terminals=False, dont_reflect=True, debug=False, show_diffs=False, **kwargs)[source]¶ Bases:
objectA virtual environment configuration generator
-
build(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, from_environ=False, dont_reflect=True, debug=False, show_diffs=False, build_user_aliases=False, build_userlog_env=False)[source]¶ Build
VenvStepswithStepBuilder
-
static
parse_VENVSTR(env=None, VENVSTR=None, VENVSTRAPP=None, VENVPREFIX=None, VIRTUAL_ENV=None, VIRTUAL_ENV_NAME=None, _APP=None, _SRC=None, _WRD=None, _Venv__WRK=None, WORKON_HOME=None, from_environ=False, **kwargs)[source]¶ Get the path to a virtualenv given a
VENVSTRKeyword Arguments: - env (Env) –
- VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) –
- VENVPREFIX (str) –
- WORKON_HOME (str) –
- from_environ (bool) – whether to try and read from
os.environ["VIRTUAL_ENV"]
Returns: a path to a virtualenv (for
$VIRTUAL_ENV)Return type: str
-
aliases¶ Returns: OrderedDict: self.env.aliases
-
classmethod
workon(env=None, VENVSTR=None, VENVSTRAPP=None, **kwargs)[source]¶ Parameters: - VENVSTR (str) – a path to a virtualenv containing
/OR just the name of a virtualenv in$WORKON_HOME - VENVSTRAPP (str) – e.g.
dotfilesordotfiles/docs - kwargs (dict) – kwargs to pass to Venv (see
Venv.__init__)
Returns: an intialized
VenvReturn type: - VENVSTR (str) – a path to a virtualenv containing
-
configure_ipython(*args, **kwargs)[source]¶ Configure IPython with
Venv._configure_ipythonanduser_aliasesfromself.aliases.items().Parameters: - args (list) – args for
Venv._configure_ipython - kwargs (dict) – kwargs for
Venv._configure_ipython.
- args (list) – args for
-
generate_bash_env(shell_keyword='export ', shell_quotefunc=<function shell_quote>, include_paths=True, include_aliases=True, include_cdaliases=False, **kwargs)[source]¶ Generate a
source-able script for the environment variables, aliases, and functions defined by the currentVenv.Keyword Arguments: - shell_keyword (str) – shell variable def (default: “export “)
- include_paths (bool) – Include environ vars in output (default: True)
- include_aliases (bool) – Include aliases in output (default: True)
- include_cdaliases (bool) – Include cdaliases in output (default: False)
- compress_paths (bool) – Compress paths to $VAR (default=False)
Yields: str – block of bash script
-
generate_bash_cdalias()[source]¶ Generate a
source-able script for cdalias functionsYields: str – block of bash script
-
generate_vim_cdalias()[source]¶ Generate a
source-able vimscript for vimYields: str – block of vim script
-
generate_venv_ipymagics()[source]¶ Generate an
venv_ipymagics.pyfile for IPythonYields: str – block of Python code
-
project_files¶
-
PROJECT_FILES¶
-
system(cmd=None)[source]¶ Call
os.systemwith the given command stringParameters: cmd (string) – command string to call
os.systemwithRaises: - Exception – if
cmdis None - NotImplementedError – if
cmdis a tuple
- Exception – if
-
to_json(indent=None)[source]¶ Parameters: indent (int) – number of spaces with which to indent JSON output Returns: json.dumps(self.to_dict()) Return type: str
-
-
dotfiles.venv.venv_ipyconfig.ipython_main()[source]¶ Configure IPython with
Venv:py:method:`configure_ipython` (:py:method:`_configure_ipython`).
-
dotfiles.venv.venv_ipyconfig.ipython_imports()[source]¶ Default imports for IPython (currently unused)
-
class
dotfiles.venv.venv_ipyconfig.VenvTestUtils[source]¶ Bases:
objectTest fixtures for TestCases and examples
-
class
dotfiles.venv.venv_ipyconfig.Test_001_lookup(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv_ipyconfig.Test_100_Env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv_ipyconfig.Test_200_StepBuilder(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv_ipyconfig.Test_250_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv_ipyconfig.Test_300_venv_build_env(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCasetest each build step independently
kwargs = {} env = env.copy() buildfunc = build_virtualenvwrapper_env new_env = buildfunc(env=env, **kwargs)
-
class
dotfiles.venv.venv_ipyconfig.Test_500_Venv(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
class
dotfiles.venv.venv_ipyconfig.Test_900_Venv_main(methodName='runTest')[source]¶ Bases:
dotfiles.venv.venv_ipyconfig.VenvTestCase,unittest.case.TestCase
-
dotfiles.venv.venv_ipyconfig.build_venv_arg_parser()[source]¶ Returns: options for the commandline interface Return type: optparse.OptionParser
dotfiles.venv.venv_ipymagics module¶
-
dotfiles.venv.venv_ipymagics.magics_class(cls, *args, **kwargs)¶
-
dotfiles.venv.venv_ipymagics.line_magic(func, *args, **kwargs)¶