virtualenvwrapper-4.1.1/0000755000101700007650000000000012173006006017237 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/.gitignore0000644000101700007650000000071012172574313021237 0ustar dhellmanndhellmann00000000000000syntax: glob *~ *.pyc README.html build dist distribute*.egg distribute*.tar.gz docs/build docs/html docs/website docs/en docs/es docs/ja tests/catch_output tests/testpackage/build tests/testpackage/dist tests/testpackage/testpackage.egg-info tests/testtemplate/build tests/testtemplate/dist tests/testtemplate/testtemplate.egg-info trace.txt virtualenvwrapper.egg-info virtualenvwrapper/docs .tox *.orig TAGS ChangeLog AUTHORS syntax: re .DS_Store ^web/ virtualenvwrapper-4.1.1/announce.rst0000644000101700007650000000273012172763550021616 0ustar dhellmanndhellmann00000000000000======================= virtualenvwrapper 4.1 ======================= .. tags:: virtualenvwrapper release python What is virtualenvwrapper? ========================== virtualenvwrapper_ is a set of extensions to virtualenv_. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. What's New? =========== - Ensure that all ``$()`` style commands that produce paths are quoted; addresses issue 164. - Add ``wipeenv`` command for removing all packages installed in the virtualenv. - Allow users of ``virtualenvwrapper_lazy.sh`` to extend the list of API commands that trigger the lazy-loader by extending ``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see issue 188. - Fix detection of ``--python`` option to ``mkvirtualenv``. Resolves issue 190. - Add ``allvirtualenv`` command to run a command across all virtualenvs. Suggested by Dave Coutts in issue 186. - Fix ``lsvirtualenv`` when there are spaces in ``WORKON_HOME``. Resolves issue 194. - Switch to `pbr`_ for packaging. .. _pbr: https://github.com/openstack-dev/pbr Installing ========== Visit the virtualenvwrapper_ project page for download links and installation instructions. .. _virtualenv: http://pypi.python.org/pypi/virtualenv .. _virtualenvwrapper: http://virtualenvwrapper.readthedocs.org/en/latest/ virtualenvwrapper-4.1.1/docs/0000755000101700007650000000000012173006006020167 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/docs/Makefile0000644000101700007650000001276112143435521021643 0ustar dhellmanndhellmann00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/virtualenvwrapper.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/virtualenvwrapper.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/virtualenvwrapper" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/virtualenvwrapper" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." virtualenvwrapper-4.1.1/docs/requirements.txt0000644000101700007650000000003012143435521023451 0ustar dhellmanndhellmann00000000000000sphinxcontrib-bitbucket virtualenvwrapper-4.1.1/docs/source/0000755000101700007650000000000012173006006021467 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/docs/source/command_ref.rst0000644000101700007650000003732712146216472024521 0ustar dhellmanndhellmann00000000000000.. Quick reference documentation for virtualenvwrapper command line functions Originally contributed Thursday, May 28, 2009 by Steve Steiner (ssteinerX@gmail.com) .. _command: ################# Command Reference ################# All of the commands below are to be used on the Terminal command line. ===================== Managing Environments ===================== .. _command-mkvirtualenv: mkvirtualenv ------------ Create a new environment, in the WORKON_HOME. Syntax:: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] ENVNAME All command line options except ``-a``, ``-i``, ``-r``, and ``-h`` are passed directly to ``virtualenv``. The new environment is automatically activated after being initialized. :: $ workon $ mkvirtualenv mynewenv New python executable in mynewenv/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (mynewenv)$ workon mynewenv (mynewenv)$ The ``-a`` option can be used to associate an existing project directory with the new environment. The ``-i`` option can be used to install one or more packages (by repeating the option) after the environment is created. The ``-r`` option can be used to specify a text file listing packages to be installed. The argument value is passed to ``pip -r`` to be installed. .. seealso:: * :ref:`scripts-premkvirtualenv` * :ref:`scripts-postmkvirtualenv` * `requirements file format`_ .. _requirements file format: http://www.pip-installer.org/en/latest/requirements.html .. _command-mktmpenv: mktmpenv -------- Create a new virtualenv in the ``WORKON_HOME`` directory. Syntax:: mktmpenv [VIRTUALENV_OPTIONS] A unique virtualenv name is generated. :: $ mktmpenv Using real prefix '/Library/Frameworks/Python.framework/Versions/2.7' New python executable in 1e513ac6-616e-4d56-9aa5-9d0a3b305e20/bin/python Overwriting 1e513ac6-616e-4d56-9aa5-9d0a3b305e20/lib/python2.7/distutils/__init__.py with new content Installing distribute............................................... .................................................................... .................................................................done. This is a temporary environment. It will be deleted when deactivated. (1e513ac6-616e-4d56-9aa5-9d0a3b305e20) $ .. _command-lsvirtualenv: lsvirtualenv ------------ List all of the environments. Syntax:: lsvirtualenv [-b] [-l] [-h] -b Brief mode, disables verbose output. -l Long mode, enables verbose output. Default. -h Print the help for lsvirtualenv. .. seealso:: * :ref:`scripts-get_env_details` .. _command-showvirtualenv: showvirtualenv -------------- Show the details for a single virtualenv. Syntax:: showvirtualenv [env] .. seealso:: * :ref:`scripts-get_env_details` .. _command-rmvirtualenv: rmvirtualenv ------------ Remove an environment, in the WORKON_HOME. Syntax:: rmvirtualenv ENVNAME You must use :ref:`command-deactivate` before removing the current environment. :: (mynewenv)$ deactivate $ rmvirtualenv mynewenv $ workon $ .. seealso:: * :ref:`scripts-prermvirtualenv` * :ref:`scripts-postrmvirtualenv` .. _command-cpvirtualenv: cpvirtualenv ------------ Duplicate an existing virtualenv environment. The source can be an environment managed by virtualenvwrapper or an external environment created elsewhere. .. warning:: Copying virtual environments is not well supported. Each virtualenv has path information hard-coded into it, and there may be cases where the copy code does not know to update a particular file. **Use with caution.** Syntax:: cpvirtualenv ENVNAME [TARGETENVNAME] .. note:: Target environment name is required for WORKON_HOME duplications. However, target environment name can be ommited for importing external environments. If omitted, the new environment is given the same name as the original. :: $ workon $ mkvirtualenv source New python executable in source/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (source)$ cpvirtualenv source dest Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/easy_install relative Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/easy_install-2.6 relative Making script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/pip relative Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/postactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python) Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/postdeactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python) Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/preactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python) Script /Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/predeactivate cannot be made relative (it's not a normal script that starts with #!/Users/dhellmann/Devel/virtualenvwrapper/tmp/dest/bin/python) (dest)$ workon dest source (dest)$ .. seealso:: * :ref:`scripts-precpvirtualenv` * :ref:`scripts-postcpvirtualenv` * :ref:`scripts-premkvirtualenv` * :ref:`scripts-postmkvirtualenv` .. _command-allvirtualenv: allvirtualenv ------------- Run a command in all virtualenvs under WORKON_HOME. Syntax:: allenvs command with arguments Each virtualenv is activated, bypassing activation hooks, the current working directory is changed to the current virtualenv, and then the command is run. Commands cannot modify the current shell state, but can modify the virtualenv. :: $ allenvs pip install -U pip ================================== Controlling the Active Environment ================================== .. _command-workon: workon ------ List or change working virtual environments Syntax:: workon [environment_name] If no ``environment_name`` is given the list of available environments is printed to stdout. :: $ workon $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ mkvirtualenv env2 New python executable in env2/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env2)$ workon env1 env2 (env2)$ workon env1 (env1)$ echo $VIRTUAL_ENV /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1 (env1)$ workon env2 (env2)$ echo $VIRTUAL_ENV /Users/dhellmann/Devel/virtualenvwrapper/tmp/env2 (env2)$ .. seealso:: * :ref:`scripts-predeactivate` * :ref:`scripts-postdeactivate` * :ref:`scripts-preactivate` * :ref:`scripts-postactivate` .. _command-deactivate: deactivate ---------- Switch from a virtual environment to the system-installed version of Python. Syntax:: deactivate .. note:: This command is actually part of virtualenv, but is wrapped to provide before and after hooks, just as workon does for activate. :: $ workon $ echo $VIRTUAL_ENV $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ echo $VIRTUAL_ENV /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1 (env1)$ deactivate $ echo $VIRTUAL_ENV $ .. seealso:: * :ref:`scripts-predeactivate` * :ref:`scripts-postdeactivate` ================================== Quickly Navigating to a virtualenv ================================== There are two functions to provide shortcuts to navigate into the currently-active virtualenv. cdvirtualenv ------------ Change the current working directory to ``$VIRTUAL_ENV``. Syntax:: cdvirtualenv [subdir] Calling ``cdvirtualenv`` changes the current working directory to the top of the virtualenv (``$VIRTUAL_ENV``). An optional argument is appended to the path, allowing navigation directly into a subdirectory. :: $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ echo $VIRTUAL_ENV /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1 (env1)$ cdvirtualenv (env1)$ pwd /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1 (env1)$ cdvirtualenv bin (env1)$ pwd /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1/bin cdsitepackages -------------- Change the current working directory to the ``site-packages`` for ``$VIRTUAL_ENV``. Syntax:: cdsitepackages [subdir] Because the exact path to the site-packages directory in the virtualenv depends on the version of Python, ``cdsitepackages`` is provided as a shortcut for ``cdvirtualenv lib/python${pyvers}/site-packages``. An optional argument is also allowed, to specify a directory hierarchy within the ``site-packages`` directory to change into. :: $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ echo $VIRTUAL_ENV /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1 (env1)$ cdsitepackages PyMOTW/bisect/ (env1)$ pwd /Users/dhellmann/Devel/virtualenvwrapper/tmp/env1/lib/python2.6/site-packages/PyMOTW/bisect lssitepackages -------------- Calling ``lssitepackages`` shows the content of the ``site-packages`` directory of the currently-active virtualenv. Syntax:: lssitepackages :: $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ $ workon env1 (env1)$ lssitepackages distribute-0.6.10-py2.6.egg pip-0.6.3-py2.6.egg easy-install.pth setuptools.pth =============== Path Management =============== add2virtualenv -------------- Adds the specified directories to the Python path for the currently-active virtualenv. Syntax:: add2virtualenv directory1 directory2 ... Sometimes it is desirable to share installed packages that are not in the system ``site-packages`` directory and which should not be installed in each virtualenv. One possible solution is to symlink the source into the environment ``site-packages`` directory, but it is also easy to add extra directories to the PYTHONPATH by including them in a ``.pth`` file inside ``site-packages`` using ``add2virtualenv``. 1. Check out the source for a big project, such as Django. 2. Run: ``add2virtualenv path_to_source``. 3. Run: ``add2virtualenv``. 4. A usage message and list of current "extra" paths is printed. The directory names are added to a path file named ``_virtualenv_path_extensions.pth`` inside the site-packages directory for the environment. *Based on a contribution from James Bennett and Jannis Leidel.* .. _command-toggleglobalsitepackages: toggleglobalsitepackages ------------------------ Controls whether the active virtualenv will access the packages in the global Python ``site-packages`` directory. Syntax:: toggleglobalsitepackages [-q] Outputs the new state of the virtualenv. Use the ``-q`` switch to turn off all output. :: $ mkvirtualenv env1 New python executable in env1/bin/python Installing distribute............................................. .................................................................. .................................................................. done. (env1)$ toggleglobalsitepackages Disabled global site-packages (env1)$ toggleglobalsitepackages Enabled global site-packages (env1)$ toggleglobalsitepackages -q (env1)$ ============================ Project Directory Management ============================ .. seealso:: :ref:`project-management` .. _command-mkproject: mkproject --------- Create a new virtualenv in the WORKON_HOME and project directory in PROJECT_HOME. Syntax:: mkproject [-t template] [virtualenv_options] ENVNAME The template option may be repeated to have several templates used to create a new project. The templates are applied in the order named on the command line. All other options are passed to ``mkvirtualenv`` to create a virtual environment with the same name as the project. :: $ mkproject myproj New python executable in myproj/bin/python Installing distribute............................................. .................................................................. .................................................................. done. Creating /Users/dhellmann/Devel/myproj (myproj)$ pwd /Users/dhellmann/Devel/myproj (myproj)$ echo $VIRTUAL_ENV /Users/dhellmann/Envs/myproj (myproj)$ .. seealso:: * :ref:`scripts-premkproject` * :ref:`scripts-postmkproject` .. _command-setvirtualenvproject: setvirtualenvproject -------------------- Bind an existing virtualenv to an existing project. Syntax:: setvirtualenvproject [virtualenv_path project_path] The arguments to ``setvirtualenvproject`` are the full paths to the virtualenv and project directory. An association is made so that when ``workon`` activates the virtualenv the project is also activated. :: $ mkproject myproj New python executable in myproj/bin/python Installing distribute............................................. .................................................................. .................................................................. done. Creating /Users/dhellmann/Devel/myproj (myproj)$ mkvirtualenv myproj_new_libs New python executable in myproj/bin/python Installing distribute............................................. .................................................................. .................................................................. done. Creating /Users/dhellmann/Devel/myproj (myproj_new_libs)$ setvirtualenvproject $VIRTUAL_ENV $(pwd) When no arguments are given, the current virtualenv and current directory are assumed. Any number of virtualenvs can refer to the same project directory, making it easy to switch between versions of Python or other dependencies for testing. .. _command-cdproject: cdproject --------- Change the current working directory to the one specified as the project directory for the active virtualenv. Syntax:: cdproject =========================== Managing Installed Packages =========================== .. _command-wipeenv: wipeenv ------- Remove all of the installed third-party packages in the current virtualenv. Syntax:: wipeenv virtualenvwrapper-4.1.1/docs/source/conf.py0000644000101700007650000001473512143435521023005 0ustar dhellmanndhellmann00000000000000# -*- coding: utf-8 -*- # # virtualenvwrapper documentation build configuration file, created by # sphinx-quickstart on Thu May 28 22:35:13 2009. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import datetime import subprocess # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.append(os.path.abspath('.')) # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinxcontrib.bitbucket'] bitbucket_project_url = 'http://bitbucket.org/dhellmann/virtualenvwrapper/' # Add any paths that contain templates here, relative to this directory. #templates_path = ['pkg/templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8' # The master toctree document. master_doc = 'index' # General information about the project. project = u'virtualenvwrapper' copyright = u'2009-%s, Doug Hellmann' % datetime.datetime.today().year # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = subprocess.check_output([ 'sh', '-c', 'cd ../..; python setup.py --version', ]) version = version.strip() # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of documents that shouldn't be included in the build. #unused_docs = [] # List of directories, relative to source directory, that shouldn't be searched # for source files. exclude_trees = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. Major themes that come with # Sphinx are currently 'default' and 'sphinxdoc'. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". #html_static_path = ['static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. html_use_modindex = False # If false, no index is generated. html_use_index = False # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = '' # Output file base name for HTML help builder. htmlhelp_basename = 'virtualenvwrapperdoc' # -- Options for LaTeX output ------------------------------------------------ # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass # [howto/manual]). latex_documents = [ ('index', 'virtualenvwrapper.tex', u'virtualenvwrapper Documentation', u'Doug Hellmann', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_use_modindex = True virtualenvwrapper-4.1.1/docs/source/design.rst0000644000101700007650000002125412143435521023503 0ustar dhellmanndhellmann00000000000000========================================================= Why virtualenvwrapper is (Mostly) Not Written In Python ========================================================= If you look at the source code for virtualenvwrapper you will see that most of the interesting parts are implemented as shell functions in ``virtualenvwrapper.sh``. The hook loader is a Python app, but doesn't do much to manage the virtualenvs. Some of the most frequently asked questions about virtualenvwrapper are "Why didn't you write this as a set of Python programs?" or "Have you thought about rewriting it in Python?" For a long time these questions baffled me, because it was always obvious to me that it had to be implemented as it is. But they come up frequently enough that I feel the need to explain. tl;dr: POSIX Made Me Do It ========================== The choice of implementation language for virtualenvwrapper was made for pragmatic, rather than philosophical, reasons. The wrapper commands need to modify the state and environment of the user's *current shell process*, and the only way to do that is to have the commands run *inside that shell.* That resulted in me writing virtualenvwrapper as a set of shell functions, rather than separate shell scripts or even Python programs. Where Do POSIX Processes Come From? =================================== New POSIX processes are created when an existing process invokes the ``fork()`` system call. The invoking process becomes the "parent" of the new "child" process, and the child is a full clone of the parent. The *semantic* result of ``fork()`` is that an entire new copy of the parent process is created. In practice, optimizations are normally made to avoid copying more memory than is absolutely necessary (frequently via a copy-on-write system). But for the purposes of this explanation it is sufficient to think of the child as a full replica of the parent. The important parts of the parent process that are copied include dynamic memory (the stack and heap), static stuff (the program code), resources like open file descriptors, and the *environment variables* exported from the parent process. Inheriting environment variables is a fundamental aspect of the way POSIX programs pass state and configuration information to one another. A parent can establish a series of ``name=value`` pairs, which are then given to the child process. The child can access them through functions like ``getenv()``, ``setenv()`` (and in Python through ``os.environ``). The choice of the term *inherit* to describe the way the variables and their contents are passed from parent to child is significant. Although a child can change its own environment, it cannot directly change the environment settings of its parent because there is no system call to modify the parental environment settings. How the Shell Runs a Program ============================ When a shell receives a command to be executed, either interactively or by parsing a script file, and determines that the command is implemented in a separate program file, is uses ``fork()`` to create a new process and then inside that process it uses one of the ``exec`` functions to start the specified program. The language that program is written in doesn't make any difference in the decision about whether or not to ``fork()``, so even if the "program" is a shell script written in the language understood by the current shell, a new process is created. On the other hand, if the shell decides that the command is a *function*, then it looks at the definition and invokes it directly. Shell functions are made up of other commands, some of which may result in child processes being created, but the function itself runs in the original shell process and can therefore modify its state, for example by changing the working directory or the values of variables. It is possible to force the shell to run a script directly, and not in a child process, by *sourcing* it. The ``source`` command causes the shell to read the file and interpret it in the current process. Again, as with functions, the contents of the file may cause child processes to be spawned, but there is not a second shell process interpreting the series of commands. What Does This Mean for virtualenvwrapper? ========================================== The original and most important features of virtualenvwrapper are automatically activating a virtualenv when it is created by ``mkvirtualenv`` and using ``workon`` to deactivate one environment and activate another. Making these features work drove the implementation decisions for the other parts of virtualenvwrapper, too. Environments are activated interactively by sourcing ``bin/activate`` inside the virtualenv. The ``activate`` script does a few things, but the important parts are setting the ``VIRTUAL_ENV`` variable and modifying the shell's search path through the ``PATH`` variable to put the ``bin`` directory for the environment on the front of the path. Changing the path means that the programs installed in the environment, especially the python interpreter there, are found before other programs with the same name. Simply running ``bin/activate``, without using ``source`` doesn't work because it sets up the environment of the *child* process, without affecting the parent. In order to source the activate script in the interactive shell, both ``mkvirtualenv`` and ``workon`` also need to be run in that shell process. Why Choose One When You Can Have Both? ====================================== The hook loader is one part of virtualenvwrapper that *is* written in Python. Why? Again, because it was easier. Hooks are discovered using setuptools entry points, because after an entry point is installed the user doesn't have to take any other action to allow the loader to discover and use it. It's easy to imagine writing a hook to create new files on the filesystem (by installing a package, instantiating a template, etc.). How, then, do hooks running in a separate process (the Python interpreter) modify the shell environment to set variables or change the working directory? They cheat, of course. Each hook point defined by virtualenvwrapper actually represents two hooks. First, the hooks meant to be run in Python are executed. Then the "source" hooks are run, and they *print out* a series of shell commands. All of those commands are collected, saved to a temporary file, and then the shell is told to source the file. Starting up the hook loader turns out to be way more expensive than most of the other actions virtualenvwrapper takes, though, so I am considering making its use optional. Most users customize the hooks by using shell scripts (either globally or in the virtualenv). Finding and running those can be handled by the shell quite easily. Implications for Cross-Shell Compatibility ========================================== Other than requests for a full-Python implementation, the other most common request is to support additional shells. fish_ comes up a lot, as do various Windows-only shells. The officially :ref:`supported-shells` all have a common enough syntax that the same implementation works for each. Supporting other shells would require rewriting much, if not all, of the logic using an alternate syntax -- those other shells are basically different programming languages. So far I have dealt with the ports by encouraging other developers to handle them, and then trying to link to and otherwise promote the results. .. _fish: http://ridiculousfish.com/shell/ Not As Bad As It Seems ====================== Although there are some special challenges created by the the requirement that the commands run in a user's interactive shell (see the many bugs reported by users who alias common commands like ``rm`` and ``cd``), using the shell as a programming language holds up quite well. The shells are designed to make finding and executing other programs easy, and especially to make it easy to combine a series of smaller programs to perform more complicated operations. As that's what virtualenvwrapper is doing, it's a natural fit. .. seealso:: * `Advanced Programming in the UNIX Environment`_ by W. Richard Stevens & Stephen A. Rago * `Fork (operating system)`_ on Wikipedia * `Environment variable`_ on Wikipedia * `Linux implementation of fork()`_ .. _Advanced Programming in the UNIX Environment: http://www.amazon.com/gp/product/0321637739/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0321637739&linkCode=as2&tag=hellflynet-20 .. _Fork (operating system): http://en.wikipedia.org/wiki/Fork_(operating_system) .. _Environment variable: http://en.wikipedia.org/wiki/Environment_variable .. _Linux implementation of fork(): https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/kernel/fork.c?id=refs/tags/v3.9-rc8#n1558 virtualenvwrapper-4.1.1/docs/source/developers.rst0000644000101700007650000000771712143435521024412 0ustar dhellmanndhellmann00000000000000############## For Developers ############## If you would like to contribute to virtualenvwrapper directly, these instructions should help you get started. Patches, bug reports, and feature requests are all welcome through the `BitBucket site `_. Contributions in the form of patches or pull requests are easier to integrate and will receive priority attention. .. note:: Before contributing new features to virtualenvwrapper core, please consider whether they should be implemented as an extension instead. Building Documentation ====================== The documentation for virtualenvwrapper is written in reStructuredText and converted to HTML using Sphinx. The build itself is driven by make. You will need the following packages in order to build the docs: - Sphinx - docutils Once all of the tools are installed into a virtualenv using pip, run ``make html`` to generate the HTML version of the documentation:: $ make html rm -rf virtualenvwrapper/docs (cd docs && make html SPHINXOPTS="-c sphinx/pkg") sphinx-build -b html -d build/doctrees -c sphinx/pkg source build/html Running Sphinx v0.6.4 loading pickled environment... done building [html]: targets for 2 source files that are out of date updating environment: 0 added, 2 changed, 0 removed reading sources... [ 50%] command_ref reading sources... [100%] developers looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [ 33%] command_ref writing output... [ 66%] developers writing output... [100%] index writing additional files... search copying static files... WARNING: static directory '/Users/dhellmann/Devel/virtualenvwrapper/plugins/docs/sphinx/pkg/static' does not exist done dumping search index... done dumping object inventory... done build succeeded, 1 warning. Build finished. The HTML pages are in build/html. cp -r docs/build/html virtualenvwrapper/docs The output version of the documentation ends up in ``./virtualenvwrapper/docs`` inside your sandbox. Running Tests ============= The test suite for virtualenvwrapper uses shunit2_ and tox_. The shunit2 source is included in the ``tests`` directory, but tox must be installed separately (``pip install tox``). To run the tests under bash, zsh, and ksh for Python 2.4 through 2.7, run ``tox`` from the top level directory of the hg repository. To run individual test scripts, use a command like:: $ tox tests/test_cd.sh To run tests under a single version of Python, specify the appropriate environment when running tox:: $ tox -e py27 Combine the two modes to run specific tests with a single version of Python:: $ tox -e py27 tests/test_cd.sh Add new tests by modifying an existing file or creating new script in the ``tests`` directory. .. _shunit2: http://shunit2.googlecode.com/ .. _tox: http://codespeak.net/tox .. _developer-templates: Creating a New Template ======================= virtualenvwrapper.project templates work like `virtualenvwrapper plugins `__. The *entry point* group name is ``virtualenvwrapper.project.template``. Configure your entry point to refer to a function that will **run** (source hooks are not supported for templates). The argument to the template function is the name of the project being created. The current working directory is the directory created to hold the project files (``$PROJECT_HOME/$envname``). Help Text --------- One difference between project templates and other virtualenvwrapper extensions is that only the templates specified by the user are run. The ``mkproject`` command has a help option to give the user a list of the available templates. The names are taken from the registered entry point names, and the descriptions are taken from the docstrings for the template functions. virtualenvwrapper-4.1.1/docs/source/extensions.rst0000644000101700007650000000343712143435521024434 0ustar dhellmanndhellmann00000000000000===================== Existing Extensions ===================== Below is a list of some of the extensions available for use with virtualenvwrapper. emacs-desktop ============= Emacs desktop-mode_ lets you save the state of emacs (open buffers, kill rings, buffer positions, etc.) between sessions. It can also be used as a project file similar to other IDEs. The emacs-desktop_ plugin adds a trigger to save the current desktop file and load a new one when activating a new virtualenv using ``workon``. .. _desktop-mode: http://www.emacswiki.org/emacs/DeskTop .. _emacs-desktop: http://www.doughellmann.com/projects/virtualenvwrapper-emacs-desktop/ .. _extensions-user_scripts: user_scripts ============ The ``user_scripts`` extension is delivered with virtualenvwrapper and enabled by default. It implements the user customization script features described in :ref:`scripts`. vim-virtualenv ============== `vim-virtualenv`_ is Jeremey Cantrell's plugin for controlling virtualenvs from within vim. When used together with virtualenvwrapper, vim-virtualenv identifies the virtualenv to activate based on the name of the file being edited. .. _vim-virtualenv: https://github.com/jmcantrell/vim-virtualenv .. _extensions-templates: Templates ========= Below is a list of some of the templates available for use with :ref:`command-mkproject`. .. _templates-bitbucket: bitbucket --------- The bitbucket_ extension automatically clones a mercurial repository from the specified bitbucket project. .. _bitbucket: http://www.doughellmann.com/projects/virtualenvwrapper.bitbucket/ .. _templates-django: django ------ The django_ extension automatically creates a new Django project. .. _django: http://www.doughellmann.com/projects/virtualenvwrapper.django/ .. seealso:: * :ref:`developer-templates` virtualenvwrapper-4.1.1/docs/source/history.rst0000644000101700007650000005142012173005741023731 0ustar dhellmanndhellmann00000000000000=============== Release History =============== 4.1.1 ===== - Fix packaging issue with 4.1. 4.1 === - Ensure that all ``$()`` style commands that produce paths are quoted. Addresses :bbissue:`164`. - Add :ref:`command-wipeenv` command for removing all packages installed in the virtualenv. - Allow users of ``virtualenvwrapper_lazy.sh`` to extend the list of API commands that trigger the lazy-loader by extending ``_VIRTUALENVWRAPPER_API``. Patch contributed by John Purnell, see :bbissue:`188`. - Fix detection of ``--python`` option to :ref:`command-mkvirtualenv`. Resolves :bbissue:`190`. - Add :ref:`command-allvirtualenv` command to run a command across all virtualenvs. Suggested by Dave Coutts in :bbissue:`186`. - Fix :ref:`command-lsvirtualenv` when there are spaces in ``WORKON_HOME``. Resolves :bbissue:`194`. - Switch to `pbr`_ for packaging. .. _pbr: https://github.com/openstack-dev/pbr 4.0 === **Warning:** This release includes some potentially incompatible changes for extensions. The python modules for extensions are now *always* run with ``PWD=$WORKON_HOME`` (previously the value of PWD varied depending on the hook). The *shell* portion of any hook (anything sourced by the user's shell when the hook is run) is still run in the same place as before. - All tests pass under Python 2.6, 2.7, 3.2 and 3.3. - Fix the name of the script in an error message produced by ``virtualenvwrapper_lazy.sh``. (Contributed by :bbuser:`scottstvnsn`.) 3.7.1 ===== - Rename functions for generating help so they do not pollute the global namespace, and especially so they do not interfere with tab completion. Contributed by :bbuser:`davidszotten`. - Fix an issue with listing project templates if none are installed. (:bbissue:`179`) - Fix an issue with the ``--python`` option to ``mkvirtualenv`` becoming *sticky* for future calls that do not explicitly specify the option. (:bbissue:`178`) 3.7 === - Improve tab-completion support for users of the lazy-loading mode. (:bbuser:`upsuper`) - Add ``--help`` option to ``mkproject``. - Add ``--help`` option to ``workon``. - Turn off logging from the hook loader by default, and replace ``VIRTUALENVWRAPPER_LOG_DIR`` environment variable with ``VIRTUALENVWRAPPER_LOG_FILE``. The rotating log behavior remains the same. The motivation for this change is the race condition caused by that rotating behavior, especially when the wrappers are being used by users with different permissions and umasks. (:bbissue:`152`) - Use flake8_ for style checking. .. _flake8: https://pypi.python.org/pypi/flake8 3.6.1 ===== - Replace realpath with a more portable way of converting a relative path to an absolute path, used with the ``--python`` option to mkvirtualenv (contributed by Radu Voicilas, :bbuser:`rvoicilas`). - Posted release to PyPI, resolving download redirect issue. (:bbissue:`171` and :bbissue:`172`) 3.6 === - Switch to stevedore_ for plugin management - mkvirtualenv_help should use ``$VIRTUALENVWRAPPER_PYTHON`` instead of calling ``virtualenv`` directly (:bbissue:`148`). - Fix issue with lazy-loader code under zsh (:bbissue:`144`). - Fix issue with ``noclobber`` option under zsh (:bbissue:`137`). Fix based on patch from :bbuser:`rob_b`. - Fix documentation for ``add2virtualenv`` to show the correct name for the file containing the new path entry. (contributed by :bbuser:`rvoicilas`) - Fix problem with ``virtualenvwrapper_show_workon_options`` under zsh with ``chpwd`` functions that produce output. (:bbissue:`153`) .. _stevedore: http://pypi.python.org/pypi/stevedore 3.5 === - Rewrite :ref:`command-cpvirtualenv` to use `virtualenv-clone`_ instead of making the new environment relocatable. Contributed by Justin Barber (:bbuser:`barberj`). This also resolves a problem with cpvirtualenv not honoring the ``--no-site-packages`` flag (:bbissue:`102`). - Update docs with link to `virtualenvwrapper-win`_ port by David Marble. - Use ``command`` to avoid functions named the same as common utilities. (:bbissue:`119`) .. _virtualenv-clone: http://pypi.python.org/pypi/virtualenv-clone .. _virtualenvwrapper-win: http://pypi.python.org/pypi/virtualenvwrapper-win 3.4 === - Add :ref:`install-lazy-loader` option. 3.3 === - Clean up file permissions and remove shebangs from scripts not intended to be executed on the command line. (contributed by :bbuser:`ralphbean`) - Worked on some brittle tests. - Received updates to Japanese translation of the documentation from :bbuser:`t2y`. - Fix the test script and runner so the user's ``$WORKON_HOME`` is not erased if they do not have some test shells installed. (big thanks to :bbuser:`agriffis`). - If the hook loader is told to list plugins but is not given a hook name, it prints the list of core hooks. - Merge several fixes for path and variable handling for MSYS users from :bbuser:`bwanamarko`. Includes a fix for :bbissue:`138`. - Change :ref:`command-mkvirtualenv` so it catches both ``-h`` and ``--help``. - Fix some issues with the way temporary files are used for hook scripts. (contributed by :bbuser:`agriffis`) - Allow relative path to requirements file with :ref:`command-mkvirtualenv` and ``-r`` option. (:bbuser:`barberj`) - Make whitespace consistent. (:bbuser:`agriffis`) 3.2 === - Make ``project_dir`` a local variable so that :ref:`command-cdproject` does not interfere with other variables the user might have set. (contributed by :bbuser:`slackorama`) - Fix typo in documentation reported by Nick Martin. - Change trove classifier for license "MIT" to reflect the license text presented in the documentation. *This does not indicate a change in the license, just a correction to the expression of that intent. See :ref:`license`* (contributed by :bbuser:`ralphbean` as fix for :bbissue:`134`) - Extend :ref:`command-rmvirtualenv` to allow removing more than one environment at a time. (contributed by :bbuser:`ciberglo`) - Change the definition of ``virtualenvwrapper_get_site_packages_dir`` to ask ``distutils`` for the ``site-packages`` directory instead of trying to build the path ourselves in the shell script. This should resolve :bbissue:`112` and improve support for Python interpreters other than C Python. Thanks to Carl Meyer and Dario Bertini for their contributions toward the fix. 3.1 === - Fix a problem with activation hooks when associating a new virtualenv with an existing project directory. (:bbissue:`122`) - Fix a problem with :ref:`command-add2virtualenv` and paths containing "special" characters such as ``&``. (:bbissue:`132`) 3.0.1 ===== - Fix some packaging issues that made it more difficult to run the tests directly from the sdist package. (:bbissue:`126`) 3.0 === - Add Python 3 support, thanks in large part to the efforts of Daniel Kraus (:bbuser:`dakra`). Tested under Python 2.6, 2.7, and 3.2. 2.11.1 ====== - Remove the initialization shortcut because it breaks tab completion in sub-shell environments like screen and tmux. (:bbissue:`121`) 2.11 ==== - Add ``-a`` option to :ref:`command-mkvirtualenv` to associate a new virtualenv with an existing project directory. Contributed by Mike Fogel (:bbuser:`mfogel`). - Drops support for Python 2.4 and 2.5. The tools may still work, but I no longer have a development environment set up for testing them, so I do not officially support them. - Shortcut initialization if it has run before. - Set hook log file permissions to be group-writable. (:bbissue:`62` reported by :bbuser:`hedgeddown`) - Add ``VIRTUALENVWRAPPER_PROJECT_FILENAME`` variable so the ``.project`` file used to link a virtualenv to a project can be renamed to avoid conflicts with other tools. (:bbissue:`120` reported by :bbuser:`arthuralvim`) 2.10.1 ====== - Changed arguments to :ref:`command-mktmpenv` so it always creates an environment name for you. (:bbissue:`114` reported by :bbuser:`alex_gaynor`) 2.10 ==== - Incorporated patch to add ``-d`` option to :ref:`command-add2virtualenv`, contributed by :bbuser:`miracle2k`. - Add ``-i`` option to :ref:`command-mkvirtualenv`. - Add :ref:`command-mktmpenv` command for creating temporary environments that are automatically removed when they are deactivated. - Fixed a problem with hook_loader that prevented it from working under Python 2.5 and 2.4. - Fix a problem with the way template names were processed under zsh. (:bbissue:`111`) 2.9 === - Change the shell function shell definition syntax so that ksh will treat typeset-declared variables as local. No kidding. - Merge the "project directory" features of the ``virtualenvwrapper.project`` plugin into the main project, adding :ref:`command-mkproject`, :ref:`command-cdproject`, and :ref:`command-setvirtualenvproject` commands. - Add ``-r`` option to :ref:`command-mkvirtualenv` to install dependencies using a pip requirements file. 2.8 === - Use VIRTUALENVWRAPPER_VIRTUALENV in `cpvirtualenv` (:bbissue:`104`). - Add support for `MSYS `_ environment under Windows. Contributed by Axel H. (:bbuser:`noirbizarre`). 2.7.2 ===== - Move setup code for tab completion later in the startup code so all of the needed variables are configured. (:bbissue:`97`) - Expand tab completion for zsh to work for all commands. 2.7.1 ===== - When testing for WORKON_HOME during startup, dereference any symlink to make sure it is a directory. - Set VIRTUALENVWRAPPER_HOOK_DIR and VIRTUALENV_WRAPPER_LOG DIR in virtualenvwrapper_initialize after WORKON_HOME is set (:bbissue:`94`). - Update the :ref:`install-basic` instructions to be more explicit about needing to install virtualenvwrapper globally (or at least outside of a virtualenv). 2.7 === - Fix problem with space in WORKON_HOME path (:bbissue:`79`). - Fix problem with argument processing in lsvirtualenv under zsh (:bbissue:`86`). Thanks to Nat Williams (:bbuser:`natw`) for the bug report and patch. - If WORKON_HOME does not exist, create it. Patch from Carl Karsten (:bbuser:`CarlFK`). Test updates based on patches from Matt Austin (:bbuser:`maafy6`) and Hugo Lopes Tavares (:bbuser:`hltbra`). - Merge in contributions from Paul McLanahan (:bbuser:`pmclanahan`) to fix the test harness to ensure that the test scripts are actually running under the expected shell. - Merge in new shell command :ref:`command-toggleglobalsitepackages` from Paul McLanahan (:bbuser:`pmclanahan`). The new command changes the configuration of the active virtualenv to enable or disable the global ``site-packages`` directory. - Fixed some tests that were failing under ksh on Ubuntu 10.10. - Document the :ref:`VIRTUALENVWRAPPER_VIRTUALENV ` variable. - Implement suggestion by Van Lindberg to have :ref:`VIRTUALENVWRAPPER_HOOK_DIR ` and :ref:`VIRTUALENVWRAPPER_LOG_DIR ` variables to control the locations of hooks and logs. - Enabled tab completion for :ref:`command-showvirtualenv` (:bbissue:`78`). - Fixed a problem with running :ref:`command-rmvirtualenv` from within the environment being removed (:bbissue:`83`). - Removed use of -e option in calls to grep for better portability (:bbissue:`85`). 2.6.3 ===== - Hard-code the version information in the setup.py and conf.py scripts. This still doesn't work for http://readthedocs.org, since the doc build needs the sphinxcontrib.bitbucket extension, but will make it easier to transition the docs to another site later. 2.6.2 ===== - Attempted to make the doc build work with http://readthedocs.org. - Merged in `Japanese translation of the documentation `__ from Tetsuya Morimoto. - Incorporate a suggestion from Ales Zoulek to let the user specify the virtualenv binary through an environment variable (:ref:`VIRTUALENVWRAPPER_VIRTUALENV `). 2.6.1 ===== - Fixed virtualenvwrapper_get_python_version (:bbissue:`73`). 2.6 === - Fixed a problem with hook script line endings under Cygwin (:bbissue:`68`). - Updated documentation to include a list of the compatible shells (:ref:`supported-shells`) and Python versions (:ref:`supported-versions`) (:bbissue:`70`). - Fixed installation dependency on virtualenv (:bbissue:`60`). - Fixed the method for determining the Python version so it works under Python 2.4 (:bbissue:`61`). - Converted the test infrastructure to use `tox `_ instead of home-grown scripts in the Makefile. 2.5.3 ===== - Point release uploaded to PyPI during outage on doughellmann.com. 2.5.2 ===== - Apply patch from Zach Voase to fix :ref:`command-lsvirtualenv` under zsh. Resolves :bbissue:`64`. 2.5.1 ===== - Make :ref:`command-workon` list brief environment details when run without argument, instead of full details. 2.5 === - Add :ref:`command-showvirtualenv` command. Modify :ref:`command-lsvirtualenv` to make verbose output the default. 2.4 === - Add :ref:`command-lsvirtualenv` command with ``-l`` option to run :ref:`scripts-get_env_details` hook instead of always running it when :ref:`command-workon` has no arguments. 2.3 === - Added ``get_env_details`` hook. 2.2.2 ===== - Integrate Fred Palmer's patch to escape more shell commands to avoid aliases. Resolves :bbissue:`57`. - Fix a problem with egrep argument escaping (:bbissue:`55`). - Fix a problem with running mkvirtualenv without arguments (:bbissue:`56`). 2.2.1 ===== - Escape ``which`` calls to avoid aliases. Resolves :bbissue:`46`. - Integrate Manuel Kaufmann's patch to unset GREP_OPTIONS before calling grep. Resolves :bbissue:`51`. - Escape ``$`` in regex to resolve :bbissue:`53`. - Escape ``rm`` to avoid issues with aliases and resolve :bbissue:`50`. 2.2 === - Switched hook loader execution to a form that works with Python 2.4 to resolve :bbissue:`43`. - Tested under Python 2.7b1. See :bbissue:`44`. - Incorporated performance improvements from David Wolever. See :bbissue:`38`. - Added some debug instrumentation for :bbissue:`35`. 2.1.1 ===== - Added `Spanish translation for the documentation `__ via Manuel Kaufmann's fork at http://bitbucket.org/humitos/virtualenvwrapper-es-translation/ - Fixed improper use of python from ``$PATH`` instead of the location where the wrappers are installed. See :bbissue:`41`. - Quiet spurrious error/warning messages when deactivating a virtualenv under zsh. See :bbissue:`42`. 2.1 === - Add support for ksh. Thanks to Doug Latornell for doing the research on what needed to be changed. - Test import of virtualenvwrapper.hook_loader on startup and report the error in a way that should help the user figure out how to fix it (:bbissue:`33`). - Update :ref:`command-mkvirtualenv` documentation to include the fact that a new environment is activated immediately after it is created (:bbissue:`30`). - Added hooks around :ref:`command-cpvirtualenv`. - Made deactivation more robust, especially under ksh. - Use Python's ``tempfile`` module for creating temporary filenames safely and portably. - Fix a problem with ``virtualenvwrapper_show_workon_options`` that caused it to show ``*`` as the name of a virtualenv when no environments had yet been created. - Change the hook loader so it can be told to run only a set of named hooks. - Add support for listing the available hooks, to be used in help output of commands like virtualenvwrapper.project's mkproject. - Fix mkvirtualenv -h option behavior. - Change logging so the $WORKON_HOME/hook.log file rotates after 10KiB. 2.0.2 ===== - Fixed :bbissue:`32`, making virtualenvwrapper.user_scripts compatible with Python 2.5 again. 2.0.1 ===== - Fixed :bbissue:`29`, to use a default value for ``TMPDIR`` if it is not set in the user's shell environment. 2.0 === - Rewrote hook management using Distribute_ entry points to make it easier to share extensions. .. _Distribute: http://packages.python.org/distribute/ 1.27 ==== - Added cpvirtualenv command [Thomas Desvenain] 1.26 ==== - Fix a problem with error messages showing up during init for users with the wrappers installed site-wide but who are not actually using them. See :bbissue:`26`. - Split up the tests into multiple files. - Run all tests with all supported shells. 1.25 ==== - Merged in changes to cdsitepackages from William McVey. It now takes an argument and supports tab-completion for directories within site-packages. 1.24.2 ====== - Add user provided :ref:`tips-and-tricks` section. - Add link to Rich Leland's screencast to :ref:`references` section. 1.24.1 ====== - Add license text to the header of the script. 1.24 ==== - Resolve a bug with the preactivate hook not being run properly. Refer to :bbissue:`21` for complete details. 1.23 ==== - Resolve a bug with the postmkvirtualenv hook not being run properly. Refer to :bbissue:`19` and :bbissue:`20` for complete details. 1.22 ==== - Automatically create any missing hook scripts as stubs with comments to expose the feature in case users are not aware of it. 1.21 ==== - Better protection of ``$WORKON_HOME`` does not exist when the wrapper script is sourced. 1.20 ==== - Incorporate lssitepackages feature from Sander Smits. - Refactor some of the functions that were using copy-and-paste code to build path names. - Add a few tests. 1.19 ==== - Fix problem with add2virtualenv and relative paths. Thanks to Doug Latornell for the bug report James Bennett for the suggested fix. 1.18.1 ====== - Incorporate patch from Sascha Brossmann to fix a :bbissue:`15`. Directory normalization was causing ``WORKON_HOME`` to appear to be a missing directory if there were control characters in the output of ``pwd``. 1.18 ==== - Remove warning during installation if sphinxcontrib.paverutils is not installed. (:bbissue:`10`) - Added some basic developer information to the documentation. - Added documentation for deactivate command. 1.17 ==== - Added documentation updates provided by Steve Steiner. 1.16 ==== - Merged in changes to ``cdvirtualenv`` from wam and added tests and docs. - Merged in changes to make error messages go to stderr, also provided by wam. 1.15 ==== - Better error handling in mkvirtualenv. - Remove bogus VIRTUALENV_WRAPPER_BIN variable. 1.14 ==== - Wrap the virtualenv version of deactivate() with one that lets us invoke the predeactivate hooks. - Fix virtualenvwrapper_show_workon_options for colorized versions of ls and write myself a note so I don't break it again later. - Convert test.sh to use true tests with `shunit2 `_ 1.13 ==== - Fix :bbissue:`5` by correctly handling symlinks and limiting the list of envs to things that look like they can be activated. 1.12 ==== - Check return value of virtualenvwrapper_verify_workon_home everywhere, thanks to Jeff Forcier for pointing out the errors. - Fix instructions at top of README, pointed out by Matthew Scott. - Add cdvirtualenv and cdsitepackages, contributed by James Bennett. - Enhance test.sh. 1.11 ==== - Optimize virtualenvwrapper_show_workon_options. - Add global postactivate hook. 1.10 ==== - Pull in fix for colorized ls from Jeff Forcier (:bbchangeset:`b42a25f7b74a`). 1.9 === - Add more hooks for operations to run before and after creating or deleting environments based on changes from Chris Hasenpflug. 1.8.1 ===== - Corrected a problem with change to mkvirtualenv that lead to release 1.8 by using an alternate fix proposed by James in comments on release 1.4. 1.8 === - Fix for processing the argument list in mkvirtualenv from jorgevargas (:bbissue:`1`) 1.7 === - Move to bitbucket.org for hosting - clean up TODO list and svn keywords - add license section below 1.6.1 ===== - More zsh support (fixes to rmvirtualenv) from Byron Clark. 1.6 === - Add completion support for zsh, courtesy of Ted Leung. 1.5 === - Fix some issues with spaces in directory or env names. They still don't really work with virtualenv, though. - Added documentation for the postactivate and predeactivate scripts. 1.4 === - Includes a new .pth management function based on work contributed by James Bennett and Jannis Leidel. 1.3.x ===== - Includes a fix for a nasty bug in rmvirtualenv identified by John Shimek. virtualenvwrapper-4.1.1/docs/source/hooks.rst0000644000101700007650000000056412143435521023356 0ustar dhellmanndhellmann00000000000000=============================== Customizing Virtualenvwrapper =============================== virtualenvwrapper adds several hook points you can use to change your settings, shell environment, or other configuration values when creating, deleting, or moving between environments. These hooks are exposed in two ways: .. toctree:: :maxdepth: 1 scripts plugins virtualenvwrapper-4.1.1/docs/source/index.rst0000644000101700007650000002262012143435521023337 0ustar dhellmanndhellmann00000000000000.. virtualenvwrapper documentation master file, created by sphinx-quickstart on Thu May 28 22:35:13 2009. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. ########################### virtualenvwrapper |release| ########################### virtualenvwrapper is a set of extensions to Ian Bicking's `virtualenv `_ tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. ======== Features ======== 1. Organizes all of your virtual environments in one place. 2. Wrappers for managing your virtual environments (create, delete, copy). 3. Use a single command to switch between environments. 4. Tab completion for commands that take a virtual environment as argument. 5. User-configurable hooks for all operations (see :ref:`scripts`). 6. Plugin system for more creating sharable extensions (see :ref:`plugins`). ============ Introduction ============ The best way to explain the features virtualenvwrapper gives you is to show it in use. First, some initialization steps. Most of this only needs to be done one time. You will want to add the command to ``source /usr/local/bin/virtualenvwrapper.sh`` to your shell startup file, changing the path to virtualenvwrapper.sh depending on where it was installed by pip. :: $ pip install virtualenvwrapper ... $ export WORKON_HOME=~/Envs $ mkdir -p $WORKON_HOME $ source /usr/local/bin/virtualenvwrapper.sh $ mkvirtualenv env1 Installing distribute.......................................... .................................................... .................................................... ...............................done. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/predeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postdeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/preactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env1/bin/postactivate New python executable in env1/bin/python (env1)$ ls $WORKON_HOME env1 hook.log Now we can install some software into the environment. :: (env1)$ pip install django Downloading/unpacking django Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded Running setup.py egg_info for package django Installing collected packages: django Running setup.py install for django changing mode of build/scripts-2.6/django-admin.py from 644 to 755 changing mode of /Users/dhellmann/Envs/env1/bin/django-admin.py to 755 Successfully installed django We can see the new package with ``lssitepackages``:: (env1)$ lssitepackages Django-1.1.1-py2.6.egg-info easy-install.pth distribute-0.6.10-py2.6.egg pip-0.6.3-py2.6.egg django setuptools.pth Of course we are not limited to a single virtualenv:: (env1)$ ls $WORKON_HOME env1 hook.log (env1)$ mkvirtualenv env2 Installing distribute............................... .................................................... .................................................... ........... ...............................done. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/predeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postdeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/preactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env2/bin/postactivate New python executable in env2/bin/python (env2)$ ls $WORKON_HOME env1 env2 hook.log Switch between environments with ``workon``:: (env2)$ workon env1 (env1)$ echo $VIRTUAL_ENV /Users/dhellmann/Envs/env1 (env1)$ The ``workon`` command also includes tab completion for the environment names, and invokes customization scripts as an environment is activated or deactivated (see :ref:`scripts`). :: (env1)$ echo 'cd $VIRTUAL_ENV' >> $WORKON_HOME/postactivate (env1)$ workon env2 (env2)$ pwd /Users/dhellmann/Envs/env2 :ref:`scripts-postmkvirtualenv` is run when a new environment is created, letting you automatically install commonly-used tools. :: (env2)$ echo 'pip install sphinx' >> $WORKON_HOME/postmkvirtualenv (env3)$ mkvirtualenv env3 New python executable in env3/bin/python Installing distribute............................... .................................................... .................................................... ........... ...............................done. virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/predeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postdeactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/preactivate virtualenvwrapper.user_scripts Creating /Users/dhellmann/Envs/env3/bin/postactivate Downloading/unpacking sphinx Downloading Sphinx-0.6.5.tar.gz (972Kb): 972Kb downloaded Running setup.py egg_info for package sphinx no previously-included directories found matching 'doc/_build' Downloading/unpacking Pygments>=0.8 (from sphinx) Downloading Pygments-1.3.1.tar.gz (1.1Mb): 1.1Mb downloaded Running setup.py egg_info for package Pygments Downloading/unpacking Jinja2>=2.1 (from sphinx) Downloading Jinja2-2.4.tar.gz (688Kb): 688Kb downloaded Running setup.py egg_info for package Jinja2 warning: no previously-included files matching '*' found under directory 'docs/_build/doctrees' Downloading/unpacking docutils>=0.4 (from sphinx) Downloading docutils-0.6.tar.gz (1.4Mb): 1.4Mb downloaded Running setup.py egg_info for package docutils Installing collected packages: docutils, Jinja2, Pygments, sphinx Running setup.py install for docutils Running setup.py install for Jinja2 Running setup.py install for Pygments Running setup.py install for sphinx no previously-included directories found matching 'doc/_build' Installing sphinx-build script to /Users/dhellmann/Envs/env3/bin Installing sphinx-quickstart script to /Users/dhellmann/Envs/env3/bin Installing sphinx-autogen script to /Users/dhellmann/Envs/env3/bin Successfully installed docutils Jinja2 Pygments sphinx (env3)$ (venv3)$ which sphinx-build /Users/dhellmann/Envs/env3/bin/sphinx-build Through a combination of the existing functions defined by the core package (see :ref:`command`), third-party plugins (see :ref:`plugins`), and user-defined scripts (see :ref:`scripts`) virtualenvwrapper gives you a wide variety of opportunities to automate repetitive operations. ======= Details ======= .. toctree:: :maxdepth: 2 install command_ref hooks projects tips developers extensions design history .. _references: ========== References ========== `virtualenv `_, from Ian Bicking, is a pre-requisite to using these extensions. For more details, refer to the column I wrote for the May 2008 issue of Python Magazine: `virtualenvwrapper | And Now For Something Completely Different `_. Rich Leland has created a short `screencast `__ showing off the features of virtualenvwrapper. Manuel Kaufmann has `translated this documentation into Spanish `__. Tetsuya Morimoto has `translated this documentation into Japanese `__. ======= Support ======= Join the `virtualenvwrapper Google Group `__ to discuss issues and features. Report bugs via the `bug tracker on BitBucket `__. Shell Aliases ============= Since virtualenvwrapper is largely a shell script, it uses shell commands for a lot of its actions. If your environment makes heavy use of shell aliases or other customizations, you may encounter issues. Before reporting bugs in the bug tracker, please test *without* your aliases enabled. If you can identify the alias causing the problem, that will help make virtualenvwrapper more robust. .. _license: ======= License ======= Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. virtualenvwrapper-4.1.1/docs/source/install.rst0000644000101700007650000002363112143435521023701 0ustar dhellmanndhellmann00000000000000============ Installation ============ .. _supported-shells: Supported Shells ================ virtualenvwrapper is a set of shell *functions* defined in Bourne shell compatible syntax. Its automated tests run under these shells on OS X and Linux: * ``bash`` * ``ksh`` * ``zsh`` It may work with other shells, so if you find that it does work with a shell not listed here please let me know. If you can modify it to work with another shell without completely rewriting it, then send a pull request through the `bitbucket project page`_. If you write a clone to work with an incompatible shell, let me know and I will link to it from this page. .. _bitbucket project page: https://bitbucket.org/dhellmann/virtualenvwrapper/ Windows Command Prompt ---------------------- David Marble has ported virtualenvwrapper to Windows batch scripts, which can be run under Microsoft Windows Command Prompt. This is also a separately distributed re-implementation. You can download `virtualenvwrapper-win`_ from PyPI. .. _virtualenvwrapper-win: http://pypi.python.org/pypi/virtualenvwrapper-win MSYS ---- It is possible to use virtualenv wrapper under `MSYS `_ with a native Windows Python installation. In order to make it work, you need to define an extra environment variable named ``MSYS_HOME`` containing the root path to the MSYS installation. :: export WORKON_HOME=$HOME/.virtualenvs export MSYS_HOME=/c/msys/1.0 source /usr/local/bin/virtualenvwrapper.sh or:: export WORKON_HOME=$HOME/.virtualenvs export MSYS_HOME=C:\msys\1.0 source /usr/local/bin/virtualenvwrapper.sh Depending on your MSYS setup, you may need to install the `MSYS mktemp binary`_ in the ``MSYS_HOME/bin`` folder. .. _MSYS mktemp binary: http://sourceforge.net/projects/mingw/files/MSYS/mktemp/ PowerShell ---------- Guillermo López-Anglada has ported virtualenvwrapper to run under Microsoft's PowerShell. We have agreed that since it is not compatible with the rest of the extensions, and is largely a re-implementation (rather than an adaptation), it should be distributed separately. You can download virtualenvwrapper-powershell_ from PyPI. .. _virtualenvwrapper-powershell: http://pypi.python.org/pypi/virtualenvwrapper-powershell/2.7.1 .. _supported-versions: Python Versions =============== virtualenvwrapper is tested under Python 2.6-3.3. .. _install-basic: Basic Installation ================== virtualenvwrapper should be installed into the same global site-packages area where virtualenv is installed. You may need administrative privileges to do that. The easiest way to install it is using pip_:: $ pip install virtualenvwrapper or:: $ sudo pip install virtualenvwrapper .. warning:: virtualenv lets you create many different Python environments. You should only ever install virtualenv and virtualenvwrapper on your base Python installation (i.e. NOT while a virtualenv is active) so that the same release is shared by all Python environments that depend on it. An alternative to installing it into the global site-packages is to add it to `your user local directory `__ (usually `~/.local`). :: $ pip install --install-option="--user" virtualenvwrapper .. _install-shell-config: Shell Startup File ================== Add three lines to your shell startup file (``.bashrc``, ``.profile``, etc.) to set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:: export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/Devel source /usr/local/bin/virtualenvwrapper.sh After editing it, reload the startup file (e.g., run ``source ~/.bashrc``). .. _install-lazy-loader: Lazy Loading ------------ An alternative initialization script is provided for loading virtualenvwrapper lazily. Instead of sourcing ``virtualenvwrapper.sh`` directly, use ``virtualenvwrapper_lazy.sh``. If ``virtualenvwrapper.sh`` is not on your ``$PATH``, set ``VIRTUALENVWRAPPER_SCRIPT`` to point to it. :: export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/Devel export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh source /usr/local/bin/virtualenvwrapper_lazy.sh .. warning:: When the lazy-loading version of the startup script is used, tab-completion of arguments to virtualenvwrapper commands (such as environment names) is not enabled until after the first command has been run. For example, tab completion of environments does not work for the first instance of :ref:`command-workon`. Quick-Start =========== 1. Run: ``workon`` 2. A list of environments, empty, is printed. 3. Run: ``mkvirtualenv temp`` 4. A new environment, ``temp`` is created and activated. 5. Run: ``workon`` 6. This time, the ``temp`` environment is included. Configuration ============= virtualenvwrapper can be customized by changing environment variables. Set the variables in your shell startup file *before* loading ``virtualenvwrapper.sh``. .. _variable-WORKON_HOME: Location of Environments ------------------------ The variable ``WORKON_HOME`` tells virtualenvwrapper where to place your virtual environments. The default is ``$HOME/.virtualenvs``. If the directory does not exist when virtualenvwrapper is loaded, it will be created automatically. .. _variable-PROJECT_HOME: Location of Project Directories ------------------------------- The variable ``PROJECT_HOME`` tells virtualenvwrapper where to place your project working directories. The variable must be set and the directory created before :ref:`command-mkproject` is used. .. seealso:: * :ref:`project-management` .. _variable-VIRTUALENVWRAPPER_PROJECT_FILENAME: Project Linkage Filename ------------------------ The variable ``VIRTUALENVWRAPPER_PROJECT_FILENAME`` tells virtualenvwrapper how to name the file linking a virtualenv to a project working directory. The default is ``.project``. .. seealso:: * :ref:`project-management` .. _variable-VIRTUALENVWRAPPER_HOOK_DIR: Location of Hook Scripts ------------------------ The variable ``VIRTUALENVWRAPPER_HOOK_DIR`` tells virtualenvwrapper where the :ref:`user-defined hooks ` should be placed. The default is ``$WORKON_HOME``. .. seealso:: * :ref:`scripts` .. _variable-VIRTUALENVWRAPPER_LOG_FILE: Location of Hook Logs --------------------- The variable ``VIRTUALENVWRAPPER_LOG_FILE`` tells virtualenvwrapper where the logs for the hook loader should be written. The default is to not log from the hooks. .. _variable-VIRTUALENVWRAPPER_VIRTUALENV: .. _variable-VIRTUALENVWRAPPER_VIRTUALENV_ARGS: .. _variable-VIRTUALENVWRAPPER_PYTHON: Python Interpreter, virtualenv, and $PATH ----------------------------------------- During startup, ``virtualenvwrapper.sh`` finds the first ``python`` and ``virtualenv`` programs on the ``$PATH`` and remembers them to use later. This eliminates any conflict as the ``$PATH`` changes, enabling interpreters inside virtual environments where virtualenvwrapper is not installed or where different versions of virtualenv are installed. Because of this behavior, it is important for the ``$PATH`` to be set **before** sourcing ``virtualenvwrapper.sh``. For example:: export PATH=/usr/local/bin:$PATH source /usr/local/bin/virtualenvwrapper.sh To override the ``$PATH`` search, set the variable ``VIRTUALENVWRAPPER_PYTHON`` to the full path of the interpreter to use and ``VIRTUALENVWRAPPER_VIRTUALENV`` to the full path of the ``virtualenv`` binary to use. Both variables *must* be set before sourcing ``virtualenvwrapper.sh``. For example:: export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv source /usr/local/bin/virtualenvwrapper.sh Default Arguments for virtualenv -------------------------------- If the application identified by ``VIRTUALENVWRAPPER_VIRTUALENV`` needs arguments, they can be set in ``VIRTUALENVWRAPPER_VIRTUALENV_ARGS``. The same variable can be used to set default arguments to be passed to ``virtualenv``. For example, set the value to ``--no-site-packages`` to ensure that all new environments are isolated from the system ``site-packages`` directory. :: export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' Temporary Files --------------- virtualenvwrapper creates temporary files in ``$TMPDIR``. If the variable is not set, it uses ``/tmp``. To change the location of temporary files just for virtualenvwrapper, set ``VIRTUALENVWRAPPER_TMPDIR``. Site-wide Configuration ----------------------- Most UNIX systems include the ability to change the configuration for all users. This typically takes one of two forms: editing the *skeleton* files for new accounts or editing the global startup file for a shell. Editing the skeleton files for new accounts means that each new user will have their private startup files preconfigured to load virtualenvwrapper. They can disable it by commenting out or removing those lines. Refer to the documentation for the shell and operating system to identify the appropriate file to edit. Modifying the global startup file for a given shell means that all users of that shell will have virtualenvwrapper enabled, and they cannot disable it. Refer to the documentation for the shell to identify the appropriate file to edit. Upgrading to 2.9 ================ Version 2.9 includes the features previously delivered separately by ``virtualenvwrapper.project``. If you have an older verison of the project extensions installed, remove them before upgrading. Upgrading from 1.x ================== The shell script containing the wrapper functions has been renamed in the 2.x series to reflect the fact that shells other than bash are supported. In your startup file, change ``source /usr/local/bin/virtualenvwrapper_bashrc`` to ``source /usr/local/bin/virtualenvwrapper.sh``. .. _pip: http://pypi.python.org/pypi/pip virtualenvwrapper-4.1.1/docs/source/plugins.rst0000644000101700007650000003407212143435521023715 0ustar dhellmanndhellmann00000000000000.. _plugins: =========================== Extending Virtualenvwrapper =========================== Long experience with home-grown solutions for customizing a development environment has proven how valuable it can be to have the ability to automate common tasks and eliminate persistent annoyances. Carpenters build jigs, software developers write shell scripts. virtualenvwrapper continues the tradition of encouraging a craftsman to modify their tools to work the way they want, rather than the other way around. Use the hooks provided to eliminate repetitive manual operations and streamline your development workflow. For example, set up the :ref:`plugins-pre_activate` and :ref:`plugins-post_activate` hooks to trigger an IDE to load a project file to reload files from the last editing session, manage time-tracking records, or start and stop development versions of an application server. Use the :ref:`plugins-initialize` hook to add entirely new commands and hooks to virtualenvwrapper. And the :ref:`plugins-pre_mkvirtualenv` and :ref:`plugins-post_mkvirtualenv` hooks give you an opportunity to install basic requirements into each new development environment, initialize a source code control repository, or otherwise set up a new project. There are two ways to attach your code so that virtualenvwrapper will run it: End-users can use shell scripts or other programs for personal customization (see :ref:`scripts`). Extensions can also be implemented in Python by using Distribute_ *entry points*, making it possible to share common behaviors between systems and developers. Defining an Extension ===================== .. note:: Virtualenvwrapper is delivered with a plugin for creating and running the user customization scripts (:ref:`extensions-user_scripts`). The examples below are taken from the implementation of that plugin. Code Organization ----------------- The Python package for ``virtualenvwrapper`` is a *namespace package*. That means multiple libraries can install code into the package, even if they are not distributed together or installed into the same directory. Extensions can (optionally) use the ``virtualenvwrapper`` namespace by setting up their source tree like: * virtualenvwrapper/ * __init__.py * user_scripts.py And placing the following code in ``__init__.py``:: """virtualenvwrapper module """ __import__('pkg_resources').declare_namespace(__name__) .. note:: Extensions can be loaded from any package, so using the ``virtualenvwrapper`` namespace is not required. Extension API ------------- After the package is established, the next step is to create a module to hold the extension code. For example, ``virtualenvwrapper/user_scripts.py``. The module should contain the actual extension entry points. Supporting code can be included, or imported from elsewhere using standard Python code organization techniques. The API is the same for every extension point. Each uses a Python function that takes a single argument, a list of strings passed to the hook loader on the command line. :: def function_name(args): # args is a list of strings passed to the hook loader The contents of the argument list are defined for each extension point below (see :ref:`plugins-extension-points`). Extension Invocation -------------------- Direct Action ~~~~~~~~~~~~~ Plugins can attach to each hook in two different ways. The default is to have a function run and do some work directly. For example, the ``initialize()`` function for the user scripts plugin creates default user scripts when ``virtualenvwrapper.sh`` is loaded. :: def initialize(args): for filename, comment in GLOBAL_HOOKS: make_hook(os.path.join('$WORKON_HOME', filename), comment) return .. _plugins-user-env: Modifying the User Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are cases where the extension needs to update the user's environment (e.g., changing the current working directory or setting environment variables). Modifications to the user environment must be made within the user's current shell, and cannot be run in a separate process. To have code run in the user's shell process, extensions can define hook functions to return the text of the shell statements to be executed. These *source* hooks are run after the regular hooks with the same name, and should not do any work of their own. The ``initialize_source()`` hook for the user scripts plugin looks for a global initialize script and causes it to be run in the current shell process. :: def initialize_source(args): return """ # # Run user-provided scripts # [ -f "$WORKON_HOME/initialize" ] && source "$WORKON_HOME/initialize" """ .. warning:: Because the extension is modifying the user's working shell, care must be taken not to corrupt the environment by overwriting existing variable values unexpectedly. Avoid creating temporary variables where possible, and use unique names where variables cannot be avoided. Prefixing variables with the extension name is a good way to manage the namespace. For example, instead of ``temp_file`` use ``user_scripts_temp_file``. Use ``unset`` to release temporary variable names when they are no longer needed. .. warning:: virtualenvwrapper works under several shells with slightly different syntax (bash, sh, zsh, ksh). Take this portability into account when defining source hooks. Sticking to the simplest possible syntax usually avoids problems, but there may be cases where examining the ``SHELL`` environment variable to generate different syntax for each case is the only way to achieve the desired result. Registering Entry Points ------------------------ The functions defined in the plugin need to be registered as *entry points* in order for virtualenvwrapper's hook loader to find them. Distribute_ entry points are configured in the ``setup.py`` for your package by mapping the entry point name to the function in the package that implements it. This partial copy of virtualenvwrapper's ``setup.py`` illustrates how the ``initialize()`` and ``initialize_source()`` entry points are configured. :: # Bootstrap installation of Distribute import distribute_setup distribute_setup.use_setuptools() from setuptools import setup setup( name = 'virtualenvwrapper', version = '2.0', description = 'Enhancements to virtualenv', # ... details omitted ... namespace_packages = [ 'virtualenvwrapper' ], entry_points = { 'virtualenvwrapper.initialize': [ 'user_scripts = virtualenvwrapper.user_scripts:initialize', ], 'virtualenvwrapper.initialize_source': [ 'user_scripts = virtualenvwrapper.user_scripts:initialize_source', ], # ... details omitted ... }, ) The ``entry_points`` argument to ``setup()`` is a dictionary mapping the entry point *group names* to lists of entry point specifiers. A different group name is defined by virtualenvwrapper for each extension point (see :ref:`plugins-extension-points`). The entry point specifiers are strings with the syntax ``name = package.module:function``. By convention, the *name* of each entry point is the plugin name, but that is not required (the names are not used). .. seealso:: * `namespace packages `__ * `Extensible Applications and Frameworks `__ The Hook Loader --------------- Extensions are run through a command line application implemented in ``virtualenvwrapper.hook_loader``. Because ``virtualenvwrapper.sh`` is the primary caller and users do not typically need to run the app directly, no separate script is installed. Instead, to run the application, use the ``-m`` option to the interpreter:: $ python -m virtualenvwrapper.hook_loader -h Usage: virtualenvwrapper.hook_loader [options] [] Manage hooks for virtualenvwrapper Options: -h, --help show this help message and exit -s, --source Print the shell commands to be run in the current shell -l, --list Print a list of the plugins available for the given hook -v, --verbose Show more information on the console -q, --quiet Show less information on the console -n NAMES, --name=NAMES Only run the hook from the named plugin To run the extensions for the initialize hook:: $ python -m virtualenvwrapper.hook_loader -v initialize To get the shell commands for the initialize hook:: $ python -m virtualenvwrapper.hook_loader --source initialize In practice, rather than invoking the hook loader directly it is more convenient to use the shell function, ``virtualenvwrapper_run_hook`` to run the hooks in both modes.:: $ virtualenvwrapper_run_hook initialize All of the arguments given to shell function are passed directly to the hook loader. Logging ------- The hook loader configures logging so that messages are written to ``$WORKON_HOME/hook.log``. Messages also may be written to stderr, depending on the verbosity flag. The default is for messages at *info* or higher levels to be written to stderr, and *debug* or higher to go to the log file. Using logging in this way provides a convenient mechanism for users to control the verbosity of extensions. To use logging from within your extension, simply instantiate a logger and call its ``info()``, ``debug()`` and other methods with the messages. :: import logging log = logging.getLogger(__name__) def pre_mkvirtualenv(args): log.debug('pre_mkvirtualenv %s', str(args)) # ... .. seealso:: * `Standard library documentation for logging `__ * `PyMOTW for logging `__ .. _plugins-extension-points: Extension Points ================ The extension point names for native plugins follow a naming convention with several parts: ``virtualenvwrapper.(pre|post)_[_source]``. The ** is the action taken by the user or virtualenvwrapper that triggers the extension. ``(pre|post)`` indicates whether to call the extension before or after the event. The suffix ``_source`` is added for extensions that return shell code instead of taking action directly (see :ref:`plugins-user-env`). .. _plugins-get_env_details: get_env_details =============== The ``virtualenvwrapper.get_env_details`` hooks are run when ``workon`` is run with no arguments and a list of the virtual environments is printed. The hook is run once for each environment, after the name is printed, and can be used to show additional information about that environment. .. _plugins-initialize: initialize ---------- The ``virtualenvwrapper.initialize`` hooks are run each time ``virtualenvwrapper.sh`` is loaded into the user's environment. The initialize hook can be used to install templates for configuration files or otherwise prepare the system for proper plugin operation. .. _plugins-pre_mkvirtualenv: pre_mkvirtualenv ---------------- The ``virtualenvwrapper.pre_mkvirtualenv`` hooks are run after the virtual environment is created, but before the new environment is activated. The current working directory for when the hook is run is ``$WORKON_HOME`` and the name of the new environment is passed as an argument. .. _plugins-post_mkvirtualenv: post_mkvirtualenv ----------------- The ``virtualenvwrapper.post_mkvirtualenv`` hooks are run after a new virtual environment is created and activated. ``$VIRTUAL_ENV`` is set to point to the new environment. .. _plugins-pre_activate: pre_activate ------------ The ``virtualenvwrapper.pre_activate`` hooks are run just before an environment is enabled. The environment name is passed as the first argument. .. _plugins-post_activate: post_activate ------------- The ``virtualenvwrapper.post_activate`` hooks are run just after an environment is enabled. ``$VIRTUAL_ENV`` is set to point to the current environment. .. _plugins-pre_deactivate: pre_deactivate -------------- The ``virtualenvwrapper.pre_deactivate`` hooks are run just before an environment is disabled. ``$VIRTUAL_ENV`` is set to point to the current environment. .. _plugins-post_deactivate: post_deactivate --------------- The ``virtualenvwrapper.post_deactivate`` hooks are run just after an environment is disabled. The name of the environment just deactivated is passed as the first argument. .. _plugins-pre_rmvirtualenv: pre_rmvirtualenv ---------------- The ``virtualenvwrapper.pre_rmvirtualenv`` hooks are run just before an environment is deleted. The name of the environment being deleted is passed as the first argument. .. _plugins-post_rmvirtualenv: post_rmvirtualenv ----------------- The ``virtualenvwrapper.post_rmvirtualenv`` hooks are run just after an environment is deleted. The name of the environment being deleted is passed as the first argument. Adding New Extension Points =========================== Plugins that define new operations can also define new extension points. No setup needs to be done to allow the hook loader to find the extensions; documenting the names and adding calls to ``virtualenvwrapper_run_hook`` is sufficient to cause them to be invoked. The hook loader assumes all extension point names start with ``virtualenvwrapper.`` and new plugins will want to use their own namespace qualifier to append to that. For example, the project_ extension defines new events around creating project directories (pre and post). These are called ``virtualenvwrapper.project.pre_mkproject`` and ``virtualenvwrapper.project.post_mkproject``. These are invoked with:: virtualenvwrapper_run_hook project.pre_mkproject $project_name and:: virtualenvwrapper_run_hook project.post_mkproject respectively. .. _Distribute: http://packages.python.org/distribute/ .. _project: http://www.doughellmann.com/projects/virtualenvwrapper.project/ virtualenvwrapper-4.1.1/docs/source/projects.rst0000644000101700007650000000253212143435521024061 0ustar dhellmanndhellmann00000000000000.. _project-management: ==================== Project Management ==================== A :term:`project directory` is associated with a virtualenv, but usually contains the source code under active development rather than the installed components needed to support the development. For example, the project directory may contain the source code checked out from a version control system, temporary artifacts created by testing, experimental files not committed to version control, etc. A project directory is created and bound to a virtualenv when :ref:`command-mkproject` is run instead of :ref:`command-mkvirtualenv`. To bind an existing project directory to a virtualenv, use :ref:`command-setvirtualenvproject`. Using Templates =============== A new project directory can be created empty, or populated using one or more :term:`template` plugins. Templates should be specified as arguments to :ref:`command-mkproject`. Multiple values can be provided to apply more than one template. For example, to check out a Mercurial repository from on a project on bitbucket and create a new Django site, combine the :ref:`templates-bitbucket` and :ref:`templates-django` templates. :: $ mkproject -t bitbucket -t django my_site .. seealso:: * :ref:`extensions-templates` * :ref:`variable-PROJECT_HOME` * :ref:`variable-VIRTUALENVWRAPPER_PROJECT_FILENAME` virtualenvwrapper-4.1.1/docs/source/scripts.rst0000644000101700007650000001525212143435521023722 0ustar dhellmanndhellmann00000000000000.. _scripts: ======================== Per-User Customization ======================== The end-user customization scripts are either *sourced* (allowing them to modify your shell environment) or *run* as an external program at the appropriate trigger time. The global scripts applied to all environments should be placed in the directory named by :ref:`VIRTUALENVWRAPPER_HOOK_DIR `. The local scripts should be placed in the ``bin`` directory of the virtualenv. .. _scripts-get_env_details: get_env_details =============== :Global/Local: both :Argument(s): env name :Sourced/Run: run ``$VIRTUALENVWRAPPER_HOOK_DIR/get_env_details`` is run when ``workon`` is run with no arguments and a list of the virtual environments is printed. The hook is run once for each environment, after the name is printed, and can print additional information about that environment. .. _scripts-initialize: initialize ========== :Global/Local: global :Argument(s): None :Sourced/Run: sourced ``$VIRTUALENVWRAPPER_HOOK_DIR/initialize`` is sourced when ``virtualenvwrapper.sh`` is loaded into your environment. Use it to adjust global settings when virtualenvwrapper is enabled. .. _scripts-premkvirtualenv: premkvirtualenv =============== :Global/Local: global :Argument(s): name of new environment :Sourced/Run: run ``$VIRTUALENVWRAPPER_HOOK_DIR/premkvirtualenv`` is run as an external program after the virtual environment is created but before the current environment is switched to point to the new env. The current working directory for the script is ``$WORKON_HOME`` and the name of the new environment is passed as an argument to the script. .. _scripts-postmkvirtualenv: postmkvirtualenv ================ :Global/Local: global :Argument(s): none :Sourced/Run: sourced ``$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv`` is sourced after the new environment is created and activated. If the ``-a`` flag was used, the link to the project directory is set up before this script is sourced. .. _scripts-precpvirtualenv: precpvirtualenv =============== :Global/Local: global :Argument(s): name of original environment, name of new environment :Sourced/Run: run ``$VIRTUALENVWRAPPER_HOOK_DIR/precpvirtualenv`` is run as an external program after the source environment is duplicated and made relocatable, but before the ``premkvirtualenv`` hook is run or the current environment is switched to point to the new env. The current working directory for the script is ``$WORKON_HOME`` and the names of the source and new environments are passed as arguments to the script. .. _scripts-postcpvirtualenv: postcpvirtualenv ================ :Global/Local: global :Argument(s): none :Sourced/Run: sourced ``$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv`` is sourced after the new environment is created and activated. .. _scripts-preactivate: preactivate =========== :Global/Local: global, local :Argument(s): environment name :Sourced/Run: run The global ``$VIRTUALENVWRAPPER_HOOK_DIR/preactivate`` script is run before the new environment is enabled. The environment name is passed as the first argument. The local ``$VIRTUAL_ENV/bin/preactivate`` hook is run before the new environment is enabled. The environment name is passed as the first argument. .. _scripts-postactivate: postactivate ============ :Global/Local: global, local :Argument(s): none :Sourced/Run: sourced The global ``$VIRTUALENVWRAPPER_HOOK_DIR/postactivate`` script is sourced after the new environment is enabled. ``$VIRTUAL_ENV`` refers to the new environment at the time the script runs. This example script adds a space between the virtual environment name and your old PS1 by making use of ``_OLD_VIRTUAL_PS1``. :: PS1="(`basename \"$VIRTUAL_ENV\"`) $_OLD_VIRTUAL_PS1" The local ``$VIRTUAL_ENV/bin/postactivate`` script is sourced after the new environment is enabled. ``$VIRTUAL_ENV`` refers to the new environment at the time the script runs. This example script for the PyMOTW environment changes the current working directory and the PATH variable to refer to the source tree containing the PyMOTW source. :: pymotw_root=/Users/dhellmann/Documents/PyMOTW cd $pymotw_root PATH=$pymotw_root/bin:$PATH .. _scripts-predeactivate: predeactivate ============= :Global/Local: local, global :Argument(s): none :Sourced/Run: sourced The local ``$VIRTUAL_ENV/bin/predeactivate`` script is sourced before the current environment is deactivated, and can be used to disable or clear settings in your environment. ``$VIRTUAL_ENV`` refers to the old environment at the time the script runs. The global ``$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate`` script is sourced before the current environment is deactivated. ``$VIRTUAL_ENV`` refers to the old environment at the time the script runs. .. _scripts-postdeactivate: postdeactivate ============== :Global/Local: local, global :Argument(s): none :Sourced/Run: sourced The ``$VIRTUAL_ENV/bin/postdeactivate`` script is sourced after the current environment is deactivated, and can be used to disable or clear settings in your environment. The path to the environment just deactivated is available in ``$VIRTUALENVWRAPPER_LAST_VIRTUALENV``. .. _scripts-prermvirtualenv: prermvirtualenv =============== :Global/Local: global :Argument(s): environment name :Sourced/Run: run The ``$VIRTUALENVWRAPPER_HOOK_DIR/prermvirtualenv`` script is run as an external program before the environment is removed. The full path to the environment directory is passed as an argument to the script. .. _scripts-postrmvirtualenv: postrmvirtualenv ================ :Global/Local: global :Argument(s): environment name :Sourced/Run: run The ``$VIRTUALENVWRAPPER_HOOK_DIR/postrmvirtualenv`` script is run as an external program after the environment is removed. The full path to the environment directory is passed as an argument to the script. .. _scripts-premkproject: premkproject ============ :Global/Local: global :Argument(s): name of new project :Sourced/Run: run ``$WORKON_HOME/premkproject`` is run as an external program after the virtual environment is created and after the current environment is switched to point to the new env, but before the new project directory is created. The current working directory for the script is ``$PROJECT_HOME`` and the name of the new project is passed as an argument to the script. .. _scripts-postmkproject: postmkproject ============= :Global/Local: global :Argument(s): none :Sourced/Run: sourced ``$WORKON_HOME/postmkproject`` is sourced after the new environment and project directories are created and the virtualenv is activated. The current working directory is the project directory. virtualenvwrapper-4.1.1/docs/source/tips.rst0000644000101700007650000001065512143435521023214 0ustar dhellmanndhellmann00000000000000.. _tips-and-tricks: ================= Tips and Tricks ================= This is a list of user-contributed tips for making virtualenv and virtualenvwrapper even more useful. If you have tip to share, drop me an email or post a comment on `this blog post `__ and I'll add it here. zsh Prompt ========== From `Nat `_: Using zsh, I added some bits to ``$WORKON_HOME/post(de)activate`` to show the active virtualenv on the right side of my screen instead. in ``postactivate``:: PS1="$_OLD_VIRTUAL_PS1" _OLD_RPROMPT="$RPROMPT" RPROMPT="%{${fg_bold[white]}%}(env: %{${fg[green]}%}`basename \"$VIRTUAL_ENV\"`%{${fg_bold[white]}%})%{${reset_color}%} $RPROMPT" and in ``postdeactivate``:: RPROMPT="$_OLD_RPROMPT" Adjust colors according to your own personal tastes or environment. Updating cached ``$PATH`` entries ================================= From `Nat `_: I also added the command 'rehash' to ``$WORKON_HOME/postactivate`` and ``$WORKON_HOME/postdeactivate`` as I was having some problems with zsh not picking up the new paths immediately. Tying to pip's virtualenv support ================================= Via http://becomingguru.com/: Add this to your shell login script to make pip use the same directory for virtualenvs as virtualenvwrapper:: export PIP_VIRTUALENV_BASE=$WORKON_HOME and Via Nat: in addition to what becomingguru said, this line is key:: export PIP_RESPECT_VIRTUALENV=true That makes pip detect an active virtualenv and install to it, without having to pass it the -E parameter. Creating Project Work Directories ================================= Via `James `_: In the ``postmkvirtualenv`` script I have the following to create a directory based on the project name, add that directory to the python path and then cd into it:: proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}') mkdir $HOME/projects/$proj_name add2virtualenv $HOME/projects/$proj_name cd $HOME/projects/$proj_name In the ``postactivate`` script I have it set to automatically change to the project directory when I use the workon command:: proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}') cd ~/projects/$proj_name Automatically Run workon When Entering a Directory ================================================== `Justin Lily posted `__ about some code he added to his shell environment to look at the directory each time he runs ``cd``. If it finds a ``.venv`` file, it activates the environment named within. On leaving that directory, the current virtualenv is automatically deactivated. `Harry Marr `__ wrote a similar function that works with `git repositories `__. Installing Common Tools Automatically in New Environments ========================================================= Via `rizumu `__: I have this ``postmkvirtualenv`` to install the get a basic setup. :: $ cat postmkvirtualenv #!/usr/bin/env bash curl -O http://python-distribute.org/distribute_setup.p... />python distribute_setup.py rm distribute_setup.py easy_install pip==dev pip install Mercurial Then I have a pip requirement file with my dev tools. :: $ cat developer_requirements.txt ipdb ipython pastescript nose http://douglatornell.ca/software/python/Nosy-1.0.tar.gz coverage sphinx grin pyflakes pep8 Then each project has it's own pip requirement file for things like PIL, psycopg2, django-apps, numpy, etc. Changing the Default Behavior of ``cd`` ======================================= Via `mae `__: This is supposed to be executed after workon, that is as a ``postactivate`` hook. It basically overrides ``cd`` to know about the VENV so instead of doing ``cd`` to go to ``~`` you will go to the venv root, IMO very handy and I can't live without it anymore. if you pass it a proper path then it will do the right thing. :: cd () { if (( $# == 0 )) then builtin cd $VIRTUAL_ENV else builtin cd "$@" fi } cd virtualenvwrapper-4.1.1/docs/spelling_wordlist.txt0000644000101700007650000000011712143435521024500 0ustar dhellmanndhellmann00000000000000Hellmann Bicking virtualenvwrapper mkvirtualenv rmvirtualenv virtualenv stderr virtualenvwrapper-4.1.1/LICENSE0000644000101700007650000000167012146224442020256 0ustar dhellmanndhellmann00000000000000Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. virtualenvwrapper-4.1.1/Makefile0000644000101700007650000000164412143435521020711 0ustar dhellmanndhellmann00000000000000# Default target is to show help help: @echo "sdist - Source distribution" @echo "html - HTML documentation" @echo "docclean - Remove documentation build files" @echo "upload - upload a new release to PyPI" @echo "develop - install development version" @echo "test - run the test suite" @echo "test-quick - run the test suite for bash and one version of Python ($(PYTHON26))" .PHONY: sdist sdist: html rm -f dist/*.gz rm -rf docs/website python setup.py sdist cp -v dist/*.gz ~/Desktop # Documentation .PHONY: html html: (cd docs && $(MAKE) html) .PHONY: docclean docclean: rm -rf docs/build docs/html # Register the new version on pypi .PHONY: register register: echo "USE upload target" exit 1 python setup.py register .PHONY: upload upload: python setup.py sdist upload # Testing test: tox test-quick: tox -e py27 develop: python setup.py develop virtualenvwrapper-4.1.1/MANIFEST.in0000644000101700007650000000010012172575463021005 0ustar dhellmanndhellmann00000000000000recursive-include docs *.rst *.py *.html *.css *.js *.png *.txt virtualenvwrapper-4.1.1/PKG-INFO0000644000101700007650000001342512173006006020341 0ustar dhellmanndhellmann00000000000000Metadata-Version: 1.1 Name: virtualenvwrapper Version: 4.1.1 Summary: Enhancements to virtualenv Home-page: http://virtualenvwrapper.readthedocs.org/ Author: Doug Hellmann Author-email: doug.hellmann@gmail.com License: MIT Description: .. -*- mode: rst -*- ################# virtualenvwrapper ################# virtualenvwrapper is a set of extensions to Ian Bicking's `virtualenv `_ tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. **Warning:** The 4.x release includes some potentially incompatible changes for extensions from 3.x. The python modules for extensions are now *always* run with ``PWD=$WORKON_HOME`` (previously the value of PWD varied depending on the hook). The *shell* portion of any hook (anything sourced by the user's shell when the hook is run) is still run in the same place as before. ======== Features ======== 1. Organizes all of your virtual environments in one place. 2. Wrappers for creating, copying and deleting environments, including user-configurable hooks. 3. Use a single command to switch between environments. 4. Tab completion for commands that take a virtual environment as argument. 5. User-configurable hooks for all operations. 6. Plugin system for more creating sharable extensions. Rich Leland has created a short `screencast `__ showing off the features of virtualenvwrapper. ============ Installation ============ See the `project documentation `__ for installation and setup instructions. Supported Shells ================ virtualenvwrapper is a set of shell *functions* defined in Bourne shell compatible syntax. It is tested under ``bash``, ``ksh``, and ``zsh``. It may work with other shells, so if you find that it does work with a shell not listed here please let me know. If you can modify it to work with another shell, without completely rewriting it, send a pull request through the bitbucket project page. If you write a clone to work with an incompatible shell, let me know and I will link to it from this page. Python Versions =============== virtualenvwrapper is tested under Python 2.6 - 3.3. ======= Support ======= Join the `virtualenvwrapper Google Group `__ to discuss issues and features. Report bugs via the `bug tracker on BitBucket `__. Shell Aliases ============= Since virtualenvwrapper is largely a shell script, it uses shell commands for a lot of its actions. If your environment makes heavy use of shell aliases or other customizations, you may encounter issues. Before reporting bugs in the bug tracker, please test *without* your aliases enabled. If you can identify the alias causing the problem, that will help make virtualenvwrapper more robust. ========== Change Log ========== The `release history`_ is part of the project documentation. .. _release history: http://www.doughellmann.com/docs/virtualenvwrapper/history.html ======= License ======= Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Keywords: virtualenv Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Intended Audience :: Developers Classifier: Environment :: Console Provides: virtualenvwrapper Provides: virtualenvwrapper.user_scripts Provides: virtualenvwrapper.project virtualenvwrapper-4.1.1/README.es.rst0000644000101700007650000000575212143435521021352 0ustar dhellmanndhellmann00000000000000.. -*- mode: rst -*- ################# virtualenvwrapper ################# virtualenvwrapper es un conjunto de extensiones de la herramienta de Ian Bicking `virtualenv `_. Las extensiones incluyen funciones para la creación y eliminación de entornos virtuales y por otro lado administración de tu rutina de desarrollo, haciendo fácil trabajar en más de un proyecto al mismo tiempo sin introducir conflictos entre sus dependencias. =============== Características =============== 1. Organiza todos tus entornos virtuales en un sólo lugar. 2. Funciones para administrar tus entornos virtuales (crear, eliminar, copiar). 3. Usa un sólo comando para cambiar entre los entornos. 4. Completa con Tab los comandos que toman un entorno virtual como argumento. 5. Ganchos configurables para todas las operaciones. 6. Sistema de plugins para la creación de extensiones compartibles. Rich Leland ha grabado un pequeño `screencast `__ mostrando las características de virtualenvwrapper. =========== Instalación =========== Ve a la `documentación del proyecto `__ para las instrucciones de instalación y configuración. Actualizar desde 1.x ==================== El script de shell que contiene las funciones ha sido renombrado en la serie 2.x para reflejar el hecho de que otros shells, además de bash, son soportados. En tu archivo de inicio del shell, cambia ``source /usr/local/bin/virtualenvwrapper_bashrc`` por ``source /usr/local/bin/virtualenvwrapper.sh``. ============== Contribuciones ============== Antes de contribuir con nuevas características al *core* de virtualenvwrapper, por favor considera, en vez, si no debe ser implementada como una extensión. Ve a la `documentación para desarrolladores `__ por trucos sobre parches. ======== Licencia ======== Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .. _BitBucket: http://bitbucket.org/dhellmann/virtualenvwrapper/overview/ virtualenvwrapper-4.1.1/README.ja.rst0000644000101700007650000001202012143435521021317 0ustar dhellmanndhellmann00000000000000.. -*- mode: rst -*- ################# virtualenvwrapper ################# virtualenvwrapper は Ian Bicking の `virtualenv `_ ツールの 拡張機能です。この拡張機能は仮想環境の作成・削除を行ったり、 開発ワークフローを管理するラッパーを提供します。このラッパーを 使用することで、開発環境の依存による競合を発生させず、1つ以上の プロジェクトで同時に作業し易くなります。 ==== 機能 ==== 1. 1つの開発環境で全ての仮想環境を構成する 2. 仮想環境を管理(作成、削除、コピー)するラッパー 3. たった1つのコマンドで仮想環境を切り替える 4. コマンドの引数として仮想環境がタブ補完できる 5. 全ての操作に対してユーザ設定でフックできる(:ref:`scripts` を参照) 6. さらに共有可能な拡張機能を作成できるプラグインシステム(:ref:`plugins` を参照) Rich Leland は virtualenvwrapper の機能を誇示するために短い `スクリーンキャスト `__ を作成しました。 ============ インストール ============ インストールとインフラを設定するには `プロジェクトのドキュメント `__ を参照してください。 サポートシェル ============== virtualenvwrapper は Bourne シェル互換の構文で定義された シェル *関数* のセットです。それは `bash`, `ksh` と `zsh` で テストされています。その他のシェルでも動作するかもしれませんが、 ここに記載されていないシェルで動作することを発見したら私に 教えてください。もしあなたがその他のシェルで動作させるために virtualenvwrapper を完全に書き直すことなく修正できるなら、 bitbucket のプロジェクトページを通じて pull リクエストを 送ってください。あなたが非互換なシェル上で動作させるクローンを 作成するなら、このページでリンクを張るので私に連絡してください。 Python バージョン ================= virtualenvwrapper は Python 2.4 - 2.7 でテストされています。 1.x からのアップグレード ======================== ラッパー関数を含むシェルスクリプトは 2.x バージョンで bash 以外のシェルをサポートするためにその名前が変更されました。 あなたの起動ファイルの ``source /usr/local/bin/virtualenvwrapper_bashrc`` を ``source /usr/local/bin/virtualenvwrapper.sh`` へ変更してください。 ==== 貢献 ==== virtualenvwrapper のコアへ新しい機能を追加する前に、 その代わりに機能拡張として実装すべきかどうかをよく考えてください。 パッチを提供するための tips は `開発者ドキュメント `__ を参照してください。 ======== サポート ======== 問題や機能を議論するには `virtualenvwrapper Google Group `__ に参加してください。 `BitBucket のバグトラッカー `__ でバグを報告してください。 シェルエイリアス ================ virtualenvwrapper は大きなシェルスクリプトなので、 多くのアクションはシェルコマンドを使用します。 あなたの環境が多くのシェルエイリアスやその他の カスタマイズを行っているなら、何かしら問題に 遭遇する可能性があります。バグトラッカーにバグを 報告する前に、そういったエイリアスを無効な *状態* で テストしてください。あなたがその問題を引き起こす エイリアスを判別できるなら virtualenvwrapper を もっと堅牢なものにすることに役立つでしょう。 ========== ライセンス ========== Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. virtualenvwrapper-4.1.1/README.txt0000644000101700007650000000773212143435521020753 0ustar dhellmanndhellmann00000000000000.. -*- mode: rst -*- ################# virtualenvwrapper ################# virtualenvwrapper is a set of extensions to Ian Bicking's `virtualenv `_ tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. **Warning:** The 4.x release includes some potentially incompatible changes for extensions from 3.x. The python modules for extensions are now *always* run with ``PWD=$WORKON_HOME`` (previously the value of PWD varied depending on the hook). The *shell* portion of any hook (anything sourced by the user's shell when the hook is run) is still run in the same place as before. ======== Features ======== 1. Organizes all of your virtual environments in one place. 2. Wrappers for creating, copying and deleting environments, including user-configurable hooks. 3. Use a single command to switch between environments. 4. Tab completion for commands that take a virtual environment as argument. 5. User-configurable hooks for all operations. 6. Plugin system for more creating sharable extensions. Rich Leland has created a short `screencast `__ showing off the features of virtualenvwrapper. ============ Installation ============ See the `project documentation `__ for installation and setup instructions. Supported Shells ================ virtualenvwrapper is a set of shell *functions* defined in Bourne shell compatible syntax. It is tested under ``bash``, ``ksh``, and ``zsh``. It may work with other shells, so if you find that it does work with a shell not listed here please let me know. If you can modify it to work with another shell, without completely rewriting it, send a pull request through the bitbucket project page. If you write a clone to work with an incompatible shell, let me know and I will link to it from this page. Python Versions =============== virtualenvwrapper is tested under Python 2.6 - 3.3. ======= Support ======= Join the `virtualenvwrapper Google Group `__ to discuss issues and features. Report bugs via the `bug tracker on BitBucket `__. Shell Aliases ============= Since virtualenvwrapper is largely a shell script, it uses shell commands for a lot of its actions. If your environment makes heavy use of shell aliases or other customizations, you may encounter issues. Before reporting bugs in the bug tracker, please test *without* your aliases enabled. If you can identify the alias causing the problem, that will help make virtualenvwrapper more robust. ========== Change Log ========== The `release history`_ is part of the project documentation. .. _release history: http://www.doughellmann.com/docs/virtualenvwrapper/history.html ======= License ======= Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. virtualenvwrapper-4.1.1/requirements.txt0000644000101700007650000000004612172573106022534 0ustar dhellmanndhellmann00000000000000virtualenv virtualenv-clone stevedore virtualenvwrapper-4.1.1/setup.cfg0000644000101700007650000000527412173006006021070 0ustar dhellmanndhellmann00000000000000[metadata] name = virtualenvwrapper author = Doug Hellmann author-email = doug.hellmann@gmail.com summary = Enhancements to virtualenv description-file = README.txt license = MIT classifier = Development Status :: 5 - Production/Stable License :: OSI Approved :: MIT License Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.6 Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.2 Programming Language :: Python :: 3.3 Intended Audience :: Developers Environment :: Console keywords = virtualenv home-page = http://virtualenvwrapper.readthedocs.org/ zip_safe = False provides_dist = virtualenvwrapper virtualenvwrapper.user_scripts virtualenvwrapper.project [files] packages = virtualenvwrapper namespace_packages = virtualenvwrapper scripts = virtualenvwrapper.sh virtualenvwrapper_lazy.sh [global] zip_safe = False setup-hooks = pbr.hooks.setup_hook [entry_points] virtualenvwrapper.initialize = user_scripts = virtualenvwrapper.user_scripts:initialize project = virtualenvwrapper.project:initialize virtualenvwrapper.initialize_source = user_scripts = virtualenvwrapper.user_scripts:initialize_source virtualenvwrapper.pre_mkvirtualenv = user_scripts = virtualenvwrapper.user_scripts:pre_mkvirtualenv virtualenvwrapper.post_mkvirtualenv_source = user_scripts = virtualenvwrapper.user_scripts:post_mkvirtualenv_source virtualenvwrapper.pre_cpvirtualenv = user_scripts = virtualenvwrapper.user_scripts:pre_cpvirtualenv virtualenvwrapper.post_cpvirtualenv_source = user_scripts = virtualenvwrapper.user_scripts:post_cpvirtualenv_source virtualenvwrapper.pre_rmvirtualenv = user_scripts = virtualenvwrapper.user_scripts:pre_rmvirtualenv virtualenvwrapper.post_rmvirtualenv = user_scripts = virtualenvwrapper.user_scripts:post_rmvirtualenv virtualenvwrapper.project.pre_mkproject = project = virtualenvwrapper.project:pre_mkproject virtualenvwrapper.project.post_mkproject_source = project = virtualenvwrapper.project:post_mkproject_source virtualenvwrapper.pre_activate = user_scripts = virtualenvwrapper.user_scripts:pre_activate virtualenvwrapper.post_activate_source = user_scripts = virtualenvwrapper.user_scripts:post_activate_source project = virtualenvwrapper.project:post_activate_source virtualenvwrapper.pre_deactivate_source = user_scripts = virtualenvwrapper.user_scripts:pre_deactivate_source virtualenvwrapper.post_deactivate_source = user_scripts = virtualenvwrapper.user_scripts:post_deactivate_source virtualenvwrapper.get_env_details = user_scripts = virtualenvwrapper.user_scripts:get_env_details [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 virtualenvwrapper-4.1.1/setup.py0000644000101700007650000000016012173005415020751 0ustar dhellmanndhellmann00000000000000#!/usr/bin/env python from setuptools import setup setup( setup_requires=['pbr>=0.5.19'], pbr=True, ) virtualenvwrapper-4.1.1/tests/0000755000101700007650000000000012173006006020401 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/tests/manual_test_install.sh0000755000101700007650000000141612143435521025011 0ustar dhellmanndhellmann00000000000000#!/bin/sh # # Test installation of virtualenvwrapper in a new virtualenv. # test_dir=$(dirname $0) source "$test_dir/../virtualenvwrapper.sh" export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME" VERSION=$(python setup.py --version) oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_build_ok () { (cd "$test_dir/.." && make sdist) outcome=$? assertSame "0" "$outcome" } test_install () { dist_dir=$(dirname $test_dir)/dist pip install "$dist_dir/virtualenvwrapper-$VERSION.tar.gz" RC=$? assertTrue "Error code $RC" "[ $RC -eq 0 ]" assertTrue "Missing wrapper script" "[ -f $WORKON_HOME/installtest/bin/virtualenvwrapper.sh ]" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/run_tests0000755000101700007650000000375012172523735022376 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- #set -x envdir="$1" shift scripts="$*" if [ -z "$scripts" ] then scripts=$(ls tests/test*.sh) if [ -z "$scripts" ] then echo "Could not find any test scripts to run" 1>&2 exit 1 fi fi # Force the tox virtualenv to be active. # # Since this script runs from within a separate shell created by tox, # the name of the virtualenv (in $VIRTUAL_ENV) is inherited, but the # shell functions and other settings created by the activate script # are *not* inherited. # source "$envdir/bin/activate" TMPDIR="$envdir/tmp" export TMPDIR mkdir -p "$TMPDIR" # Set up virtualenvwrapper.hook_loader to print more details than usual for debugging. #export HOOK_VERBOSE_OPTION=-vvv HOOK_VERBOSE_OPTION="-q" export HOOK_VERBOSE_OPTION # Force virtualenvwrapper to use the python interpreter in the # tox-created virtualenv. VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python" export VIRTUALENVWRAPPER_PYTHON # Clear any user settings for the hook directory or log directory unset VIRTUALENVWRAPPER_HOOK_DIR unset VIRTUALENVWRAPPER_LOG_DIR unset VIRTUALENVWRAPPER_VIRTUALENV unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS # Run the test scripts with a little formatting around them to make it # easier to find where each script output starts. for test_script in $scripts do echo echo '********************************************************************************' echo "Running $test_script" echo " VIRTUAL_ENV=$VIRTUAL_ENV" echo " VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON" echo " $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)" echo " PYTHONPATH=$PYTHONPATH" echo " SHELL=$SHELL" echo " BASH_VERSION=$BASH_VERSION" echo " ZSH_VERSION=$ZSH_VERSION" echo " KSH_VERSION=$KSH_VERSION" echo " virtualenv=$(which virtualenv)" echo " ZSH=$ZSH_NAME $ZSH_EVAL_CONTEXT" echo " TMPDIR=$TMPDIR" echo SHUNIT_PARENT="$test_script" export SHUNIT_PARENT $test_shell_opts $test_script || exit 1 echo done exit 0 virtualenvwrapper-4.1.1/tests/setup.sh0000755000101700007650000000055712172536365022126 0ustar dhellmanndhellmann00000000000000# Setup globals used by the tests #set -x # tmplocation=${TMPDIR:-/tmp} # export WORKON_HOME="$(echo ${tmplocation}/WORKON_HOME.$$ | sed 's|//|/|g')" # export PROJECT_HOME="$(echo ${tmplocation}/PROJECT_HOME.$$ | sed 's|//|/|g')" export WORKON_HOME=$(mktemp -d -t "WORKON_HOME.$$") export PROJECT_HOME=$(mktemp -d -t "PROJECT_HOME.$$") #unset HOOK_VERBOSE_OPTION virtualenvwrapper-4.1.1/tests/shunit20000644000101700007650000007472712143435521021746 0ustar dhellmanndhellmann00000000000000# $Id: shunit2 277 2008-10-29 21:20:22Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 # vim:foldmethod=marker:foldmarker=/**,*/ # #/** # # # # shUnit 2.1.5 # Shell Unit Test Framework # # http://shunit2.googlecode.com/ # # written by Kate Ward <kate.ward@forestent.com> # released under the LGPL # # This module implements a xUnit based unit test framework similar to JUnit. # #*/ SHUNIT_VERSION='2.1.5' SHUNIT_TRUE=0 SHUNIT_FALSE=1 SHUNIT_ERROR=2 _shunit_warn() { echo "shunit2:WARN $@" >&2; } _shunit_error() { echo "shunit2:ERROR $@" >&2; } _shunit_fatal() { echo "shunit2:FATAL $@" >&2; } # specific shell checks if [ -n "${ZSH_VERSION:-}" ]; then setopt |grep "^shwordsplit$" >/dev/null if [ $? -ne ${SHUNIT_TRUE} ]; then _shunit_fatal 'zsh shwordsplit option is required for proper operation' exit ${SHUNIT_ERROR} fi if [ -z "${SHUNIT_PARENT:-}" ]; then _shunit_fatal "zsh does not pass \$0 through properly. please declare \ \"SHUNIT_PARENT=\$0\" before calling shUnit2" exit ${SHUNIT_ERROR} fi fi # # constants # __SHUNIT_ASSERT_MSG_PREFIX='ASSERT:' __SHUNIT_PARENT=${SHUNIT_PARENT:-$0} # set the constants readonly shunit_constants_=`set |grep '^__SHUNIT_' |cut -d= -f1` echo "${shunit_constants_}" |grep '^Binary file' >/dev/null \ && shunit_constants_=`set |grep -a '^__SHUNIT_' |cut -d= -f1` for shunit_constant_ in ${shunit_constants_}; do shunit_ro_opts_='' case ${ZSH_VERSION:-} in '') ;; # this isn't zsh [123].*) ;; # early versions (1.x, 2.x, 3.x) *) shunit_ro_opts_='-g' ;; # all later versions. declare readonly globally esac readonly ${shunit_ro_opts_} ${shunit_constant_} done unset shunit_constant_ shunit_constants_ shunit_ro_opts_ # variables __shunit_skip=${SHUNIT_FALSE} __shunit_suite='' # counts of tests __shunit_testSuccess=${SHUNIT_TRUE} __shunit_testsTotal=0 __shunit_testsPassed=0 __shunit_testsFailed=0 # counts of asserts __shunit_assertsTotal=0 __shunit_assertsPassed=0 __shunit_assertsFailed=0 __shunit_assertsSkipped=0 __shunit_lineno='' __shunit_reportGenerated=${SHUNIT_FALSE} # macros _SHUNIT_LINENO_='eval __shunit_lineno=""; if [ "${1:-}" = "--lineno" ]; then [ -n "$2" ] && __shunit_lineno="[$2] "; shift 2; fi' #----------------------------------------------------------------------------- # assert functions # #/** # # # void # # # # # assertEquals # string [message] # string expected # string actual # # # Asserts that expected and # actual are equal to one another. The message is # optional. # # #*/ assertEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertEquals() requires two or three arguments; $# given" _shunit_error "1: ${1:+$1} 2: ${2:+$2} 3: ${3:+$3}" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_expected_=$1 shunit_actual_=$2 shunit_return=${SHUNIT_TRUE} if [ "${shunit_expected_}" = "${shunit_actual_}" ]; then _shunit_assertPass else failNotEquals "${shunit_message_}" "${shunit_expected_}" "${shunit_actual_}" shunit_return=${SHUNIT_FALSE} fi unset shunit_message_ shunit_expected_ shunit_actual_ return ${shunit_return} } _ASSERT_EQUALS_='eval assertEquals --lineno "${LINENO:-}"' #/** # # # void # # # # # assertNotEquals # string [message] # string unexpected # string actual # # # Asserts that unexpected and # actual are not # equal to one another. The message is optional. # # #*/ assertNotEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertNotEquals() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_unexpected_=$1 shunit_actual_=$2 shunit_return=${SHUNIT_TRUE} if [ "${shunit_unexpected_}" != "${shunit_actual_}" ]; then _shunit_assertPass else failSame "${shunit_message_}" "$@" shunit_return=${SHUNIT_FALSE} fi unset shunit_message_ shunit_unexpected_ shunit_actual_ return ${shunit_return} } _ASSERT_NOT_EQUALS_='eval assertNotEquals --lineno "${LINENO:-}"' #/** # # # void # # # # # assertNull # string [message] # string value # # # Asserts that value is null, # or in shell terms a zero-length string. The message is optional. # # #*/ assertNull() { ${_SHUNIT_LINENO_} if [ $# -lt 1 -o $# -gt 2 ]; then _shunit_error "assertNull() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi assertTrue "${shunit_message_}" "[ -z '$1' ]" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_NULL_='eval assertNull --lineno "${LINENO:-}"' #/** # # # void # # # # # assertNotNull # string [message] # string value # # # Asserts that value is not null, or in shell terms not # a zero-length string. The message is optional. # # #*/ assertNotNull() { ${_SHUNIT_LINENO_} if [ $# -gt 2 ]; then # allowing 0 arguments as $1 might actually be null _shunit_error "assertNotNull() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi assertTrue "${shunit_message_}" "[ -n '${1:-}' ]" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_NOT_NULL_='eval assertNotNull --lineno "${LINENO:-}"' #/** # # # void # # # # # assertSame # string [message] # string expected # string actual # # # This function is functionally equivalent to # assertEquals. # # #*/ assertSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertSame() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi assertEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_SAME_='eval assertSame --lineno "${LINENO:-}"' #/** # # # void # # # # # assertNotSame # string [message] # string unexpected # string actual # # # Asserts that unexpected and # actual are not # equal to one another. The message is optional. # # #*/ assertNotSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "assertNotSame() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_:-}$1" shift fi assertNotEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _ASSERT_NOT_SAME_='eval assertNotSame --lineno "${LINENO:-}"' #/** # # # void # # # # # assertTrue # string [message] # string condition # # # Asserts that a given shell test condition is true. The message is # optional. # Testing whether something is true or false is easy enough by using # the assertEquals/assertNotSame functions. Shell supports much more # complicated tests though, and a means to support them was needed. As such, # this function tests that conditions are true or false through evaluation # rather than just looking for a true or false. # # The following test will succeed: assertTrue "[ 34 -gt 23 ]" # The folloing test will fail with a message: assertTrue "test failed" "[ -r '/non/existant/file' ]" # # # #*/ assertTrue() { ${_SHUNIT_LINENO_} if [ $# -gt 2 ]; then _shunit_error "assertTrue() takes one two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_condition_=$1 # see if condition is an integer, i.e. a return value shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'` shunit_return=${SHUNIT_TRUE} if [ -z "${shunit_condition_}" ]; then # null condition shunit_return=${SHUNIT_FALSE} elif [ "${shunit_condition_}" = "${shunit_match_}" ]; then # possible return value. treating 0 as true, and non-zero as false. [ ${shunit_condition_} -ne 0 ] && shunit_return=${SHUNIT_FALSE} else # (hopefully) a condition ( eval ${shunit_condition_} ) >/dev/null 2>&1 [ $? -ne 0 ] && shunit_return=${SHUNIT_FALSE} fi # record the test if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then _shunit_assertPass else _shunit_assertFail "${shunit_message_}" fi unset shunit_message_ shunit_condition_ shunit_match_ return ${shunit_return} } _ASSERT_TRUE_='eval assertTrue --lineno "${LINENO:-}"' #/** # # # void # # # # # assertFalse # string [message] # string condition # # # Asserts that a given shell test condition is false. The message is # optional. # Testing whether something is true or false is easy enough by using # the assertEquals/assertNotSame functions. Shell supports much more # complicated tests though, and a means to support them was needed. As such, # this function tests that conditions are true or false through evaluation # rather than just looking for a true or false. # # The following test will succeed: assertFalse "[ 'apples' = 'oranges' ]" # The folloing test will fail with a message: assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]" # # # #*/ assertFalse() { ${_SHUNIT_LINENO_} if [ $# -lt 1 -o $# -gt 2 ]; then _shunit_error "assertFalse() quires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 2 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_condition_=$1 # see if condition is an integer, i.e. a return value shunit_match_=`expr "${shunit_condition_}" : '\([0-9]*\)'` shunit_return=${SHUNIT_TRUE} if [ -z "${shunit_condition_}" ]; then # null condition shunit_return=${SHUNIT_FALSE} elif [ "${shunit_condition_}" = "${shunit_match_}" ]; then # possible return value. treating 0 as true, and non-zero as false. [ ${shunit_condition_} -eq 0 ] && shunit_return=${SHUNIT_FALSE} else # (hopefully) a condition ( eval ${shunit_condition_} ) >/dev/null 2>&1 [ $? -eq 0 ] && shunit_return=${SHUNIT_FALSE} fi # record the test if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then _shunit_assertPass else _shunit_assertFail "${shunit_message_}" fi unset shunit_message_ shunit_condition_ shunit_match_ return ${shunit_return} } _ASSERT_FALSE_='eval assertFalse --lineno "${LINENO:-}"' #----------------------------------------------------------------------------- # failure functions # #/** # # # void # # # # # fail # string [message] # # # Fails the test immediately, with the optional message. # # #*/ fail() { ${_SHUNIT_LINENO_} if [ $# -gt 1 ]; then _shunit_error "fail() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 1 ]; then shunit_message_="${shunit_message_}$1" shift fi _shunit_assertFail "${shunit_message_}" unset shunit_message_ return ${SHUNIT_FALSE} } _FAIL_='eval fail --lineno "${LINENO:-}"' #/** # # # void # # # # # failNotEquals # string [message] # string unexpected # string actual # # # Fails the test if unexpected and # actual are not # equal to one another. The message is optional. # # #*/ failNotEquals() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failNotEquals() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi shunit_unexpected_=$1 shunit_actual_=$2 _shunit_assertFail "${shunit_message_:+${shunit_message_} }expected:<${shunit_unexpected_}> but was:<${shunit_actual_}>" unset shunit_message_ shunit_unexpected_ shunit_actual_ return ${SHUNIT_FALSE} } _FAIL_NOT_EQUALS_='eval failNotEquals --lineno "${LINENO:-}"' #/** # # # void # # # # # failSame # string [message] # # # Indicate test failure because arguments were the same. The message is # optional. # # #*/ failSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failSame() requires two or three arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi _shunit_assertFail "${shunit_message_:+${shunit_message_} }expected not same" unset shunit_message_ return ${SHUNIT_FALSE} } _FAIL_SAME_='eval failSame --lineno "${LINENO:-}"' #/** # # # void # # # # # failNotSame # string [message] # string expected # string actual # # # Indicate test failure because arguments were not the same. The # message is optional. # # #*/ failNotSame() { ${_SHUNIT_LINENO_} if [ $# -lt 2 -o $# -gt 3 ]; then _shunit_error "failNotEquals() requires one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} shunit_message_=${__shunit_lineno} if [ $# -eq 3 ]; then shunit_message_="${shunit_message_}$1" shift fi failNotEquals "${shunit_message_}" "$1" "$2" shunit_return=$? unset shunit_message_ return ${shunit_return} } _FAIL_NOT_SAME_='eval failNotSame --lineno "${LINENO:-}"' #----------------------------------------------------------------------------- # skipping functions # #/** # # # void # # # # # startSkipping # # # # This function forces the remaining assert and fail functions to be # "skipped", i.e. they will have no effect. Each function skipped will be # recorded so that the total of asserts and fails will not be altered. # # #*/ startSkipping() { __shunit_skip=${SHUNIT_TRUE} } #/** # # # void # # # # # endSkipping # # # # This function returns calls to the assert and fail functions to their # default behavior, i.e. they will be called. # # #*/ endSkipping() { __shunit_skip=${SHUNIT_FALSE} } #/** # # # boolean # # # # # isSkipping # # # # This function returns the state of skipping. # # #*/ isSkipping() { return ${__shunit_skip} } #----------------------------------------------------------------------------- # suite functions # #/** # # # void # # # # # suite # # # # This function can be optionally overridden by the user in their test # suite. # If this function exists, it will be called when # shunit2 is sourced. If it does not exist, shUnit2 will # search the parent script for all functions beginning with the word # test, and they will be added dynamically to the test # suite. # # #*/ # Note: see _shunit_mktempFunc() for actual implementation # suite() { :; } #/** # # # void # # # # # suite_addTest # string function # # # This function adds a function name to the list of tests scheduled for # execution as part of this test suite. This function should only be called # from within the suite() function. # # #*/ suite_addTest() { shunit_func_=${1:-} __shunit_suite="${__shunit_suite:+${__shunit_suite} }${shunit_func_}" __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1` unset shunit_func_ } #/** # # # void # # # # # oneTimeSetUp # # # # This function can be be optionally overridden by the user in their # test suite. # If this function exists, it will be called once before any tests are # run. It is useful to prepare a common environment for all tests. # # #*/ # Note: see _shunit_mktempFunc() for actual implementation # oneTimeSetUp() { :; } #/** # # # void # # # # # oneTimeTearDown # # # # This function can be be optionally overridden by the user in their # test suite. # If this function exists, it will be called once after all tests are # completed. It is useful to clean up the environment after all tests. # # #*/ # Note: see _shunit_mktempFunc() for actual implementation # oneTimeTearDown() { :; } #/** # # # void # # # # # setUp # # # # This function can be be optionally overridden by the user in their # test suite. # If this function exists, it will be called before each test is run. # It is useful to reset the environment before each test. # # #*/ # Note: see _shunit_mktempFunc() for actual implementation # setUp() { :; } #/** # # # void # # # # # tearDown # # # # This function can be be optionally overridden by the user in their # test suite. # If this function exists, it will be called after each test completes. # It is useful to clean up the environment after each test. # # #*/ # Note: see _shunit_mktempFunc() for actual implementation # tearDown() { :; } #------------------------------------------------------------------------------ # internal shUnit2 functions # # this function is a cross-platform temporary directory creation tool. not all # OSes have the mktemp function, so one is included here. _shunit_mktempDir() { # try the standard mktemp function ( exec mktemp -dqt shunit.XXXXXX 2>/dev/null ) && return # the standard mktemp didn't work. doing our own. if [ -r '/dev/urandom' ]; then _shunit_random_=`od -vAn -N4 -tx4 "${_shunit_file_}" #! /bin/sh exit ${SHUNIT_TRUE} EOF chmod +x "${_shunit_file_}" done unset _shunit_file_ } _shunit_cleanup() { _shunit_name_=$1 case ${_shunit_name_} in EXIT) _shunit_signal_=0 ;; INT) _shunit_signal_=2 ;; TERM) _shunit_signal_=15 ;; *) _shunit_warn "unrecognized trap value (${_shunit_name_})" _shunit_signal_=0 ;; esac # do our work rm -fr "${__shunit_tmpDir}" # exit for all non-EXIT signals if [ ${_shunit_name_} != 'EXIT' ]; then _shunit_warn "trapped and now handling the (${_shunit_name_}) signal" # disable EXIT trap trap 0 # add 128 to signal and exit exit `expr ${_shunit_signal_} + 128` elif [ ${__shunit_reportGenerated} -eq ${SHUNIT_FALSE} ] ; then _shunit_assertFail 'Unknown failure encountered running a test' _shunit_generateReport exit ${SHUNIT_ERROR} fi unset _shunit_name_ _shunit_signal_ } # The actual running of the tests happens here. _shunit_execSuite() { for _shunit_test_ in ${__shunit_suite}; do __shunit_testSuccess=${SHUNIT_TRUE} # disable skipping endSkipping # execute the per-test setup function setUp # execute the test echo "${_shunit_test_}" eval ${_shunit_test_} # execute the per-test tear-down function tearDown # update stats if [ ${__shunit_testSuccess} -eq ${SHUNIT_TRUE} ]; then __shunit_testsPassed=`expr ${__shunit_testsPassed} + 1` else __shunit_testsFailed=`expr ${__shunit_testsFailed} + 1` fi done unset _shunit_test_ } # This function exits shUnit2 with the appropriate error code and OK/FAILED # message. _shunit_generateReport() { _shunit_ok_=${SHUNIT_TRUE} # if no exit code was provided one, determine an appropriate one [ ${__shunit_testsFailed} -gt 0 \ -o ${__shunit_testSuccess} -eq ${SHUNIT_FALSE} ] \ && _shunit_ok_=${SHUNIT_FALSE} echo if [ ${__shunit_testsTotal} -eq 1 ]; then echo "Ran ${__shunit_testsTotal} test." else echo "Ran ${__shunit_testsTotal} tests." fi _shunit_failures_='' _shunit_skipped_='' [ ${__shunit_assertsFailed} -gt 0 ] \ && _shunit_failures_="failures=${__shunit_assertsFailed}" [ ${__shunit_assertsSkipped} -gt 0 ] \ && _shunit_skipped_="skipped=${__shunit_assertsSkipped}" if [ ${_shunit_ok_} -eq ${SHUNIT_TRUE} ]; then _shunit_msg_='OK' [ -n "${_shunit_skipped_}" ] \ && _shunit_msg_="${_shunit_msg_} (${_shunit_skipped_})" else _shunit_msg_="FAILED (${_shunit_failures_}" [ -n "${_shunit_skipped_}" ] \ && _shunit_msg_="${_shunit_msg_},${_shunit_skipped_}" _shunit_msg_="${_shunit_msg_})" fi echo echo ${_shunit_msg_} __shunit_reportGenerated=${SHUNIT_TRUE} unset _shunit_failures_ _shunit_msg_ _shunit_ok_ _shunit_skipped_ } _shunit_shouldSkip() { [ ${__shunit_skip} -eq ${SHUNIT_FALSE} ] && return ${SHUNIT_FALSE} _shunit_assertSkip } _shunit_assertPass() { __shunit_assertsPassed=`expr ${__shunit_assertsPassed} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` } _shunit_assertFail() { _shunit_msg_=$1 __shunit_testSuccess=${SHUNIT_FALSE} __shunit_assertsFailed=`expr ${__shunit_assertsFailed} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` echo "${__SHUNIT_ASSERT_MSG_PREFIX}${_shunit_msg_}" unset _shunit_msg_ } _shunit_assertSkip() { __shunit_assertsSkipped=`expr ${__shunit_assertsSkipped} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` } #------------------------------------------------------------------------------ # main # # create a temporary storage location __shunit_tmpDir=`_shunit_mktempDir` # provide a public temporary directory for unit test scripts # TODO(kward): document this shunit_tmpDir="${__shunit_tmpDir}/tmp" mkdir "${shunit_tmpDir}" # setup traps to clean up after ourselves trap '_shunit_cleanup EXIT' 0 trap '_shunit_cleanup INT' 2 trap '_shunit_cleanup TERM' 15 # create phantom functions to work around issues with Cygwin _shunit_mktempFunc PATH="${__shunit_tmpDir}:${PATH}" # execute the oneTimeSetUp function (if it exists) oneTimeSetUp # execute the suite function defined in the parent test script # deprecated as of 2.1.0 suite # if no suite function was defined, dynamically build a list of functions if [ -z "${__shunit_suite}" ]; then shunit_funcs_=`grep "^[ \t]*test[A-Za-z0-9_]* *()" ${__SHUNIT_PARENT} \ |sed 's/[^A-Za-z0-9_]//g'` for shunit_func_ in ${shunit_funcs_}; do suite_addTest ${shunit_func_} done fi unset shunit_func_ shunit_funcs_ # execute the tests _shunit_execSuite # execute the oneTimeTearDown function (if it exists) oneTimeTearDown # generate the report _shunit_generateReport # that's it folks [ ${__shunit_testsFailed} -eq 0 ] exit $? #/** # #*/ virtualenvwrapper-4.1.1/tests/test.sh0000755000101700007650000001025112172545201021722 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo unset VIRTUALENVWRAPPER_INITIALIZED rm -f "$TMPDIR/catch_output" } test_virtualenvwrapper_initialize() { assertTrue "Initialized" virtualenvwrapper_initialize for hook in premkvirtualenv postmkvirtualenv prermvirtualenv postrmvirtualenv preactivate postactivate predeactivate postdeactivate do assertTrue "Global $WORKON_HOME/$hook was not created" "[ -f $WORKON_HOME/$hook ]" assertTrue "Global $WORKON_HOME/$hook is not executable" "[ -x $WORKON_HOME/$hook ]" done echo "echo GLOBAL initialize >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize" virtualenvwrapper_initialize output=$(cat "$TMPDIR/catch_output") expected="GLOBAL initialize" assertSame "$expected" "$output" } test_virtualenvwrapper_space_in_workon_home() { before="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/this has spaces" expected="$WORKON_HOME" mkdir -p "$expected" virtualenvwrapper_initialize RC=$? assertSame "$expected" "$WORKON_HOME" assertSame "0" "$RC" export WORKON_HOME="$before" } test_virtualenvwrapper_verify_workon_home() { assertTrue "WORKON_HOME not verified" virtualenvwrapper_verify_workon_home } test_virtualenvwrapper_verify_workon_home_missing_dir() { old_home="$WORKON_HOME" WORKON_HOME="$WORKON_HOME/not_there" assertTrue "Directory already exists" "[ ! -d \"$WORKON_HOME\" ]" virtualenvwrapper_verify_workon_home >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertSame "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." "$output" WORKON_HOME="$old_home" } test_virtualenvwrapper_verify_workon_home_missing_dir_quiet() { old_home="$WORKON_HOME" WORKON_HOME="$WORKON_HOME/not_there_quiet" assertTrue "Directory already exists" "[ ! -d \"$WORKON_HOME\" ]" output=$(virtualenvwrapper_verify_workon_home -q 2>&1) assertSame "" "$output" WORKON_HOME="$old_home" } test_virtualenvwrapper_verify_workon_home_missing_dir_grep_options() { old_home="$WORKON_HOME" WORKON_HOME="$WORKON_HOME/not_there" # This should prevent the message from being found if it isn't # unset correctly. export GREP_OPTIONS="--count" assertTrue "WORKON_HOME not verified" virtualenvwrapper_verify_workon_home WORKON_HOME="$old_home" unset GREP_OPTIONS } test_python_interpreter_set_incorrectly() { return_to="$(pwd)" cd "$WORKON_HOME" mkvirtualenv no_wrappers >/dev/null 2>&1 RC=$? assertEquals "mkvirtualenv return code wrong" "0" "$RC" expected="No module named virtualenvwrapper" # test_shell is set by tests/run_tests if [ "$test_shell" = "" ] then export test_shell=$SHELL fi outfilename="$WORKON_HOME/test_out.$$" subshell_output=$(VIRTUALENVWRAPPER_PYTHON="$WORKON_HOME/no_wrappers/bin/python" $test_shell $return_to/virtualenvwrapper.sh >"$outfilename" 2>&1) #echo "$subshell_output" cat "$outfilename" | sed "s/'//g" | grep -q "$expected" 2>&1 found_it=$? #echo "$found_it" assertTrue "Expected \'$expected\', got: \'$(cat "$outfilename")\'" "[ $found_it -eq 0 ]" assertFalse "Failed to detect invalid Python location" "VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python virtualenvwrapper_run_hook initialize >/dev/null 2>&1" cd "$return_to" deactivate } test_virtualenvwrapper_verify_virtualenv(){ assertTrue "Verified unable to verify virtualenv" virtualenvwrapper_verify_virtualenv VIRTUALENVWRAPPER_VIRTUALENV="thiscannotpossiblyexist123" assertFalse "Incorrectly verified virtualenv" virtualenvwrapper_verify_virtualenv } test_virtualenvwrapper_verify_virtualenv_clone(){ assertTrue "Verified unable to verify virtualenv_clone" virtualenvwrapper_verify_virtualenv_clone VIRTUALENVWRAPPER_VIRTUALENV_CLONE="thiscannotpossiblyexist123" assertFalse "Incorrectly verified virtualenv_clone" virtualenvwrapper_verify_virtualenv_clone } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_add2virtualenv.sh0000755000101700007650000001171712172543422024747 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" >/dev/null 2>&1 } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_add2virtualenv () { mkvirtualenv "pathtest" >/dev/null 2>&1 full_path=$(pwd) add2virtualenv "$full_path" cdsitepackages # Check contents of path file path_file="./_virtualenv_path_extensions.pth" assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file" assertTrue "No path insert code in $(cat $path_file)" "grep -q sys.__egginsert $path_file" # Check the path we inserted is actually at the top expected="$full_path" actual=$($WORKON_HOME/pathtest/bin/python -c "import sys; sys.stdout.write(sys.path[1]+'\n')") assertSame "$expected" "$actual" # Make sure the temporary file created # during the edit was removed assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]" cd - >/dev/null 2>&1 } test_add2virtualenv_zsh_noclobber () { # See issue #137 if [ ! -z $ZSH_VERSION ] then set -o noclobber elif [[ "$SHELL" =~ "bash" ]] then shopt -o -s noclobber else return 0 fi mkvirtualenv "pathtest_noclobber" >/dev/null 2>&1 full_path=$(pwd) add2virtualenv "$full_path" RC=$? if [ ! -z $ZSH_VERSION ] then unsetopt noclobber elif [[ "/$SHELL" =~ "/bash" ]] then shopt -o -u noclobber fi assertEquals "0" "$RC" cdsitepackages # Check contents of path file path_file="./_virtualenv_path_extensions.pth" assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file" assertTrue "No path insert code in $(cat $path_file)" "grep -q sys.__egginsert $path_file" # Check the path we inserted is actually at the top expected="$full_path" actual=$($WORKON_HOME/pathtest_noclobber/bin/python -c "import sys; sys.stdout.write(sys.path[1]+'\n')") assertSame "$expected" "$actual" # Make sure the temporary file created # during the edit was removed assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]" cd - >/dev/null 2>&1 } test_add2virtualenv_relative () { mkvirtualenv "pathtest_relative" >/dev/null 2>&1 parent_dir=$(dirname $(pwd)) base_dir=$(basename $(pwd)) add2virtualenv "../$base_dir" cdsitepackages path_file="./_virtualenv_path_extensions.pth" assertTrue "No $parent_dir/$base_dir in \"`cat $path_file`\"" "grep -q \"$parent_dir/$base_dir\" $path_file" cd - >/dev/null 2>&1 } test_add2virtualenv_space () { # see #132 mkvirtualenv "pathtest_space" >/dev/null 2>&1 parent_dir=$(dirname $(pwd)) cdvirtualenv mkdir 'a b' add2virtualenv 'a b' cdsitepackages path_file="./_virtualenv_path_extensions.pth" assertTrue "No 'a b' in \"`cat $path_file`\"" "grep -q 'a b' $path_file" cd - >/dev/null 2>&1 } test_add2virtualenv_ampersand () { # see #132 mkvirtualenv "pathtest_ampersand" >/dev/null 2>&1 parent_dir=$(dirname $(pwd)) cdvirtualenv mkdir 'a & b' add2virtualenv 'a & b' cdsitepackages path_file="./_virtualenv_path_extensions.pth" assertTrue "No 'a & b' in \"`cat $path_file`\"" "grep -q 'a & b' $path_file" cd - >/dev/null 2>&1 } test_add2virtualenv_delete () { path_file="./_virtualenv_path_extensions.pth" mkvirtualenv "pathtest_delete" >/dev/null 2>&1 cdsitepackages # Make sure it was added add2virtualenv "/full/path" assertTrue "No /full/path in $(cat $path_file)" "grep -q /full/path $path_file" # Remove it and verify that change add2virtualenv -d "/full/path" assertFalse "/full/path in `cat $path_file`" "grep -q /full/path $path_file" cd - >/dev/null 2>&1 } test_add2virtualenv_delete_space () { path_file="./_virtualenv_path_extensions.pth" mkvirtualenv "pathtest_delete_space" >/dev/null 2>&1 cdsitepackages # Make sure it was added add2virtualenv "/full/path with spaces" assertTrue "No /full/path with spaces in $(cat $path_file)" "grep -q '/full/path with spaces' $path_file" # Remove it and verify that change add2virtualenv -d "/full/path with spaces" assertFalse "/full/path with spaces in `cat $path_file`" "grep -q '/full/path with spaces' $path_file" cd - >/dev/null 2>&1 } test_add2virtualenv_delete_ampersand () { path_file="./_virtualenv_path_extensions.pth" mkvirtualenv "pathtest_delete_ampersand" >/dev/null 2>&1 cdsitepackages # Make sure it was added add2virtualenv "/full/path & dir" assertTrue "No /full/path & dir in $(cat $path_file)" "grep -q '/full/path & dir' $path_file" # Remove it and verify that change add2virtualenv -d "/full/path & dir" assertFalse "/full/path & dir in `cat $path_file`" "grep -q '/full/path & dir' $path_file" cd - >/dev/null 2>&1 } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_allvirtualenv.sh0000755000101700007650000000121512172544500024673 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" unset VIRTUAL_ENV source "$test_dir/../virtualenvwrapper.sh" mkvirtualenv test1 >/dev/null 2>&1 mkvirtualenv test2 >/dev/null 2>&1 deactivate } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } tearDown () { deactivate >/dev/null 2>&1 } test_allvirtualenv_all() { assertTrue "Did not find test1" "allvirtualenv pwd | grep -q 'test1$'" assertTrue "Did not find test2" "allvirtualenv pwd | grep -q 'test2$'" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_cd.sh0000755000101700007650000000342612172543425022404 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" unset VIRTUAL_ENV source "$test_dir/../virtualenvwrapper.sh" mkvirtualenv cd-test deactivate } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo workon cd-test } tearDown () { deactivate >/dev/null 2>&1 } test_cdvirtual() { start_dir="$(pwd)" cdvirtualenv assertSame "$VIRTUAL_ENV" "$(pwd)" cdvirtualenv bin assertSame "$VIRTUAL_ENV/bin" "$(pwd)" cd "$start_dir" } test_cdsitepackages () { start_dir="$(pwd)" cdsitepackages pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.) sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages" assertSame "$sitepackages" "$(pwd)" cd "$start_dir" } test_cdsitepackages_with_arg () { start_dir="$(pwd)" pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.) sitepackage_subdir="$VIRTUAL_ENV/lib/python${pyvers}/site-packages/subdir" mkdir -p "${sitepackage_subdir}" cdsitepackages subdir assertSame "$sitepackage_subdir" "$(pwd)" cd "$start_dir" } test_cdvirtualenv_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" cdvirtualenv >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" WORKON_HOME="$old_home" } test_cdsitepackages_no_workon_home () { deactivate 2>&1 old_home="$WORKON_HOME" cd "$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" assertFalse "Was able to change to site-packages" cdsitepackages assertSame "$old_home" "$(pwd)" WORKON_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_cp.sh0000755000101700007650000001426212172545147022423 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" setUp () { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" rm -f "$TMPDIR/catch_output" echo } tearDown() { if type deactivate >/dev/null 2>&1 then deactivate fi rm -rf "$WORKON_HOME" } test_new_env_activated () { mkvirtualenv "source" >/dev/null 2>&1 RC=$? assertEquals "0" "$RC" (cd tests/testpackage && python setup.py install) >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 rmvirtualenv "source" >/dev/null 2>&1 testscript="$(which testscript.py)" assertTrue "Environment test script not found in path" "[ $WORKON_HOME/destination/bin/testscript.py -ef $testscript ]" testscriptcontent="$(cat $testscript)" assertTrue "No cpvirtualenvtest in $testscriptcontent" "echo $testscriptcontent | grep cpvirtualenvtest" assertTrue virtualenvwrapper_verify_active_environment } test_virtual_env_variable () { mkvirtualenv "source" >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 assertSame "Wrong virtualenv name" "destination" $(basename "$VIRTUAL_ENV") assertTrue "$WORKON_HOME not in $VIRTUAL_ENV" "echo $VIRTUAL_ENV | grep -q $WORKON_HOME" } fake_venv () { ### # create a silly file to ensure copy happens ### typeset envname="$1" virtualenv $@ touch "$WORKON_HOME/$envname/fake_virtualenv_was_here" } fake_venv_clone () { ### # create a silly file to ensure copy happens ### typeset src_path="$1" touch "$src_path/fake_virtualenv_clone_was_here" virtualenv-clone $@ } test_virtualenvwrapper_virtualenv_variable () { eval 'virtualenvwrapper_verify_virtualenv () { return 0 }' VIRTUALENVWRAPPER_VIRTUALENV=fake_venv assertSame "VIRTUALENVWRAPPER_VIRTUALENV is not set correctly" "$VIRTUALENVWRAPPER_VIRTUALENV" "fake_venv" mkvirtualenv "source" >/dev/null 2>&1 assertTrue "Fake file not made in fake_venv" "[ -f "$VIRTUAL_ENV/fake_virtualenv_was_here" ]" cpvirtualenv "source" "destination" >/dev/null 2>&1 unset VIRTUALENVWRAPPER_VIRTUALENV assertTrue "VIRTUALENVWRAPPER_CLONE did not clone fake file" "[ -f $WORKON_HOME/destination/fake_virtualenv_was_here ]" } test_virtualenvwrapper_virtualenv_clone_variable () { eval 'virtualenvwrapper_verify_virtualenv_clone () { return 0 }' VIRTUALENVWRAPPER_VIRTUALENV_CLONE=fake_venv_clone assertSame "VIRTUALENVWRAPPER_VIRTUALENV_CLONE is not set correctly" "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" "fake_venv_clone" mkvirtualenv "source" >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 unset VIRTUALENVWRAPPER_VIRTUALENV_CLONE assertTrue "VIRTUALENVWRAPPER_CLONE did not clone fake file" "[ -f $WORKON_HOME/destination/fake_virtualenv_clone_was_here ]" } test_source_relocatable () { mkvirtualenv "source" >/dev/null 2>&1 (cd tests/testpackage && python setup.py install) >/dev/null 2>&1 assertTrue "virtualenv --relocatable \"$WORKON_HOME/source\"" cpvirtualenv "source" "destination" >/dev/null 2>&1 testscript="$(which testscript.py)" assertTrue "Environment test script not the same as copy" "[ $WORKON_HOME/destination/bin/testscript.py -ef $testscript ]" assertTrue virtualenvwrapper_verify_active_environment assertSame "Wrong virtualenv name" "destination" $(basename "$VIRTUAL_ENV") } test_source_does_not_exist () { assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv virtualenvthatdoesntexist foo)" } test_hooks () { mkvirtualenv "source" >/dev/null 2>&1 # Set the interpreter of the hook script to the simple shell echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv" chmod +x "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv" # Set the interpreter of the hook script to the simple shell echo "#!/bin/sh" > "$WORKON_HOME/precpvirtualenv" echo "echo GLOBAL precpvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/precpvirtualenv" chmod +x "$WORKON_HOME/precpvirtualenv" # Set the interpreter of the hook script to the simple shell echo "#!/bin/sh" > "$WORKON_HOME/postcpvirtualenv" echo "echo GLOBAL postcpvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postcpvirtualenv" cpvirtualenv "source" "destination" >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output") workon_home_as_pwd=$(cd $WORKON_HOME; pwd) expected="GLOBAL precpvirtualenv $workon_home_as_pwd $workon_home_as_pwd/source destination GLOBAL premkvirtualenv $workon_home_as_pwd destination GLOBAL postmkvirtualenv GLOBAL postcpvirtualenv" assertSame "$expected" "$output" rm -f "$WORKON_HOME/premkvirtualenv" rm -f "$WORKON_HOME/postmkvirtualenv" } test_no_site_packages () { # See issue #102 mkvirtualenv "source" --no-site-packages >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist in copied env" "[ -f \"$ngsp_file\" ]" } test_no_site_packages_default_args () { # See issue #102 VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages" # With the argument, verify that they are not copied. mkvirtualenv "source" >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]" unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS } test_no_site_packages_default_behavior () { # See issue #102 # virtualenv 1.7 changed to make --no-site-packages the default mkvirtualenv "source" >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist in copied env" "[ -f \"$ngsp_file\" ]" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_cpvirtualenv.sh0000755000101700007650000002051312172545636024542 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" setUp () { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" echo } tearDown () { if type deactivate >/dev/null 2>&1 then deactivate fi rm -rf "$WORKON_HOME" } test_no_arguments () { assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv)" } test_venv_already_exists_in_workon () { mkvirtualenv "cpvenv_test" >/dev/null 2>&1 assertSame "cpvenv_test virtualenv already exists." "$(cpvirtualenv 'cpvenv_test')" } test_bad_path () { assertSame "Please provide a valid virtualenv to copy." "$(cpvirtualenv '~/cpvenv_test')" } test_copy_venv () { # verify venvs don't exist assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]" mkvirtualenv "cpvenv_test" >/dev/null 2>&1 touch "$WORKON_HOME/cpvenv_test/mytestpackage" assertTrue "Virtualenv to copy didn't get created" "[ -d $WORKON_HOME/cpvenv_test ]" assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]" cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1 # verify copied venv exist assertTrue "Copied virtualenv doesn't exist" "[ -d $WORKON_HOME/copied_venv ]" # verify test package exists assertTrue "Test package is missing" "[ -f $WORKON_HOME/copied_venv/mytestpackage ]" } test_copy_venv_activate () { # verify venvs don't exist assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]" mkvirtualenv "cpvenv_test" >/dev/null 2>&1 assertTrue "Virtualenv to copy didn't get created" "[ -d $WORKON_HOME/cpvenv_test ]" assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]" cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1 # verify copied venv exist assertTrue "Copied virtualenv doesn't exist" "[ -d $WORKON_HOME/copied_venv ]" assertSame "copied_venv" "$(basename $VIRTUAL_ENV)" assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment } test_copy_venv_is_listed () { # verify venvs don't exist assertTrue "Virtualenv to copy already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" assertTrue "Copied virtualenv already exists" "[ ! -d $WORKON_HOME/copied_venv ]" mkvirtualenv "cpvenv_test" >/dev/null 2>&1 typeset listed=$(lsvirtualenv) [[ "$listed" != *copied_venv* ]] RC=$? assertTrue "Copied virtualenv found in virtualenv list" $RC cpvirtualenv "cpvenv_test" "copied_venv" >/dev/null 2>&1 listed=$(lsvirtualenv -b) [[ "$listed" == *copied_venv* ]] RC=$? assertTrue "Copied virtualenv not found in virtualenv list" $RC } test_clone_venv () { typeset tmplocation=$(dirname $WORKON_HOME) # verify venvs don't exist assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]" $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1 touch "$tmplocation/cpvenv_test/mytestpackage" assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]" cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1 # verify cloned venv exist assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cloned_venv ]" # verify test package exists assertTrue "Test package is missing" "[ -f $WORKON_HOME/cloned_venv/mytestpackage ]" rm -rf "$tmplocation/cpvenv_test" } test_clone_venv_activate () { typeset tmplocation=$(dirname $WORKON_HOME) # verify venvs don't exist assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]" assertTrue "Virtualenv with same name as clone source already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]" $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1 assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]" #cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1 cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2/>&1 # verify cloned venv exist assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cloned_venv ]" assertSame "cloned_venv" "$(basename $VIRTUAL_ENV)" assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment rm -rf "$tmplocation/cpvenv_test" } test_clone_venv_is_listed (){ typeset tmplocation=$(dirname $WORKON_HOME) # verify venvs don't exist assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]" assertTrue "Virtualenv with same name as clone source already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cloned_venv ]" typeset listed=$(lsvirtualenv) [[ "$listed" != *cloned_venv* ]] RC=$? assertTrue "Cloned virtualenv found in virtualenv list" $RC $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1 cpvirtualenv "$tmplocation/cpvenv_test" "cloned_venv" >/dev/null 2>&1 listed=$(lsvirtualenv -b) [[ "$listed" == *cloned_venv* ]] RC=$? assertTrue "Cloned virtualenv not found in virtualenv list" $RC rm -rf "$tmplocation/cpvenv_test" } test_clone_venv_using_same_name () { typeset tmplocation=$(dirname $WORKON_HOME) # verify venvs don't exist assertTrue "Virtualenv to clone already exists" "[ ! -d $tmplocation/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" $VIRTUALENVWRAPPER_VIRTUALENV "$tmplocation/cpvenv_test" >/dev/null 2>&1 touch "$tmplocation/cpvenv_test/mytestpackage" assertTrue "Virtualenv to clone didn't get created" "[ -d $tmplocation/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" typeset listed=$(lsvirtualenv) [[ "$listed" != *cpvenv_test* ]] RC=$? assertTrue "Cloned virtualenv found in virtualenv list" $RC cpvirtualenv "$tmplocation/cpvenv_test" >/dev/null 2>&1 >/dev/null 2>&1 # verify cloned venv exist assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cpvenv_test ]" assertTrue "Test package is missing" "[ -f $WORKON_HOME/cpvenv_test/mytestpackage ]" listed=$(lsvirtualenv -b) [[ "$listed" == *cpvenv_test* ]] RC=$? assertTrue "Cloned virtualenv not found in virtualenv list" $RC assertSame "cpvenv_test" "$(basename $VIRTUAL_ENV)" assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment rm -rf "$tmplocation/cpvenv_test" } test_clone_venv_using_vars () { # verify venvs don't exist assertTrue "Virtualenv to clone already exists" "[ ! -d $TMPDIR/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" $VIRTUALENVWRAPPER_VIRTUALENV "$TMPDIR/cpvenv_test" >/dev/null 2>&1 touch "$TMPDIR/cpvenv_test/mytestpackage" assertTrue "Virtualenv to clone didn't get created" "[ -d $TMPDIR/cpvenv_test ]" assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]" typeset listed=$(lsvirtualenv) [[ "$listed" != *cpvenv_test* ]] RC=$? assertTrue "Cloned virtualenv found in virtualenv list" $RC cpvirtualenv '$TMPDIR/cpvenv_test' >/dev/null 2>&1 >/dev/null 2>&1 # verify cloned venv exist assertTrue "Cloned virtualenv doesn't exist" "[ -d $WORKON_HOME/cpvenv_test ]" assertTrue "Test package is missing" "[ -f $WORKON_HOME/cpvenv_test/mytestpackage ]" listed=$(lsvirtualenv -b) [[ "$listed" == *cpvenv_test* ]] RC=$? assertTrue "Cloned virtualenv not found in virtualenv list" $RC assertSame "cpvenv_test" "$(basename $VIRTUAL_ENV)" assertTrue "Virtualenv not active" virtualenvwrapper_verify_active_environment rm -rf "$TMPDIR/cpvenv_test" } source "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_deactivate.sh0000755000101700007650000000243212172545232024121 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" mkvirtualenv "env1" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo rm -f "$TMPDIR/catch_output" } test_deactivate () { workon env1 assertNotNull "$VIRTUAL_ENV" deactivate assertNull "$VIRTUAL_ENV" assertFalse virtualenvwrapper_verify_active_environment } test_deactivate_hooks () { workon env1 for t in pre post do echo "echo GLOBAL ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $TMPDIR/catch_output" > "$WORKON_HOME/${t}deactivate" echo "echo ENV ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $TMPDIR/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate" done touch "$TMPDIR/catch_output" deactivate output=$(cat "$TMPDIR/catch_output") expected="ENV predeactivate GLOBAL predeactivate ENV postdeactivate $WORKON_HOME/env1 GLOBAL postdeactivate $WORKON_HOME/env1" assertSame "$expected" "$output" for t in pre post do rm -f "$WORKON_HOME/env1/bin/${t}activate" rm -f "$WORKON_HOME/${t}activate" done } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_derive_workon_home.sh0000755000101700007650000000174312172543477025712 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" TMP_WORKON_HOME="$WORKON_HOME" oneTimeSetUp() { rm -rf "$TMP_WORKON_HOME" mkdir -p "$TMP_WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" echo $PYTHONPATH } oneTimeTearDown() { rm -rf "$TMP_WORKON_HOME" } setUp () { echo WORKON_HOME="$TMP_WORKON_HOME" } test_default() { unset WORKON_HOME assertSame "$HOME/.virtualenvs" "$(virtualenvwrapper_derive_workon_home)" } test_includes_relative_path() { WORKON_HOME="$WORKON_HOME/../$(basename $WORKON_HOME)" assertSame "$WORKON_HOME" "$(virtualenvwrapper_derive_workon_home)" } test_begins_relative_path() { WORKON_HOME=".test-virtualenvs" assertSame "$HOME/.test-virtualenvs" "$(virtualenvwrapper_derive_workon_home)" } test_includes_tilde() { WORKON_HOME="~/.test-virtualenvs" assertSame "$HOME/.test-virtualenvs" "$(virtualenvwrapper_derive_workon_home)" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_dir_stack.sh0000755000101700007650000000176512143435522023761 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { test_begin_dir=$(pwd) } oneTimeTearDown() { cd "$test_begin_dir" } setUp () { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" mkdir "$WORKON_HOME/start_here" mkdir "$WORKON_HOME/on_the_stack" echo } tearDown() { if type deactivate >/dev/null 2>&1 then deactivate fi rm -rf "$WORKON_HOME" } test_ticket_101 () { [ ! -z "$KSH_VERSION" ] && echo "Skipping test under ksh" && return 0 mkvirtualenv some_env deactivate cd "$WORKON_HOME/start_here" pushd "$WORKON_HOME/on_the_stack" rmvirtualenv some_env mkvirtualenv some_env >/dev/null 2>&1 #echo "After mkvirtualenv: `pwd`" deactivate #echo "After deactivate: `pwd`" popd #echo "After popd: `pwd`" current_dir=$(pwd) assertSame "$WORKON_HOME/start_here" "$current_dir" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_expandpath.sh0000755000101700007650000000101012143435522024131 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" TMP_WORKON_HOME="$WORKON_HOME" oneTimeSetUp() { source "$test_dir/../virtualenvwrapper.sh" echo $PYTHONPATH } oneTimeTearDown() { return 0 } test_tilde() { assertSame "$HOME" "$(virtualenvwrapper_expandpath ~)" } test_vars() { assertSame "$HOME" "$(virtualenvwrapper_expandpath '$HOME')" } test_tilde_vars() { assertSame "$HOME" "$(virtualenvwrapper_expandpath '~$USER')" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_hook_dir.sh0000755000101700007650000000143712172543503023611 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" mkdir -p "$WORKON_HOME/hooks" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo rm -f "$WORKON_HOME/hooks/*" } test_virtualenvwrapper_initialize() { export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME/hooks" source "$test_dir/../virtualenvwrapper.sh" for hook in premkvirtualenv postmkvirtualenv prermvirtualenv postrmvirtualenv preactivate postactivate predeactivate postdeactivate do assertTrue "Global $hook was not created" "[ -f $WORKON_HOME/hooks/$hook ]" assertTrue "Global $hook is not executable" "[ -x $WORKON_HOME/hooks/$hook ]" done } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_lazy.sh0000755000101700007650000000406212172543506022772 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" [ ! -z "$ZSH_VERSION" ] && unsetopt shwordsplit source "$test_dir/../virtualenvwrapper_lazy.sh" [ ! -z "$ZSH_VERSION" ] && setopt shwordsplit } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } function_defined_lazy() { name="$1" assertTrue "$name not defined" "type $name" assertTrue "$name does not load virtualenvwrapper" "typeset -f $name | grep 'virtualenvwrapper_load'" if [ "$name" = "mkvirtualenv" ] then lookfor="rmvirtualenv" else lookfor="mkvirtualenv" fi assertFalse "$name includes reference to $lookfor: $(typeset -f $name)" "typeset -f $name | grep $lookfor" } test_mkvirtualenv_defined_lazy() { function_defined_lazy mkvirtualenv } test_rmvirtualenv_defined_lazy() { function_defined_lazy rmvirtualenv } test_lsvirtualenv_defined_lazy() { function_defined_lazy lsvirtualenv } test_showvirtualenv_defined_lazy() { function_defined_lazy showvirtualenv } test_workon_defined_lazy() { function_defined_lazy workon } test_add2virtualenv_defined_lazy() { function_defined_lazy add2virtualenv } test_cdsitepackages_defined_lazy() { function_defined_lazy cdsitepackages } test_cdvirtualenv_defined_lazy() { function_defined_lazy cdvirtualenv } test_cdvirtualenv_defined_lazy() { function_defined_lazy cdvirtualenv } test_lssitepackages_defined_lazy() { function_defined_lazy lssitepackages } test_toggleglobalsitepackages_defined_lazy() { function_defined_lazy toggleglobalsitepackages } test_cpvirtualenv_defined_lazy() { function_defined_lazy cpvirtualenv } test_setvirtualenvproject_defined_lazy() { function_defined_lazy setvirtualenvproject } test_mkproject_defined_lazy() { function_defined_lazy mkproject } test_cdproject_defined_lazy() { function_defined_lazy cdproject } test_mktmpenv_defined_lazy() { function_defined_lazy mktmpenv } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_lazy_extending.sh0000755000101700007650000000162312172543511025033 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" [ ! -z "$ZSH_VERSION" ] && unsetopt shwordsplit } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } function_defined_lazy() { name="$1" assertTrue "$name not defined" "type $name" assertTrue "$name does not load virtualenvwrapper" "typeset -f $name | grep 'virtualenvwrapper_load'" if [ "$name" = "mkvirtualenv" ] then lookfor="rmvirtualenv" else lookfor="mkvirtualenv" fi assertFalse "$name includes reference to $lookfor: $(typeset -f $name)" "typeset -f $name | grep $lookfor" } test_custom_defined_lazy() { _VIRTUALENVWRAPPER_API="my_custom_command" source "$test_dir/../virtualenvwrapper_lazy.sh" function_defined_lazy my_custom_command } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_lazy_loaded.sh0000755000101700007650000000510112172544535024300 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper_lazy.sh" virtualenvwrapper_load } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } function_defined_normal() { name="$1" assertTrue "$name not defined" "type $name" assertFalse "$name still set to run lazy loader" "typeset -f $name | grep 'virtualenvwrapper_load'" } test_mkvirtualenv_defined_normal() { function_defined_normal mkvirtualenv } test_rmvirtualenv_defined_normal() { function_defined_normal rmvirtualenv } test_lsvirtualenv_defined_normal() { function_defined_normal lsvirtualenv } test_showvirtualenv_defined_normal() { function_defined_normal showvirtualenv } test_workon_defined_normal() { function_defined_normal workon } test_add2virtualenv_defined_normal() { function_defined_normal add2virtualenv } test_cdsitepackages_defined_normal() { function_defined_normal cdsitepackages } test_cdvirtualenv_defined_normal() { function_defined_normal cdvirtualenv } test_cdvirtualenv_defined_normal() { function_defined_normal cdvirtualenv } test_lssitepackages_defined_normal() { function_defined_normal lssitepackages } test_toggleglobalsitepackages_defined_normal() { function_defined_normal toggleglobalsitepackages } test_cpvirtualenv_defined_normal() { function_defined_normal cpvirtualenv } test_setvirtualenvproject_defined_normal() { function_defined_normal setvirtualenvproject } test_mkproject_defined_normal() { function_defined_normal mkproject } test_cdproject_defined_normal() { function_defined_normal cdproject } test_mktmpenv_defined_normal() { function_defined_normal mktmpenv } # test_virtualenvwrapper_initialize() { # assertTrue "Initialized" virtualenvwrapper_initialize # for hook in premkvirtualenv postmkvirtualenv prermvirtualenv postrmvirtualenv preactivate postactivate predeactivate postdeactivate # do # assertTrue "Global $WORKON_HOME/$hook was not created" "[ -f $WORKON_HOME/$hook ]" # assertTrue "Global $WORKON_HOME/$hook is not executable" "[ -x $WORKON_HOME/$hook ]" # done # assertTrue "Log file was not created" "[ -f $WORKON_HOME/hook.log ]" # echo "echo GLOBAL initialize >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize" # virtualenvwrapper_initialize # output=$(cat "$TMPDIR/catch_output") # expected="GLOBAL initialize" # assertSame "$expected" "$output" # } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_lazy_run.sh0000755000101700007650000000137212172543524023657 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" (cd "$WORKON_HOME" && virtualenv lazy_load_test >/dev/null 2>&1) source "$test_dir/../virtualenvwrapper_lazy.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_workon_changes_defs() { # See issue #144 assertFalse "virtualenvwrapper_run_hook is already defined" "type virtualenvwrapper_run_hook" workon lazy_load_test >/dev/null 2>&1 assertTrue "virtualenvwrapper_run_hook is not defined" "type virtualenvwrapper_run_hook" assertTrue "workon still set to run lazy loader" "typeset -f $name | grep 'virtualenvwrapper_load'" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_log_file.sh0000755000101700007650000000156012143435522023567 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" setUp () { echo } test_set_by_user() { export VIRTUALENVWRAPPER_LOG_FILE="$WORKON_HOME/hooks.log" source "$test_dir/../virtualenvwrapper.sh" assertTrue "Log file was not created" "[ -f $VIRTUALENVWRAPPER_LOG_FILE ]" } test_file_permissions() { export VIRTUALENVWRAPPER_LOG_FILE="$WORKON_HOME/hooks.log" source "$test_dir/../virtualenvwrapper.sh" perms=$(ls -l "$VIRTUALENVWRAPPER_LOG_FILE" | cut -f1 -d' ') #echo $perms assertTrue "Log file permissions are wrong: $perms" "echo $perms | grep '^-rw-rw'" } test_not_set_by_user() { unset WORKON_HOME unset VIRTUALENVWRAPPER_LOG_FILE unset VIRTUALENVWRAPPER_HOOK_DIR source "$test_dir/../virtualenvwrapper.sh" assertSame "" "$VIRTUALENVWRAPPER_LOG_FILE" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_ls.sh0000755000101700007650000000270312172543527022434 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_get_site_packages_dir () { mkvirtualenv "lssitepackagestest" >/dev/null 2>&1 d=$(virtualenvwrapper_get_site_packages_dir) echo "site-packages in $d" assertTrue "site-packages dir $d does not exist" "[ -d $d ]" deactivate } test_lssitepackages () { mkvirtualenv "lssitepackagestest" >/dev/null 2>&1 contents="$(lssitepackages)" actual=$(echo $contents | grep easy-install.pth) expected=$(echo $contents) assertSame "$expected" "$actual" deactivate } test_lssitepackages_add2virtualenv () { mkvirtualenv "lssitepackagestest" >/dev/null 2>&1 parent_dir=$(dirname $(pwd)) base_dir=$(basename $(pwd)) add2virtualenv "../$base_dir" contents="$(lssitepackages)" actual=$(echo $contents | grep $base_dir) expected=$(echo $contents) assertSame "$expected" "$actual" deactivate } test_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" lssitepackages >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" WORKON_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_lsvirtualenv.sh0000755000101700007650000000173612172543532024555 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" lsvirtualenv >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" WORKON_HOME="$old_home" } test_space_in_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/with space" mkdir "$WORKON_HOME" (cd "$WORKON_HOME"; virtualenv testenv) 2>&1 lsvirtualenv -b >"$old_home/output" output=$(cat "$old_home/output") assertTrue "Did not see expected message in \"$output\"" "echo $output | grep 'testenv'" WORKON_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_mktmpenv.sh0000755000101700007650000000221112172543535023650 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_mktmpenv_no_name() { before=$(lsvirtualenv -b) mktmpenv >/dev/null 2>&1 after=$(lsvirtualenv -b) assertFalse "Environment was not created" "[ \"$before\" = \"$after\" ]" } test_mktmpenv_name() { mktmpenv name-given-by-user >/dev/null 2>&1 RC=$? assertTrue "Error was not detected" "[ $RC -ne 0 ]" } test_mktmpenv_virtualenv_args() { mktmpenv --no-site-packages >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]" } test_deactivate() { mktmpenv >/dev/null 2>&1 assertTrue "Environment was not created" "[ ! -z \"$VIRTUAL_ENV\" ]" env_name=$(basename "$VIRTUAL_ENV") deactivate >/dev/null 2>&1 assertFalse "Environment still exists" "[ -d \"$WORKON_HOME/$env_name\" ]" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_mkvirtualenv.sh0000755000101700007650000001674312172545266024560 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo rm -f "$TMPDIR/catch_output" } test_create() { mkvirtualenv "env1" >/dev/null 2>&1 assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]" for hook in postactivate predeactivate postdeactivate do assertTrue "env1 $hook was not created" "[ -f $WORKON_HOME/env1/bin/$hook ]" assertTrue "env1 $hook is not executable" "[ -x $WORKON_HOME/env1/bin/$hook ]" done } test_activates () { mkvirtualenv "env2" >/dev/null 2>&1 assertTrue virtualenvwrapper_verify_active_environment assertSame "env2" $(basename "$VIRTUAL_ENV") } test_hooks () { echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv" chmod +x "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv" mkvirtualenv "env3" >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output") workon_home_as_pwd=$(cd $WORKON_HOME; pwd) expected="GLOBAL premkvirtualenv $workon_home_as_pwd env3 GLOBAL postmkvirtualenv" assertSame "$expected" "$output" rm -f "$WORKON_HOME/premkvirtualenv" rm -f "$WORKON_HOME/postmkvirtualenv" deactivate rmvirtualenv "env3" >/dev/null 2>&1 } test_no_virtualenv () { # Find "which" before we change the path which=$(which which) old_path="$PATH" PATH="/bin:/usr/sbin:/sbin" venv=$($which virtualenv 2>/dev/null) if [ ! -z "$venv" ] then echo "FOUND \"$venv\" in PATH so skipping this test" export PATH="$old_path" return 0 fi mkvirtualenv should_not_be_created >/dev/null 2>&1 RC=$? # Restore the path before testing because # the test script depends on commands in the # path. export PATH="$old_path" assertSame "$RC" "1" } test_no_args () { mkvirtualenv 2>/dev/null 1>&2 RC=$? assertSame "2" "$RC" } test_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" mkvirtualenv should_be_created >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message in \"$output\"" "cat \"$old_home/output\" | grep 'does not exist'" assertTrue "Did not create environment" "[ -d \"$WORKON_HOME/should_be_created\" ]" WORKON_HOME="$old_home" } test_mkvirtualenv_sitepackages () { # This part of the test is not reliable because # creating a new virtualenv from inside the # tox virtualenv inherits the setting from there. # # Without the option, verify that site-packages are copied. # mkvirtualenv "with_sp" >/dev/null 2>&1 # ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" # assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]" # rmvirtualenv "env3" # With the argument, verify that they are not copied. mkvirtualenv --no-site-packages "without_sp" >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]" rmvirtualenv "env4" >/dev/null 2>&1 } test_mkvirtualenv_hooks_system_site_packages () { # See issue #189 echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv" chmod +x "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv" mkvirtualenv --system-site-packages "env189" >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output") workon_home_as_pwd=$(cd $WORKON_HOME; pwd) expected="GLOBAL premkvirtualenv $workon_home_as_pwd env189 GLOBAL postmkvirtualenv" assertSame "$expected" "$output" rm -f "$WORKON_HOME/premkvirtualenv" rm -f "$WORKON_HOME/postmkvirtualenv" deactivate rmvirtualenv "env189" >/dev/null 2>&1 } test_mkvirtualenv_args () { # See issue #102 VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages" # With the argument, verify that they are not copied. mkvirtualenv "without_sp2" >/dev/null 2>&1 ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]" rmvirtualenv "env4" >/dev/null 2>&1 unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS } test_no_such_virtualenv () { VIRTUALENVWRAPPER_VIRTUALENV=/path/to/missing/program echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv" chmod +x "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv" mkvirtualenv "env3" >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output" 2>/dev/null) workon_home_as_pwd=$(cd $WORKON_HOME; pwd) expected="" assertSame "$expected" "$output" rm -f "$WORKON_HOME/premkvirtualenv" rm -f "$WORKON_HOME/postmkvirtualenv" VIRTUALENVWRAPPER_VIRTUALENV=virtualenv } test_virtualenv_fails () { # Test to reproduce the conditions in issue #76 # https://bitbucket.org/dhellmann/virtualenvwrapper/issue/76/ # # Should not run the premkvirtualenv or postmkvirtualenv hooks # because the environment is not created and even the # premkvirtualenv hooks are run *after* the environment exists # (but before it is activated). export pre_test_dir=$(cd "$test_dir"; pwd) VIRTUALENVWRAPPER_VIRTUALENV=false echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv" chmod +x "$WORKON_HOME/premkvirtualenv" echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv" mkvirtualenv "env3" >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output" 2>/dev/null) workon_home_as_pwd=$(cd $WORKON_HOME; pwd) expected="" assertSame "$expected" "$output" rm -f "$WORKON_HOME/premkvirtualenv" rm -f "$WORKON_HOME/postmkvirtualenv" VIRTUALENVWRAPPER_VIRTUALENV=virtualenv } test_mkvirtualenv_python_not_sticky () { typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV VIRTUALENVWRAPPER_VIRTUALENV=true mkvirtualenv --python blah foo assertSame "" "$interpreter" VIRTUALENVWRAPPER_VIRTUALENV=$_save } test_mkvirtualenv_python_short_option () { typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV VIRTUALENVWRAPPER_VIRTUALENV=echo output="$(mkvirtualenv -p python foo)" assertSame "--python=$(pwd)/python foo" "$output" VIRTUALENVWRAPPER_VIRTUALENV=$_save } test_mkvirtualenv_python_long_option () { typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV VIRTUALENVWRAPPER_VIRTUALENV=echo output="$(mkvirtualenv --python python foo)" assertSame "--python=$(pwd)/python foo" "$output" VIRTUALENVWRAPPER_VIRTUALENV=$_save } test_mkvirtualenv_python_long_option_equal () { typeset _save=$VIRTUALENVWRAPPER_VIRTUALENV VIRTUALENVWRAPPER_VIRTUALENV=echo output="$(mkvirtualenv --python=python foo)" assertSame "--python=$(pwd)/python foo" "$output" VIRTUALENVWRAPPER_VIRTUALENV=$_save } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_mkvirtualenv_associate.sh0000755000101700007650000000323012172545277026600 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -f "$test_dir/requirements.txt" } setUp () { echo echo "#!/bin/sh" > "$WORKON_HOME/preactivate" echo "#!/bin/sh" > "$WORKON_HOME/postactivate" rm -f "$TMPDIR/catch_output" } test_associate() { project="/dev/null" env="env1" ptrfile="$WORKON_HOME/$env/.project" mkvirtualenv -a "$project" "$env" >/dev/null 2>&1 assertTrue ".project not found" "[ -f $ptrfile ]" assertEquals "$ptrfile contains wrong content" "$project" "$(cat $ptrfile)" } test_preactivate() { project="/dev/null" env="env2" ptrfile="$WORKON_HOME/$env/.project" cat - >"$WORKON_HOME/preactivate" <> "$TMPDIR/catch_output" else echo noexists >> "$TMPDIR/catch_output" fi EOF chmod +x "$WORKON_HOME/preactivate" mkvirtualenv -a "$project" "$env" >/dev/null 2>&1 assertSame "preactivate did not find file" "exists" "$(cat $TMPDIR/catch_output)" } test_postactivate() { project="/dev/null" env="env3" ptrfile="$WORKON_HOME/$env/.project" cat - >"$WORKON_HOME/postactivate" <> "$TMPDIR/catch_output" else echo noexists >> "$TMPDIR/catch_output" fi EOF chmod +x "$WORKON_HOME/postactivate" mkvirtualenv -a "$project" "$env" >/dev/null 2>&1 assertSame "postactivate did not find file" "exists" "$(cat $TMPDIR/catch_output)" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_mkvirtualenv_install.sh0000755000101700007650000000136012172543773026274 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -f "$test_dir/requirements.txt" } setUp () { echo } test_single_package () { mkvirtualenv -i IPy "env4" installed=$(pip freeze) assertTrue "IPy not found in $installed" "pip freeze | grep IPy" } test_multiple_packages () { mkvirtualenv -i IPy -i WebTest "env5" installed=$(pip freeze) assertTrue "IPy not found in $installed" "pip freeze | grep IPy" assertTrue "WebTest not found in $installed" "pip freeze | grep WebTest" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_mkvirtualenv_requirements.sh0000755000101700007650000000111512172605315027336 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -f "$TMPDIR/requirements.txt" } setUp () { echo } test_requirements_file () { echo "IPy" > "$TMPDIR/requirements.txt" mkvirtualenv -r "$TMPDIR/requirements.txt" "env3" >/dev/null 2>&1 installed=$(pip freeze) assertTrue "IPy not found in $installed" "pip freeze | grep IPy" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_project.sh0000755000101700007650000000304712172544001023452 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" mkdir -p "$PROJECT_HOME" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -rf "$PROJECT_HOME" } setUp () { echo unset VIRTUALENVWRAPPER_INITIALIZED } test_initialize() { source "$test_dir/../virtualenvwrapper.sh" for hook in premkproject postmkproject prermproject postrmproject do assertTrue "Global $hook was not created" "[ -f $WORKON_HOME/$hook ]" assertTrue "Global $hook is not executable" "[ -x $WORKON_HOME/$hook ]" done } test_initialize_hook_dir() { export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME/hooks" mkdir -p "$VIRTUALENVWRAPPER_HOOK_DIR" source "$test_dir/../virtualenvwrapper.sh" for hook in premkproject postmkproject prermproject postrmproject do assertTrue "Global $hook was not created" "[ -f $VIRTUALENVWRAPPER_HOOK_DIR/$hook ]" assertTrue "Global $hook is not executable" "[ -x $VIRTUALENVWRAPPER_HOOK_DIR/$hook ]" done VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME" } test_virtualenvwrapper_verify_project_home() { assertTrue "PROJECT_HOME not verified" virtualenvwrapper_verify_project_home } test_virtualenvwrapper_verify_project_home_missing_dir() { old_home="$PROJECT_HOME" PROJECT_HOME="$PROJECT_HOME/not_there" assertFalse "PROJECT_HOME verified unexpectedly" virtualenvwrapper_verify_project_home PROJECT_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_project_activate.sh0000755000101700007650000000202312172544004025326 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" mkdir -p "$PROJECT_HOME" source "$test_dir/../virtualenvwrapper.sh" } # oneTimeTearDown() { # rm -rf "$WORKON_HOME" # rm -rf "$PROJECT_HOME" # } setUp () { echo } test_activate () { mkproject myproject >/dev/null 2>&1 deactivate cd $TMPDIR assertSame "" "$VIRTUAL_ENV" workon myproject assertSame "myproject" "$(basename $VIRTUAL_ENV)" assertSame "$PROJECT_HOME/myproject" "$(pwd)" deactivate } test_space_in_path () { old_project_home="$PROJECT_HOME" PROJECT_HOME="$PROJECT_HOME/with spaces" mkdir -p "$PROJECT_HOME" mkproject "myproject" >/dev/null 2>&1 deactivate cd $TMPDIR workon "myproject" assertSame "myproject" "$(basename $VIRTUAL_ENV)" assertSame "$PROJECT_HOME/myproject" "$(pwd)" deactivate PROJECT_HOME="$old_project_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_project_cd.sh0000755000101700007650000000203512172610510024113 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" mkdir -p "$PROJECT_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -rf "$PROJECT_HOME" } setUp () { echo } test_with_project () { mkproject myproject >/dev/null 2>&1 cd $TMPDIR cdproject assertSame "$PROJECT_HOME/myproject" "$(pwd)" deactivate } test_without_project () { mkvirtualenv myproject >/dev/null 2>&1 cd $TMPDIR output=$(cdproject 2>&1) echo "$output" | grep -q "No project set" RC=$? assertSame "1" "$RC" deactivate } test_space_in_path () { ( set -e PROJECT_HOME="$PROJECT_HOME/with spaces" mkdir -p "$PROJECT_HOME" mkproject "myproject" >/dev/null 2>&1 cd "$WORKON_HOME" cdproject [ "$PROJECT_HOME/myproject" == "$(pwd)" ] ) assertTrue "Did not cd to project directory" $? } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_project_mk.sh0000755000101700007650000000526712172545345024163 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" mkdir -p "$PROJECT_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -rf "$PROJECT_HOME" } setUp () { echo rm -f "$TMPDIR/catch_output" } tearDown () { type deactivate >/dev/null 2>&1 && deactivate } test_create_directories () { mkproject myproject1 >/dev/null 2>&1 assertTrue "env directory not created" "[ -d $WORKON_HOME/myproject1 ]" assertTrue "project directory not created" "[ -d $PROJECT_HOME/myproject1 ]" } test_create_virtualenv () { mkproject myproject2 >/dev/null 2>&1 assertSame "myproject2" $(basename "$VIRTUAL_ENV") assertSame "$PROJECT_HOME/myproject2" "$(cat $VIRTUAL_ENV/.project)" } test_hooks () { echo "echo GLOBAL premkproject \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$VIRTUALENVWRAPPER_HOOK_DIR/premkproject" chmod +x "$VIRTUALENVWRAPPER_HOOK_DIR/premkproject" echo "echo GLOBAL postmkproject \`pwd\` >> $TMPDIR/catch_output" > "$VIRTUALENVWRAPPER_HOOK_DIR/postmkproject" mkproject myproject3 >/dev/null 2>&1 output=$(cat "$TMPDIR/catch_output") expected="GLOBAL premkproject $WORKON_HOME myproject3 GLOBAL postmkproject $PROJECT_HOME/myproject3" assertSame "$expected" "$output" rm -f "$VIRTUALENVWRAPPER_HOOK_DIR/premkproject" rm -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkproject" } test_no_project_home () { old_home="$PROJECT_HOME" export PROJECT_HOME="$PROJECT_HOME/not_there" output=`mkproject should_not_be_created 2>&1` assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" PROJECT_HOME="$old_home" } test_project_exists () { mkproject myproject4 >/dev/null 2>&1 output=`mkproject myproject4 2>&1` assertTrue "Did not see expected message 'already exists' in: $output" "echo $output | grep 'already exists'" } test_same_workon_and_project_home () { old_project_home="$PROJECT_HOME" export PROJECT_HOME="$WORKON_HOME" mkproject myproject5 >/dev/null 2>&1 assertTrue "env directory not created" "[ -d $WORKON_HOME/myproject1 ]" assertTrue "project directory was created" "[ -d $old_project_home/myproject1 ]" PROJECT_HOME="$old_project_home" } test_alternate_linkage_filename () { export VIRTUALENVWRAPPER_PROJECT_FILENAME=".not-project" mkproject myproject6 >/dev/null 2>&1 assertSame "myproject6" $(basename "$VIRTUAL_ENV") assertSame "$PROJECT_HOME/myproject6" "$(cat $VIRTUAL_ENV/.not-project)" export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_project_templates.sh0000755000101700007650000000151212172544066025536 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { (cd "$test_dir/testtemplate" && rm -rf build && "$VIRTUAL_ENV/bin/python" setup.py install) rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" mkdir -p "$PROJECT_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" rm -rf "$PROJECT_HOME" } setUp () { echo } test_list_templates () { output=$(mkproject -h 2>&1) assertTrue "Did not find test template in \"$output\"" "echo \"$output\" | grep -q 'Creates a test file'" } test_apply_template () { mkproject -t test proj1 >/dev/null 2>&1 assertTrue "Test file not created" "[ -f TEST_FILE ]" assertTrue "project name not found" "grep -q proj1 TEST_FILE" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_rmvirtualenv.sh0000755000101700007650000000335312172544070024550 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_remove () { mkvirtualenv "deleteme" >/dev/null 2>&1 assertTrue "[ -d $WORKON_HOME/deleteme ]" deactivate rmvirtualenv "deleteme" assertFalse "[ -d $WORKON_HOME/deleteme ]" } test_remove_several_envs () { mkvirtualenv "deleteme" >/dev/null 2>&1 assertTrue "[ -d $WORKON_HOME/deleteme ]" deactivate mkvirtualenv "deleteme2" >/dev/null 2>&1 assertTrue "[ -d $WORKON_HOME/deleteme2 ]" deactivate rmvirtualenv "deleteme deleteme2" assertFalse "[ -d $WORKON_HOME/deleteme ]" assertFalse "[ -d $WORKON_HOME/deleteme2 ]" } test_within_virtualenv () { mkvirtualenv "deleteme" >/dev/null 2>&1 assertTrue "[ -d $WORKON_HOME/deleteme ]" cdvirtualenv assertSame "$VIRTUAL_ENV" "$(pwd)" deactivate rmvirtualenv "deleteme" assertSame "$WORKON_HOME" "$(pwd)" assertFalse "[ -d $WORKON_HOME/deleteme ]" } test_rm_aliased () { mkvirtualenv "deleteme" >/dev/null 2>&1 deactivate alias rm='rm -i' rmvirtualenv "deleteme" unalias rm } test_no_such_env () { assertFalse "[ -d $WORKON_HOME/deleteme ]" assertTrue "rmvirtualenv deleteme" } test_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" rmvirtualenv should_not_be_created >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" WORKON_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_run_hook.sh0000755000101700007650000000415512172545354023645 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo rm -f "$WORKON_HOME/initialize" rm -f "$WORKON_HOME/prermvirtualenv" rm -f "$TMPDIR/catch_output" } test_virtualenvwrapper_run_hook() { echo "echo run >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize" chmod +x "$WORKON_HOME/initialize" virtualenvwrapper_run_hook "initialize" output=$(cat "$TMPDIR/catch_output") expected="run" assertSame "$expected" "$output" } test_virtualenvwrapper_run_hook_alternate_dir() { mkdir "$WORKON_HOME/hooks" echo "echo WORKON_HOME >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize" echo "echo WORKON_HOME/hooks >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/hooks/initialize" chmod +x "$WORKON_HOME/initialize" chmod +x "$WORKON_HOME/hooks/initialize" VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME/hooks" virtualenvwrapper_run_hook "initialize" output=$(cat "$TMPDIR/catch_output") expected="WORKON_HOME/hooks" assertSame "$expected" "$output" VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME" } test_virtualenvwrapper_source_hook_permissions() { echo "echo run >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize" chmod -x "$WORKON_HOME/initialize" virtualenvwrapper_run_hook "initialize" output=$(cat "$TMPDIR/catch_output") expected="run" assertSame "$expected" "$output" } test_virtualenvwrapper_run_hook_permissions() { echo "#!/bin/sh" > "$WORKON_HOME/prermvirtualenv" echo "echo run $@ >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/prermvirtualenv" chmod 0444 "$WORKON_HOME/prermvirtualenv" touch "$TMPDIR/catch_output" error=$(virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo" 2>&1 | grep "could not run" | cut -f2- -d'[') output=$(cat "$TMPDIR/catch_output") expected="" assertSame "$expected" "$output" assertSame "Errno 13] Permission denied" "$error" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_support.sh0000755000101700007650000000112512172544441023523 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_get_python_version () { expected="$($VIRTUAL_ENV/bin/python -c 'import sys; sys.stdout.write("%s.%s\n" % sys.version_info[:2])')" echo "Expecting: $expected" vers=$(virtualenvwrapper_get_python_version) echo "Got : $vers" assertSame "$expected" "$vers" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_tempfile.sh0000755000101700007650000000437612172546411023626 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" #export HOOK_VERBOSE_OPTION=-v oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" echo $PYTHONPATH } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } test_tempfile () { filename=$(virtualenvwrapper_tempfile hook) assertTrue "Filename is empty" "[ ! -z \"$filename\" ]" assertTrue "File doesn't exist" "[ -f \"$filename\" ]" rm -f $filename comparable_tmpdir=$(echo $TMPDIR | sed 's|/$||') comparable_dirname=$(dirname $filename | sed 's|/$||') assertSame "Temporary directory \"$TMPDIR\" and path not the same for $filename" "$comparable_tmpdir" "$comparable_dirname" assertTrue "virtualenvwrapper-hook not in filename." "echo $filename | grep virtualenvwrapper-hook" } test_bad_mktemp() { # All of the following bogus mktemp programs should cause # virtualenvwrapper_tempfile to return non-zero status mktemp_nonzero() { return 1; } mktemp_empty_string() { return 0; } mktemp_missing_executable() { /foo/bar/baz/qux 2>/dev/null; } # returns status 127 mktemp_missing_result() { echo /foo/bar/baz/qux; } for mktemp_func in mktemp_nonzero mktemp_empty_string \ mktemp_missing_executable mktemp_missing_result do virtualenvwrapper_mktemp() { $mktemp_func "$@"; } filename=$(virtualenvwrapper_tempfile hook 2>/dev/null) assertSame "($mktemp_func) Unexpected exit code $?" "1" "$?" done # Restore the "real" definition of the replaceable function virtualenvwrapper_mktemp() { command mktemp "$@"; } } test_no_such_tmpdir () { old_tmpdir="$TMPDIR" export TMPDIR="$TMPDIR/does-not-exist" virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1 RC=$? assertSame "Unexpected exit code $RC" "1" "$RC" TMPDIR="$old_tmpdir" } test_tmpdir_not_writable () { old_tmpdir="$TMPDIR" export TMPDIR="$TMPDIR/cannot-write" mkdir "$TMPDIR" chmod ugo-w "$TMPDIR" virtualenvwrapper_run_hook "initialize" >/dev/null 2>&1 RC=$? assertSame "Unexpected exit code $RC" "1" "$RC" chmod ugo+w "$TMPDIR" rmdir "$TMPDIR" TMPDIR="$old_tmpdir" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_toggleglobalsitepackages.sh0000755000101700007650000000237712172544447027055 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo } tearDown () { deactivate >/dev/null 2>&1 } test_toggleglobalsitepackages () { mkvirtualenv --no-site-packages "test1" ngsp_file=$(dirname "`virtualenvwrapper_get_site_packages_dir`")/no-global-site-packages.txt assertTrue "$ngsp_file does not exist 1" "[ -f \"$ngsp_file\" ]" toggleglobalsitepackages -q assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]" toggleglobalsitepackages -q assertTrue "$ngsp_file does not exist 2" "[ -f \"$ngsp_file\" ]" } test_toggleglobalsitepackages_quiet () { mkvirtualenv --no-site-packages "test2" assertEquals "Command output is not correct" "Enabled global site-packages" "`toggleglobalsitepackages`" assertEquals "Command output is not correct" "Disabled global site-packages" "`toggleglobalsitepackages`" assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`" assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_wipeenv.sh0000755000101700007650000000225212172544454023472 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" setUp () { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" echo } tearDown() { if type deactivate >/dev/null 2>&1 then deactivate fi rm -rf "$WORKON_HOME" } test_wipeenv () { mkvirtualenv "wipetest" >/dev/null 2>&1 (cd tests/testpackage && python setup.py install) >/dev/null 2>&1 before="$(pip freeze)" assertTrue "testpackage not installed" "pip freeze | grep testpackage" wipeenv >/dev/null 2>&1 after="$(pip freeze)" assertFalse "testpackage still installed" "pip freeze | grep testpackage" } test_empty_env () { mkvirtualenv "wipetest" >/dev/null 2>&1 before="$(pip freeze)" assertFalse "testpackage still installed" "pip freeze | grep testpackage" wipeenv >/dev/null 2>&1 after="$(pip freeze)" assertFalse "testpackage still installed" "pip freeze | grep testpackage" } test_not_active_env () { mkvirtualenv "wipetest" >/dev/null 2>&1 deactivate assertFalse "wipenv did not report an error" "wipeenv >/dev/null 2>&1" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/test_workon.sh0000755000101700007650000000642312172545365023342 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- test_dir=$(cd $(dirname $0) && pwd) source "$test_dir/setup.sh" oneTimeSetUp() { rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" source "$test_dir/../virtualenvwrapper.sh" mkvirtualenv "env1" >/dev/null 2>&1 mkvirtualenv "env2" >/dev/null 2>&1 deactivate >/dev/null 2>&1 } oneTimeTearDown() { rm -rf "$WORKON_HOME" } setUp () { echo rm -f "$TMPDIR/catch_output" } tearDown () { deactivate >/dev/null 2>&1 } test_workon () { workon env1 assertTrue virtualenvwrapper_verify_active_environment assertSame "env1" $(basename "$VIRTUAL_ENV") } test_workon_activate_hooks () { for t in pre post do echo "#!/bin/sh" > "$WORKON_HOME/${t}activate" echo "echo GLOBAL ${t}activate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/${t}activate" chmod +x "$WORKON_HOME/${t}activate" echo "#!/bin/sh" > "$WORKON_HOME/env2/bin/${t}activate" echo "echo ENV ${t}activate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/env1/bin/${t}activate" chmod +x "$WORKON_HOME/env1/bin/${t}activate" done rm -f "$TMPDIR/catch_output" touch "$TMPDIR/catch_output" workon env1 output=$(cat "$TMPDIR/catch_output") expected="GLOBAL preactivate ENV preactivate GLOBAL postactivate ENV postactivate" assertSame "$expected" "$output" for t in pre post do rm -f "$WORKON_HOME/env1/bin/${t}activate" rm -f "$WORKON_HOME/${t}activate" done } test_virtualenvwrapper_show_workon_options () { mkdir "$WORKON_HOME/not_env" (cd "$WORKON_HOME"; ln -s env1 link_env) envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ') assertSame "env1 env2 link_env " "$envs" rmdir "$WORKON_HOME/not_env" rm -f "$WORKON_HOME/link_env" } test_virtualenvwrapper_show_workon_options_grep_options () { mkdir "$WORKON_HOME/not_env" (cd "$WORKON_HOME"; ln -s env1 link_env) export GREP_OPTIONS="--count" envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ') unset GREP_OPTIONS assertSame "env1 env2 link_env " "$envs" rmdir "$WORKON_HOME/not_env" rm -f "$WORKON_HOME/link_env" } test_virtualenvwrapper_show_workon_options_chpwd () { # https://bitbucket.org/dhellmann/virtualenvwrapper/issue/153 function chpwd { local SEARCH=' ' local REPLACE='%20' local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}" printf '\e]7;%s\a' "$PWD_URL" echo -n "\033]0;${HOST//.*}:$USER\007" } mkdir "$WORKON_HOME/not_env" envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ') assertSame "env1 env2 " "$envs" rmdir "$WORKON_HOME/not_env" rm -f "$WORKON_HOME/link_env" } test_virtualenvwrapper_show_workon_options_no_envs () { old_home="$WORKON_HOME" export WORKON_HOME=${TMPDIR:-/tmp}/$$ envs=$(virtualenvwrapper_show_workon_options 2>/dev/null | tr '\n' ' ') assertSame "" "$envs" export WORKON_HOME="$old_home" } test_no_workon_home () { old_home="$WORKON_HOME" export WORKON_HOME="$WORKON_HOME/not_there" workon should_not_be_created >"$old_home/output" 2>&1 output=$(cat "$old_home/output") assertTrue "Did not see expected message" "echo $output | grep 'does not exist'" WORKON_HOME="$old_home" } . "$test_dir/shunit2" virtualenvwrapper-4.1.1/tests/testpackage/0000755000101700007650000000000012173006006022674 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/tests/testpackage/setup.py0000644000101700007650000000051512143435522024415 0ustar dhellmanndhellmann00000000000000# Test package for virtualenvwrapper tests from setuptools import setup version = '1.0' setup( name='testpackage', version=version, description="Fake package", author="Ingeniweb", author_email='thomas.desvenain@gmail.com', url='http://pypi.python.org/pypi/testpackage/', scripts=['testscript.py'] ) virtualenvwrapper-4.1.1/tests/testpackage/testscript.py0000644000101700007650000000010212143435522025451 0ustar dhellmanndhellmann00000000000000#!/usr/bin/env python """ A test script """ print "Hello world" virtualenvwrapper-4.1.1/tests/testtemplate/0000755000101700007650000000000012173006006023114 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/tests/testtemplate/distribute_setup.py0000644000101700007650000003566512143435522027111 0ustar dhellmanndhellmann00000000000000#!python """Bootstrap distribute installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from distribute_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools, set a download mirror, or use an alternate download directory, you can do so by supplying the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ import os import sys import time import fnmatch import tempfile import tarfile from distutils import log try: from site import USER_SITE except ImportError: USER_SITE = None try: import subprocess def _python_cmd(*args): args = (sys.executable,) + args return subprocess.call(args) == 0 except ImportError: # will be used for python 2.3 def _python_cmd(*args): args = (sys.executable,) + args # quoting arguments if windows if sys.platform == 'win32': def quote(arg): if ' ' in arg: return '"%s"' % arg return arg args = [quote(arg) for arg in args] return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 DEFAULT_VERSION = "0.6.10" DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" SETUPTOOLS_FAKED_VERSION = "0.6c11" SETUPTOOLS_PKG_INFO = """\ Metadata-Version: 1.0 Name: setuptools Version: %s Summary: xxxx Home-page: xxx Author: xxx Author-email: xxx License: xxx Description: xxx """ % SETUPTOOLS_FAKED_VERSION def _install(tarball): # extracting the tarball tmpdir = tempfile.mkdtemp() log.warn('Extracting in %s', tmpdir) old_wd = os.getcwd() try: os.chdir(tmpdir) tar = tarfile.open(tarball) _extractall(tar) tar.close() # going in the directory subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) os.chdir(subdir) log.warn('Now working in %s', subdir) # installing log.warn('Installing Distribute') if not _python_cmd('setup.py', 'install'): log.warn('Something went wrong during the installation.') log.warn('See the error message above.') finally: os.chdir(old_wd) def _build_egg(egg, tarball, to_dir): # extracting the tarball tmpdir = tempfile.mkdtemp() log.warn('Extracting in %s', tmpdir) old_wd = os.getcwd() try: os.chdir(tmpdir) tar = tarfile.open(tarball) _extractall(tar) tar.close() # going in the directory subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) os.chdir(subdir) log.warn('Now working in %s', subdir) # building an egg log.warn('Building a Distribute egg in %s', to_dir) _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) finally: os.chdir(old_wd) # returning the result log.warn(egg) if not os.path.exists(egg): raise IOError('Could not build the egg.') def _do_download(version, download_base, to_dir, download_delay): egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' % (version, sys.version_info[0], sys.version_info[1])) if not os.path.exists(egg): tarball = download_setuptools(version, download_base, to_dir, download_delay) _build_egg(egg, tarball, to_dir) sys.path.insert(0, egg) import setuptools setuptools.bootstrap_install_from = egg def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15, no_fake=True): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: try: import pkg_resources if not hasattr(pkg_resources, '_distribute'): if not no_fake: _fake_setuptools() raise ImportError except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("distribute>="+version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of distribute (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U distribute'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) finally: if not no_fake: _create_fake_setuptools_pkg_info(to_dir) def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15): """Download distribute from a specified location and return its filename `version` should be a valid distribute version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the number of seconds to pause before an actual download attempt. """ # making sure we use the absolute path to_dir = os.path.abspath(to_dir) try: from urllib.request import urlopen except ImportError: from urllib2 import urlopen tgz_name = "distribute-%s.tar.gz" % version url = download_base + tgz_name saveto = os.path.join(to_dir, tgz_name) src = dst = None if not os.path.exists(saveto): # Avoid repeated downloads try: log.warn("Downloading %s", url) src = urlopen(url) # Read/write all in one block, so we don't create a corrupt file # if the download is interrupted. data = src.read() dst = open(saveto, "wb") dst.write(data) finally: if src: src.close() if dst: dst.close() return os.path.realpath(saveto) def _patch_file(path, content): """Will backup the file then patch it""" existing_content = open(path).read() if existing_content == content: # already patched log.warn('Already patched.') return False log.warn('Patching...') _rename_path(path) f = open(path, 'w') try: f.write(content) finally: f.close() return True def _same_content(path, content): return open(path).read() == content def _no_sandbox(function): def __no_sandbox(*args, **kw): try: from setuptools.sandbox import DirectorySandbox def violation(*args): pass DirectorySandbox._old = DirectorySandbox._violation DirectorySandbox._violation = violation patched = True except ImportError: patched = False try: return function(*args, **kw) finally: if patched: DirectorySandbox._violation = DirectorySandbox._old del DirectorySandbox._old return __no_sandbox @_no_sandbox def _rename_path(path): new_name = path + '.OLD.%s' % time.time() log.warn('Renaming %s into %s', path, new_name) os.rename(path, new_name) return new_name def _remove_flat_installation(placeholder): if not os.path.isdir(placeholder): log.warn('Unkown installation at %s', placeholder) return False found = False for file in os.listdir(placeholder): if fnmatch.fnmatch(file, 'setuptools*.egg-info'): found = True break if not found: log.warn('Could not locate setuptools*.egg-info') return log.warn('Removing elements out of the way...') pkg_info = os.path.join(placeholder, file) if os.path.isdir(pkg_info): patched = _patch_egg_dir(pkg_info) else: patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) if not patched: log.warn('%s already patched.', pkg_info) return False # now let's move the files out of the way for element in ('setuptools', 'pkg_resources.py', 'site.py'): element = os.path.join(placeholder, element) if os.path.exists(element): _rename_path(element) else: log.warn('Could not find the %s element of the ' 'Setuptools distribution', element) return True def _after_install(dist): log.warn('After install bootstrap.') placeholder = dist.get_command_obj('install').install_purelib _create_fake_setuptools_pkg_info(placeholder) @_no_sandbox def _create_fake_setuptools_pkg_info(placeholder): if not placeholder or not os.path.exists(placeholder): log.warn('Could not find the install location') return pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) setuptools_file = 'setuptools-%s-py%s.egg-info' % \ (SETUPTOOLS_FAKED_VERSION, pyver) pkg_info = os.path.join(placeholder, setuptools_file) if os.path.exists(pkg_info): log.warn('%s already exists', pkg_info) return log.warn('Creating %s', pkg_info) f = open(pkg_info, 'w') try: f.write(SETUPTOOLS_PKG_INFO) finally: f.close() pth_file = os.path.join(placeholder, 'setuptools.pth') log.warn('Creating %s', pth_file) f = open(pth_file, 'w') try: f.write(os.path.join(os.curdir, setuptools_file)) finally: f.close() def _patch_egg_dir(path): # let's check if it's already patched pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') if os.path.exists(pkg_info): if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): log.warn('%s already patched.', pkg_info) return False _rename_path(path) os.mkdir(path) os.mkdir(os.path.join(path, 'EGG-INFO')) pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') f = open(pkg_info, 'w') try: f.write(SETUPTOOLS_PKG_INFO) finally: f.close() return True def _before_install(): log.warn('Before install bootstrap.') _fake_setuptools() def _under_prefix(location): if 'install' not in sys.argv: return True args = sys.argv[sys.argv.index('install')+1:] for index, arg in enumerate(args): for option in ('--root', '--prefix'): if arg.startswith('%s=' % option): top_dir = arg.split('root=')[-1] return location.startswith(top_dir) elif arg == option: if len(args) > index: top_dir = args[index+1] return location.startswith(top_dir) elif option == '--user' and USER_SITE is not None: return location.startswith(USER_SITE) return True def _fake_setuptools(): log.warn('Scanning installed packages') try: import pkg_resources except ImportError: # we're cool log.warn('Setuptools or Distribute does not seem to be installed.') return ws = pkg_resources.working_set try: setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', replacement=False)) except TypeError: # old distribute API setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) if setuptools_dist is None: log.warn('No setuptools distribution found') return # detecting if it was already faked setuptools_location = setuptools_dist.location log.warn('Setuptools installation detected at %s', setuptools_location) # if --root or --preix was provided, and if # setuptools is not located in them, we don't patch it if not _under_prefix(setuptools_location): log.warn('Not patching, --root or --prefix is installing Distribute' ' in another location') return # let's see if its an egg if not setuptools_location.endswith('.egg'): log.warn('Non-egg installation') res = _remove_flat_installation(setuptools_location) if not res: return else: log.warn('Egg installation') pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') if (os.path.exists(pkg_info) and _same_content(pkg_info, SETUPTOOLS_PKG_INFO)): log.warn('Already patched.') return log.warn('Patching...') # let's create a fake egg replacing setuptools one res = _patch_egg_dir(setuptools_location) if not res: return log.warn('Patched done.') _relaunch() def _relaunch(): log.warn('Relaunching...') # we have to relaunch the process args = [sys.executable] + sys.argv sys.exit(subprocess.call(args)) def _extractall(self, path=".", members=None): """Extract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getmembers(). """ import copy import operator from tarfile import ExtractError directories = [] if members is None: members = self for tarinfo in members: if tarinfo.isdir(): # Extract directories with a safe mode. directories.append(tarinfo) tarinfo = copy.copy(tarinfo) tarinfo.mode = 448 # decimal for oct 0700 self.extract(tarinfo, path) # Reverse sort directories. if sys.version_info < (2, 4): def sorter(dir1, dir2): return cmp(dir1.name, dir2.name) directories.sort(sorter) directories.reverse() else: directories.sort(key=operator.attrgetter('name'), reverse=True) # Set correct owner, mtime and filemode on directories. for tarinfo in directories: dirpath = os.path.join(path, tarinfo.name) try: self.chown(tarinfo, dirpath) self.utime(tarinfo, dirpath) self.chmod(tarinfo, dirpath) except ExtractError: e = sys.exc_info()[1] if self.errorlevel > 1: raise else: self._dbg(1, "tarfile: %s" % e) def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" tarball = download_setuptools() _install(tarball) if __name__ == '__main__': main(sys.argv[1:]) virtualenvwrapper-4.1.1/tests/testtemplate/mytemplates/0000755000101700007650000000000012173006006025460 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/tests/testtemplate/mytemplates/__init__.py0000644000101700007650000000000012143435522027565 0ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/tests/testtemplate/mytemplates/main.py0000644000101700007650000000114112143435522026761 0ustar dhellmanndhellmann00000000000000#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """virtualenvwrapper.project plugin for tests """ import logging import os log = logging.getLogger(__name__) def template(args): """Creates a test file containing the args passed to us """ print('Running test template with args %r' % args) project, project_dir = args filename = os.path.join(project_dir, 'TEST_FILE') print('Writing to %s' % filename) output = open(filename, 'w') try: output.write('\n'.join(args)) finally: output.close() return virtualenvwrapper-4.1.1/tests/testtemplate/setup.py0000644000101700007650000001177412143435522024646 0ustar dhellmanndhellmann00000000000000#!/usr/bin/env python PROJECT = 'testtemplate' VERSION = '1.0' # Bootstrap installation of Distribute import distribute_setup distribute_setup.use_setuptools() from setuptools import setup, find_packages from distutils.util import convert_path from fnmatch import fnmatchcase import os import sys ################################################################################ # find_package_data is an Ian Bicking creation. # Provided as an attribute, so you can append to these instead # of replicating them: standard_exclude = ('*.py', '*.pyc', '*~', '.*', '*.bak', '*.swp*') standard_exclude_directories = ('.*', 'CVS', '_darcs', './build', './dist', 'EGG-INFO', '*.egg-info') def find_package_data( where='.', package='', exclude=standard_exclude, exclude_directories=standard_exclude_directories, only_in_packages=True, show_ignored=False): """ Return a dictionary suitable for use in ``package_data`` in a distutils ``setup.py`` file. The dictionary looks like:: {'package': [files]} Where ``files`` is a list of all the files in that package that don't match anything in ``exclude``. If ``only_in_packages`` is true, then top-level directories that are not packages won't be included (but directories under packages will). Directories matching any pattern in ``exclude_directories`` will be ignored; by default directories with leading ``.``, ``CVS``, and ``_darcs`` will be ignored. If ``show_ignored`` is true, then all the files that aren't included in package data are shown on stderr (for debugging purposes). Note patterns use wildcards, or can be exact paths (including leading ``./``), and all searching is case-insensitive. This function is by Ian Bicking. """ out = {} stack = [(convert_path(where), '', package, only_in_packages)] while stack: where, prefix, package, only_in_packages = stack.pop(0) for name in os.listdir(where): fn = os.path.join(where, name) if os.path.isdir(fn): bad_name = False for pattern in exclude_directories: if (fnmatchcase(name, pattern) or fn.lower() == pattern.lower()): bad_name = True if show_ignored: print >> sys.stderr, ( "Directory %s ignored by pattern %s" % (fn, pattern)) break if bad_name: continue if os.path.isfile(os.path.join(fn, '__init__.py')): if not package: new_package = name else: new_package = package + '.' + name stack.append((fn, '', new_package, False)) else: stack.append((fn, prefix + name + '/', package, only_in_packages)) elif package or not only_in_packages: # is a file bad_name = False for pattern in exclude: if (fnmatchcase(name, pattern) or fn.lower() == pattern.lower()): bad_name = True if show_ignored: print >> sys.stderr, ( "File %s ignored by pattern %s" % (fn, pattern)) break if bad_name: continue out.setdefault(package, []).append(prefix+name) return out ################################################################################ setup( name = PROJECT, version = VERSION, description = 'template for testing mkproject', author = 'Doug Hellmann', author_email = 'doug.hellmann@gmail.com', url = 'http://www.doughellmann.com/projects/virtualenvwrapper/', classifiers = [ 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python', 'Intended Audience :: Developers', 'Environment :: Console', ], platforms = ['Any'], provides=['testtemplate', ], requires=['virtualenv', 'virtualenvwrapper (>=2.9)', ], packages = find_packages(), include_package_data = True, # Scan the input for package information # to grab any data files (text, images, etc.) # associated with sub-packages. package_data = find_package_data('mytemplates', package='mytemplates', only_in_packages=False, ), entry_points = { 'virtualenvwrapper.project.template': [ 'test = mytemplates.main:template', ], }, zip_safe=False, ) virtualenvwrapper-4.1.1/tox.ini0000644000101700007650000000220412172523213020553 0ustar dhellmanndhellmann00000000000000[tox] envlist = py27,py26,py32,py33,zsh,ksh,style [testenv] commands = bash ./tests/run_tests {envdir} [] deps = distribute virtualenv virtualenv-clone stevedore setenv = TOXIC = true [testenv:style] deps = flake8 commands = flake8 virtualenvwrapper docs/source/conf.py [testenv:py27] setenv = SHELL = /bin/bash commands = bash ./tests/run_tests {envdir} [] # Not sure why the basepython setting is needed, but on my system if # it isn't included then the python version picked up for 2.6 is # actually 2.7. # # IF THIS CAUSES YOU A PROBLEM COMMENT IT OUT BEFORE RUNNING THE TESTS. # [testenv:py26] basepython=/usr/bin/python2.6 setenv = SHELL = /bin/bash commands = bash ./tests/run_tests {envdir} [] [testenv:py32] setenv = SHELL = /bin/bash commands = bash ./tests/run_tests {envdir} [] [testenv:py33] setenv = SHELL = /bin/bash commands = bash ./tests/run_tests {envdir} [] [testenv:zsh] basepython=python2.7 setenv = SHELL = /bin/zsh commands = zsh -o shwordsplit ./tests/run_tests {envdir} [] [testenv:ksh] basepython=python2.7 setenv = SHELL = /bin/ksh commands = ksh ./tests/run_tests {envdir} [] virtualenvwrapper-4.1.1/virtualenvwrapper/0000755000101700007650000000000012173006006023037 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/virtualenvwrapper/__init__.py0000644000101700007650000000013112143435522025151 0ustar dhellmanndhellmann00000000000000"""virtualenvwrapper module """ __import__('pkg_resources').declare_namespace(__name__) virtualenvwrapper-4.1.1/virtualenvwrapper/hook_loader.py0000644000101700007650000001410412143435522025705 0ustar dhellmanndhellmann00000000000000# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """Load hooks for virtualenvwrapper. """ import inspect import itertools import logging import logging.handlers import optparse import os import sys from stevedore import ExtensionManager from stevedore import NamedExtensionManager LOG_FORMAT = '%(asctime)s %(levelname)s %(name)s %(message)s' class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler): """Taken from http://stackoverflow.com/questions/1407474 """ def _open(self): prevumask = os.umask(0o002) rtv = logging.handlers.RotatingFileHandler._open(self) os.umask(prevumask) return rtv def main(): parser = optparse.OptionParser( usage='usage: %prog [options] []', prog='virtualenvwrapper.hook_loader', description='Manage hooks for virtualenvwrapper', ) parser.add_option( '-S', '--script', help='Runs "hook" then "_source", writing the ' + 'result to ', dest='script_filename', default=None, ) parser.add_option( '-s', '--source', help='Print the shell commands to be run in the current shell', action='store_true', dest='sourcing', default=False, ) parser.add_option( '-l', '--list', help='Print a list of the plugins available for the given hook', action='store_true', default=False, dest='listing', ) parser.add_option( '-v', '--verbose', help='Show more information on the console', action='store_const', const=2, default=1, dest='verbose_level', ) parser.add_option( '-q', '--quiet', help='Show less information on the console', action='store_const', const=0, dest='verbose_level', ) parser.add_option( '-n', '--name', help='Only run the hook from the named plugin', action='append', dest='names', default=[], ) parser.disable_interspersed_args() # stop when on option without an '-' options, args = parser.parse_args() root_logger = logging.getLogger('') # Set up logging to a file logfile = os.environ.get('VIRTUALENVWRAPPER_LOG_FILE') if logfile: root_logger.setLevel(logging.DEBUG) file_handler = GroupWriteRotatingFileHandler( logfile, maxBytes=10240, backupCount=1, ) formatter = logging.Formatter(LOG_FORMAT) file_handler.setFormatter(formatter) root_logger.addHandler(file_handler) # Send higher-level messages to the console, too console = logging.StreamHandler() console_level = [logging.WARNING, logging.INFO, logging.DEBUG, ][options.verbose_level] console.setLevel(console_level) formatter = logging.Formatter('%(name)s %(message)s') console.setFormatter(formatter) root_logger.addHandler(console) #logging.getLogger(__name__).debug('cli args %s', args) # Determine which hook we're running if not args: if options.listing: list_hooks() return 0 else: parser.error('Please specify the hook to run') hook = args[0] if options.sourcing and options.script_filename: parser.error('--source and --script are mutually exclusive.') if options.sourcing: hook += '_source' log = logging.getLogger(__name__) log.debug('Running %s hooks', hook) run_hooks(hook, options, args) if options.script_filename: log.debug('Saving sourcable %s hooks to %s', hook, options.script_filename) options.sourcing = True output = open(options.script_filename, "w") try: output.write('# %s\n' % hook) # output.write('echo %s\n' % hook) # output.write('set -x\n') run_hooks(hook + '_source', options, args, output) finally: output.close() return 0 def run_hooks(hook, options, args, output=None): if output is None: output = sys.stdout namespace = 'virtualenvwrapper.%s' % hook if options.names: hook_mgr = NamedExtensionManager(namespace, options.names) else: hook_mgr = ExtensionManager(namespace) if options.listing: def show(ext): output.write(' %-10s -- %s\n' % (ext.name, inspect.getdoc(ext.plugin) or '')) try: hook_mgr.map(show) except RuntimeError: # no templates output.write(' No templates installed.\n') elif options.sourcing: def get_source(ext, args): # Show the shell commands so they can # be run in the calling shell. contents = (ext.plugin(args) or '').strip() if contents: output.write('# %s\n' % ext.name) output.write(contents) output.write("\n") try: hook_mgr.map(get_source, args[1:]) except RuntimeError: pass else: # Just run the plugin ourselves def invoke(ext, args): ext.plugin(args) try: hook_mgr.map(invoke, args[1:]) except RuntimeError: pass def list_hooks(output=None): if output is None: output = sys.stdout static_names = [ 'initialize', 'get_env_details', 'project.pre_mkproject', 'project.post_mkproject', 'project.template', ] pre_post_hooks = ( '_'.join(h) for h in itertools.product(['pre', 'post'], ['mkvirtualenv', 'rmvirtualenv', 'activate', 'deactivate', 'cpvirtualenv', ]) ) for hook in itertools.chain(static_names, pre_post_hooks): output.write(hook + '\n') if __name__ == '__main__': main() virtualenvwrapper-4.1.1/virtualenvwrapper/project.py0000644000101700007650000000251512143435522025070 0ustar dhellmanndhellmann00000000000000# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """virtualenvwrapper.project """ import logging import os from virtualenvwrapper.user_scripts import make_hook, run_global log = logging.getLogger(__name__) GLOBAL_HOOKS = [ # mkproject ("premkproject", "This hook is run after a new project is created " "and before it is activated."), ("postmkproject", "This hook is run after a new project is activated."), # rmproject ("prermproject", "This hook is run before a project is deleted."), ("postrmproject", "This hook is run after a project is deleted."), ] def initialize(args): """Set up user hooks """ for filename, comment in GLOBAL_HOOKS: make_hook(os.path.join('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment) return def pre_mkproject(args): log.debug('pre_mkproject %s', str(args)) run_global('premkproject', *args) return def post_mkproject_source(args): return """ # # Run user-provided scripts # [ -f "$WORKON_HOME/postmkproject" ] && source "$WORKON_HOME/postmkproject" """ def post_activate_source(args): return """ # # Change to the project directory # [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && \ cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")" """ virtualenvwrapper-4.1.1/virtualenvwrapper/user_scripts.py0000644000101700007650000001660512172610155026153 0ustar dhellmanndhellmann00000000000000# encoding: utf-8 # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # """Plugin to handle hooks in user-defined scripts. """ import logging import os import re import stat import subprocess import sys log = logging.getLogger(__name__) # Are we running under msys if sys.platform == 'win32' and \ os.environ.get('OS') == 'Windows_NT' and \ os.environ.get('MSYSTEM') == 'MINGW32': is_msys = True script_folder = 'Scripts' else: is_msys = False script_folder = 'bin' def run_script(script_path, *args): """Execute a script in a subshell. """ if os.path.exists(script_path): cmd = [script_path] + list(args) if is_msys: cmd = [get_path(os.environ['MSYS_HOME'], 'bin', 'sh.exe')] + cmd log.debug('running %s', str(cmd)) try: subprocess.call(cmd) except OSError: _, msg, _ = sys.exc_info() log.error('could not run "%s": %s', script_path, str(msg)) #log.debug('Returned %s', return_code) return def run_global(script_name, *args): """Run a script from $VIRTUALENVWRAPPER_HOOK_DIR. """ script_path = get_path('$VIRTUALENVWRAPPER_HOOK_DIR', script_name) run_script(script_path, *args) return PERMISSIONS = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH GLOBAL_HOOKS = [ # initialize ("initialize", "This hook is run during the startup phase " "when loading virtualenvwrapper.sh."), # mkvirtualenv ("premkvirtualenv", "This hook is run after a new virtualenv is created " "and before it is activated."), ("postmkvirtualenv", "This hook is run after a new virtualenv is activated."), # rmvirtualenv ("prermvirtualenv", "This hook is run before a virtualenv is deleted."), ("postrmvirtualenv", "This hook is run after a virtualenv is deleted."), # deactivate ("predeactivate", "This hook is run before every virtualenv is deactivated."), ("postdeactivate", "This hook is run after every virtualenv is deactivated."), # activate ("preactivate", "This hook is run before every virtualenv is activated."), ("postactivate", "This hook is run after every virtualenv is activated."), # get_env_details ("get_env_details", "This hook is run when the list of virtualenvs is printed " "so each name can include details."), ] LOCAL_HOOKS = [ # deactivate ("predeactivate", "This hook is run before this virtualenv is deactivated."), ("postdeactivate", "This hook is run after this virtualenv is deactivated."), # activate ("preactivate", "This hook is run before this virtualenv is activated."), ("postactivate", "This hook is run after this virtualenv is activated."), # get_env_details ("get_env_details", "This hook is run when the list of virtualenvs is printed " "in 'long' mode so each name can include details."), ] def make_hook(filename, comment): """Create a hook script. :param filename: The name of the file to write. :param comment: The comment to insert into the file. """ filename = get_path(filename) if not os.path.exists(filename): log.info('creating %s', filename) f = open(filename, 'w') try: f.write("#!%(shell)s\n# %(comment)s\n\n" % { 'comment': comment, 'shell': os.environ.get('SHELL', '/bin/sh'), }) finally: f.close() os.chmod(filename, PERMISSIONS) return # HOOKS def initialize(args): for filename, comment in GLOBAL_HOOKS: make_hook(get_path('$VIRTUALENVWRAPPER_HOOK_DIR', filename), comment) return def initialize_source(args): return """ # # Run user-provided scripts # [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" """ def pre_mkvirtualenv(args): log.debug('pre_mkvirtualenv %s', str(args)) envname = args[0] for filename, comment in LOCAL_HOOKS: make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment) run_global('premkvirtualenv', *args) return def post_mkvirtualenv_source(args): return """ # # Run user-provided scripts # [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" """ def pre_cpvirtualenv(args): log.debug('pre_cpvirtualenv %s', str(args)) envname = args[0] for filename, comment in LOCAL_HOOKS: make_hook(get_path('$WORKON_HOME', envname, script_folder, filename), comment) run_global('precpvirtualenv', *args) return def post_cpvirtualenv_source(args): return """ # # Run user-provided scripts # [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" """ def pre_rmvirtualenv(args): log.debug('pre_rmvirtualenv') run_global('prermvirtualenv', *args) return def post_rmvirtualenv(args): log.debug('post_rmvirtualenv') run_global('postrmvirtualenv', *args) return def pre_activate(args): log.debug('pre_activate') run_global('preactivate', *args) script_path = get_path('$WORKON_HOME', args[0], script_folder, 'preactivate') run_script(script_path, *args) return def post_activate_source(args): log.debug('post_activate') return """ # # Run user-provided scripts # [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && \ source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" """ def pre_deactivate_source(args): log.debug('pre_deactivate') return """ # # Run user-provided scripts # [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && \ source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" """ def post_deactivate_source(args): log.debug('post_deactivate') return """ # # Run user-provided scripts # VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV="$WORKON_HOME/%(env_name)s" [ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && \ source "$WORKON_HOME/%(env_name)s/bin/postdeactivate" [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && \ source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV """ % {'env_name': args[0]} def get_env_details(args): log.debug('get_env_details') run_global('get_env_details', *args) script_path = get_path('$WORKON_HOME', args[0], script_folder, 'get_env_details') run_script(script_path, *args) return def get_path(*args): ''' Get a full path from args. Path separator is determined according to the os and the shell and allow to use is_msys. Variables and user are expanded during the process. ''' path = os.path.expanduser(os.path.expandvars(os.path.join(*args))) if is_msys: # MSYS accept unix or Win32 and sometimes # it drives to mixed style paths if re.match(r'^/[a-zA-Z](/|^)', path): # msys path could starts with '/c/'-form drive letter path = ''.join((path[1], ':', path[2:])) path = path.replace('/', os.sep) return os.path.abspath(path) virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/0000755000101700007650000000000012173006006024531 5ustar dhellmanndhellmann00000000000000virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/dependency_links.txt0000644000101700007650000000000112173006004030575 0ustar dhellmanndhellmann00000000000000 virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/entry_points.txt0000644000101700007650000000317712173006004030035 0ustar dhellmanndhellmann00000000000000[virtualenvwrapper.initialize_source] user_scripts = virtualenvwrapper.user_scripts:initialize_source [virtualenvwrapper.pre_deactivate_source] user_scripts = virtualenvwrapper.user_scripts:pre_deactivate_source [virtualenvwrapper.post_activate_source] user_scripts = virtualenvwrapper.user_scripts:post_activate_source project = virtualenvwrapper.project:post_activate_source [virtualenvwrapper.initialize] user_scripts = virtualenvwrapper.user_scripts:initialize project = virtualenvwrapper.project:initialize [virtualenvwrapper.project.pre_mkproject] project = virtualenvwrapper.project:pre_mkproject [virtualenvwrapper.pre_mkvirtualenv] user_scripts = virtualenvwrapper.user_scripts:pre_mkvirtualenv [virtualenvwrapper.pre_rmvirtualenv] user_scripts = virtualenvwrapper.user_scripts:pre_rmvirtualenv [virtualenvwrapper.post_mkvirtualenv_source] user_scripts = virtualenvwrapper.user_scripts:post_mkvirtualenv_source [virtualenvwrapper.project.post_mkproject_source] project = virtualenvwrapper.project:post_mkproject_source [virtualenvwrapper.pre_cpvirtualenv] user_scripts = virtualenvwrapper.user_scripts:pre_cpvirtualenv [virtualenvwrapper.post_deactivate_source] user_scripts = virtualenvwrapper.user_scripts:post_deactivate_source [virtualenvwrapper.get_env_details] user_scripts = virtualenvwrapper.user_scripts:get_env_details [virtualenvwrapper.pre_activate] user_scripts = virtualenvwrapper.user_scripts:pre_activate [virtualenvwrapper.post_rmvirtualenv] user_scripts = virtualenvwrapper.user_scripts:post_rmvirtualenv [virtualenvwrapper.post_cpvirtualenv_source] user_scripts = virtualenvwrapper.user_scripts:post_cpvirtualenv_source virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/namespace_packages.txt0000644000101700007650000000002212173006004031054 0ustar dhellmanndhellmann00000000000000virtualenvwrapper virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/PKG-INFO0000644000101700007650000001342512173006004025631 0ustar dhellmanndhellmann00000000000000Metadata-Version: 1.1 Name: virtualenvwrapper Version: 4.1.1 Summary: Enhancements to virtualenv Home-page: http://virtualenvwrapper.readthedocs.org/ Author: Doug Hellmann Author-email: doug.hellmann@gmail.com License: MIT Description: .. -*- mode: rst -*- ################# virtualenvwrapper ################# virtualenvwrapper is a set of extensions to Ian Bicking's `virtualenv `_ tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies. **Warning:** The 4.x release includes some potentially incompatible changes for extensions from 3.x. The python modules for extensions are now *always* run with ``PWD=$WORKON_HOME`` (previously the value of PWD varied depending on the hook). The *shell* portion of any hook (anything sourced by the user's shell when the hook is run) is still run in the same place as before. ======== Features ======== 1. Organizes all of your virtual environments in one place. 2. Wrappers for creating, copying and deleting environments, including user-configurable hooks. 3. Use a single command to switch between environments. 4. Tab completion for commands that take a virtual environment as argument. 5. User-configurable hooks for all operations. 6. Plugin system for more creating sharable extensions. Rich Leland has created a short `screencast `__ showing off the features of virtualenvwrapper. ============ Installation ============ See the `project documentation `__ for installation and setup instructions. Supported Shells ================ virtualenvwrapper is a set of shell *functions* defined in Bourne shell compatible syntax. It is tested under ``bash``, ``ksh``, and ``zsh``. It may work with other shells, so if you find that it does work with a shell not listed here please let me know. If you can modify it to work with another shell, without completely rewriting it, send a pull request through the bitbucket project page. If you write a clone to work with an incompatible shell, let me know and I will link to it from this page. Python Versions =============== virtualenvwrapper is tested under Python 2.6 - 3.3. ======= Support ======= Join the `virtualenvwrapper Google Group `__ to discuss issues and features. Report bugs via the `bug tracker on BitBucket `__. Shell Aliases ============= Since virtualenvwrapper is largely a shell script, it uses shell commands for a lot of its actions. If your environment makes heavy use of shell aliases or other customizations, you may encounter issues. Before reporting bugs in the bug tracker, please test *without* your aliases enabled. If you can identify the alias causing the problem, that will help make virtualenvwrapper more robust. ========== Change Log ========== The `release history`_ is part of the project documentation. .. _release history: http://www.doughellmann.com/docs/virtualenvwrapper/history.html ======= License ======= Copyright Doug Hellmann, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Doug Hellmann not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Keywords: virtualenv Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Intended Audience :: Developers Classifier: Environment :: Console Provides: virtualenvwrapper Provides: virtualenvwrapper.user_scripts Provides: virtualenvwrapper.project virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/requires.txt0000644000101700007650000000004512173006004027126 0ustar dhellmanndhellmann00000000000000virtualenv virtualenv-clone stevedorevirtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/SOURCES.txt0000644000101700007650000000422612173006006026421 0ustar dhellmanndhellmann00000000000000.gitignore LICENSE MANIFEST.in Makefile README.es.rst README.ja.rst README.txt announce.rst requirements.txt setup.cfg setup.py tox.ini virtualenvwrapper.sh virtualenvwrapper_lazy.sh docs/Makefile docs/requirements.txt docs/spelling_wordlist.txt docs/source/command_ref.rst docs/source/conf.py docs/source/design.rst docs/source/developers.rst docs/source/extensions.rst docs/source/history.rst docs/source/hooks.rst docs/source/index.rst docs/source/install.rst docs/source/plugins.rst docs/source/projects.rst docs/source/scripts.rst docs/source/tips.rst tests/manual_test_install.sh tests/run_tests tests/setup.sh tests/shunit2 tests/test.sh tests/test_add2virtualenv.sh tests/test_allvirtualenv.sh tests/test_cd.sh tests/test_cp.sh tests/test_cpvirtualenv.sh tests/test_deactivate.sh tests/test_derive_workon_home.sh tests/test_dir_stack.sh tests/test_expandpath.sh tests/test_hook_dir.sh tests/test_lazy.sh tests/test_lazy_extending.sh tests/test_lazy_loaded.sh tests/test_lazy_run.sh tests/test_log_file.sh tests/test_ls.sh tests/test_lsvirtualenv.sh tests/test_mktmpenv.sh tests/test_mkvirtualenv.sh tests/test_mkvirtualenv_associate.sh tests/test_mkvirtualenv_install.sh tests/test_mkvirtualenv_requirements.sh tests/test_project.sh tests/test_project_activate.sh tests/test_project_cd.sh tests/test_project_mk.sh tests/test_project_templates.sh tests/test_rmvirtualenv.sh tests/test_run_hook.sh tests/test_support.sh tests/test_tempfile.sh tests/test_toggleglobalsitepackages.sh tests/test_wipeenv.sh tests/test_workon.sh tests/testpackage/setup.py tests/testpackage/testscript.py tests/testtemplate/distribute_setup.py tests/testtemplate/setup.py tests/testtemplate/mytemplates/__init__.py tests/testtemplate/mytemplates/main.py virtualenvwrapper/__init__.py virtualenvwrapper/hook_loader.py virtualenvwrapper/project.py virtualenvwrapper/user_scripts.py virtualenvwrapper.egg-info/PKG-INFO virtualenvwrapper.egg-info/SOURCES.txt virtualenvwrapper.egg-info/dependency_links.txt virtualenvwrapper.egg-info/entry_points.txt virtualenvwrapper.egg-info/namespace_packages.txt virtualenvwrapper.egg-info/requires.txt virtualenvwrapper.egg-info/top_level.txt virtualenvwrapper.egg-info/zip-safevirtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/top_level.txt0000644000101700007650000000002212173006004027253 0ustar dhellmanndhellmann00000000000000virtualenvwrapper virtualenvwrapper-4.1.1/virtualenvwrapper.egg-info/zip-safe0000644000101700007650000000000112173003757026173 0ustar dhellmanndhellmann00000000000000 virtualenvwrapper-4.1.1/virtualenvwrapper.sh0000644000101700007650000010515312171354533023411 0ustar dhellmanndhellmann00000000000000# -*- mode: shell-script -*- # # Shell functions to act as wrapper for Ian Bicking's virtualenv # (http://pypi.python.org/pypi/virtualenv) # # # Copyright Doug Hellmann, All Rights Reserved # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and that # both that copyright notice and this permission notice appear in # supporting documentation, and that the name of Doug Hellmann not be used # in advertising or publicity pertaining to distribution of the software # without specific, written prior permission. # # DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO # EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # # # Project home page: http://www.doughellmann.com/projects/virtualenvwrapper/ # # # Setup: # # 1. Create a directory to hold the virtual environments. # (mkdir $HOME/.virtualenvs). # 2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs" # to your .bashrc. # 3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh" # to your .bashrc. # 4. Run: source ~/.bashrc # 5. Run: workon # 6. A list of environments, empty, is printed. # 7. Run: mkvirtualenv temp # 8. Run: workon # 9. This time, the "temp" environment is included. # 10. Run: workon temp # 11. The virtual environment is activated. # # Locate the global Python where virtualenvwrapper is installed. if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then VIRTUALENVWRAPPER_PYTHON="$(command \which python)" fi # Set the name of the virtualenv app to use. if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ] then VIRTUALENVWRAPPER_VIRTUALENV="virtualenv" fi # Set the name of the virtualenv-clone app to use. if [ "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" = "" ] then VIRTUALENVWRAPPER_VIRTUALENV_CLONE="virtualenv-clone" fi # Define script folder depending on the platorm (Win32/Unix) VIRTUALENVWRAPPER_ENV_BIN_DIR="bin" if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ] then # Only assign this for msys, cygwin use standard Unix paths # and its own python installation VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts" fi # Let the user override the name of the file that holds the project # directory name. if [ "$VIRTUALENVWRAPPER_PROJECT_FILENAME" = "" ] then export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project" fi # Portable shell scripting is hard, let's go shopping. # # People insist on aliasing commands like 'cd', either with a real # alias or even a shell function. Under bash and zsh, "builtin" forces # the use of a command that is part of the shell itself instead of an # alias, function, or external command, while "command" does something # similar but allows external commands. Under ksh "builtin" registers # a new command from a shared library, but "command" will pick up # existing builtin commands. We need to use a builtin for cd because # we are trying to change the state of the current shell, so we use # "builtin" for bash and zsh but "command" under ksh. function virtualenvwrapper_cd { if [ -n "$BASH" ] then builtin \cd "$@" elif [ -n "$ZSH_VERSION" ] then builtin \cd "$@" else command \cd "$@" fi } function virtualenvwrapper_expandpath { if [ "$1" = "" ]; then return 1 else "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')" return 0 fi } function virtualenvwrapper_absolutepath { if [ "$1" = "" ]; then return 1 else "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.abspath(\"$1\")+'\n')" return 0 fi } function virtualenvwrapper_derive_workon_home { typeset workon_home_dir="$WORKON_HOME" # Make sure there is a default value for WORKON_HOME. # You can override this setting in your .bashrc. if [ "$workon_home_dir" = "" ] then workon_home_dir="$HOME/.virtualenvs" fi # If the path is relative, prefix it with $HOME # (note: for compatibility) if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \grep '^[^/~]' > /dev/null) then workon_home_dir="$HOME/$WORKON_HOME" fi # Only call on Python to fix the path if it looks like the # path might contain stuff to expand. # (it might be possible to do this in shell, but I don't know a # cross-shell-safe way of doing it -wolever) if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \egrep '([\$~]|//)' >/dev/null) then # This will normalize the path by: # - Removing extra slashes (e.g., when TMPDIR ends in a slash) # - Expanding variables (e.g., $foo) # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur) workon_home_dir="$(virtualenvwrapper_expandpath "$workon_home_dir")" fi echo "$workon_home_dir" return 0 } # Check if the WORKON_HOME directory exists, # create it if it does not # seperate from creating the files in it because this used to just error # and maybe other things rely on the dir existing before that happens. function virtualenvwrapper_verify_workon_home { RC=0 if [ ! -d "$WORKON_HOME/" ] then if [ "$1" != "-q" ] then echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2 fi mkdir -p "$WORKON_HOME" RC=$? fi return $RC } #HOOK_VERBOSE_OPTION="-q" # Function to wrap mktemp so tests can replace it for error condition # testing. function virtualenvwrapper_mktemp { command \mktemp "$@" } # Expects 1 argument, the suffix for the new file. function virtualenvwrapper_tempfile { # Note: the 'X's must come last typeset suffix=${1:-hook} typeset file file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)" if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ] then echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2 return 1 fi echo $file return 0 } # Run the hooks function virtualenvwrapper_run_hook { typeset hook_script typeset result hook_script="$(virtualenvwrapper_tempfile ${1}-hook)" || return 1 # Use a subshell to run the python interpreter with hook_loader so # we can change the working directory. This avoids having the # Python 3 interpreter decide that its "prefix" is the virtualenv # if we happen to be inside the virtualenv when we start. ( \ cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' \ $HOOK_VERBOSE_OPTION --script "$hook_script" "$@" \ ) result=$? if [ $result -eq 0 ] then if [ ! -f "$hook_script" ] then echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2 command \rm -f "$hook_script" return 2 fi # cat "$hook_script" source "$hook_script" elif [ "${1}" = "initialize" ] then cat - 1>&2 <&2 return 1 fi if [ ! -e "$exe_path" ] then echo "ERROR: Found $1 in path as \"$exe_path\" but that does not exist" >&2 return 1 fi return 0 } # Verify that virtualenv is installed and visible function virtualenvwrapper_verify_virtualenv { virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV } function virtualenvwrapper_verify_virtualenv_clone { virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV_CLONE } # Verify that the requested environment exists function virtualenvwrapper_verify_workon_environment { typeset env_name="$1" if [ ! -d "$WORKON_HOME/$env_name" ] then echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." >&2 return 1 fi return 0 } # Verify that the active environment exists function virtualenvwrapper_verify_active_environment { if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ] then echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2 return 1 fi return 0 } # Help text for mkvirtualenv function virtualenvwrapper_mkvirtualenv_help { echo "Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name" echo echo " -a project_path" echo echo " Provide a full path to a project directory to associate with" echo " the new environment." echo echo " -i package" echo echo " Install a package after the environment is created." echo " This option may be repeated." echo echo " -r requirements_file" echo echo " Provide a pip requirements file to install a base set of packages" echo " into the new environment." echo; echo 'virtualenv help:'; echo; "$VIRTUALENVWRAPPER_VIRTUALENV" $@; } # Create a new environment, in the WORKON_HOME. # # Usage: mkvirtualenv [options] ENVNAME # (where the options are passed directly to virtualenv) # function mkvirtualenv { typeset -a in_args typeset -a out_args typeset -i i typeset tst typeset a typeset envname typeset requirements typeset packages typeset interpreter in_args=( "$@" ) if [ -n "$ZSH_VERSION" ] then i=1 tst="-le" else i=0 tst="-lt" fi while [ $i $tst $# ] do a="${in_args[$i]}" # echo "arg $i : $a" case "$a" in -a) i=$(( $i + 1 )); project="${in_args[$i]}";; -h|--help) virtualenvwrapper_mkvirtualenv_help $a; return;; -i) i=$(( $i + 1 )); packages="$packages ${in_args[$i]}";; -p|--python*) if echo "$a" | grep -q "=" then interpreter="$(echo "$a" | cut -f2 -d=)" else i=$(( $i + 1 )) interpreter="${in_args[$i]}" fi; interpreter="$(virtualenvwrapper_absolutepath "$interpreter")";; -r) i=$(( $i + 1 )); requirements="${in_args[$i]}"; requirements="$(virtualenvwrapper_expandpath "$requirements")";; *) if [ ${#out_args} -gt 0 ] then out_args=( "${out_args[@]-}" "$a" ) else out_args=( "$a" ) fi;; esac i=$(( $i + 1 )) done if [ ! -z $interpreter ] then out_args=( "--python=$interpreter" ${out_args[@]} ) fi; set -- "${out_args[@]}" eval "envname=\$$#" virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_virtualenv || return 1 ( [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT virtualenvwrapper_cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" && [ -d "$WORKON_HOME/$envname" ] && \ virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname" ) typeset RC=$? [ $RC -ne 0 ] && return $RC # If they passed a help option or got an error from virtualenv, # the environment won't exist. Use that to tell whether # we should switch to the environment and run the hook. [ ! -d "$WORKON_HOME/$envname" ] && return 0 # If they gave us a project directory, set it up now # so the activate hooks can find it. if [ ! -z "$project" ] then setvirtualenvproject "$WORKON_HOME/$envname" "$project" fi # Now activate the new environment workon "$envname" if [ ! -z "$requirements" ] then pip install -r "$requirements" fi for a in $packages do pip install $a done virtualenvwrapper_run_hook "post_mkvirtualenv" } # Remove an environment, in the WORKON_HOME. function rmvirtualenv { virtualenvwrapper_verify_workon_home || return 1 if [ ${#@} = 0 ] then echo "Please specify an enviroment." >&2 return 1 fi # support to remove several environments typeset env_name for env_name in $@ do echo "Removing $env_name..." typeset env_dir="$WORKON_HOME/$env_name" if [ "$VIRTUAL_ENV" = "$env_dir" ] then echo "ERROR: You cannot remove the active environment ('$env_name')." >&2 echo "Either switch to another environment, or run 'deactivate'." >&2 return 1 fi # Move out of the current directory to one known to be # safe, in case we are inside the environment somewhere. typeset prior_dir="$(pwd)" virtualenvwrapper_cd "$WORKON_HOME" virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name" command \rm -rf "$env_dir" virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name" # If the directory we used to be in still exists, move back to it. if [ -d "$prior_dir" ] then virtualenvwrapper_cd "$prior_dir" fi done } # List the available environments. function virtualenvwrapper_show_workon_options { virtualenvwrapper_verify_workon_home || return 1 # NOTE: DO NOT use ls or cd here because colorized versions spew control # characters into the output list. # echo seems a little faster than find, even with -depth 3. # # 1. Look for environments by finding the activate scripts. # Use a subshell so we can suppress the message printed # by zsh if the glob pattern fails to match any files. # 2. Strip the WORKON_HOME prefix from each name. # 3. Strip the bindir/activate script suffix. # 4. Format the output to show one name on a line. # 5. Eliminate any lines with * on them because that means there # were no envs. (cd "$WORKON_HOME" && echo */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate) 2>/dev/null \ | command \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate||g" \ | command \fmt -w 1 \ | (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null } function _lsvirtualenv_usage { echo "lsvirtualenv [-blh]" echo " -b -- brief mode" echo " -l -- long mode" echo " -h -- this help message" } # List virtual environments # # Usage: lsvirtualenv [-l] function lsvirtualenv { typeset long_mode=true if command -v "getopts" &> /dev/null then # Use getopts when possible OPTIND=1 while getopts ":blh" opt "$@" do case "$opt" in l) long_mode=true;; b) long_mode=false;; h) _lsvirtualenv_usage; return 1;; ?) echo "Invalid option: -$OPTARG" >&2; _lsvirtualenv_usage; return 1;; esac done else # fallback on getopt for other shell typeset -a args args=($(getopt blh "$@")) if [ $? != 0 ] then _lsvirtualenv_usage return 1 fi for opt in $args do case "$opt" in -l) long_mode=true;; -b) long_mode=false;; -h) _lsvirtualenv_usage; return 1;; esac done fi if $long_mode then allvirtualenv showvirtualenv "$env_name" else virtualenvwrapper_show_workon_options fi } # Show details of a virtualenv # # Usage: showvirtualenv [env] function showvirtualenv { typeset env_name="$1" if [ -z "$env_name" ] then if [ -z "$VIRTUAL_ENV" ] then echo "showvirtualenv [env]" return 1 fi env_name=$(basename "$VIRTUAL_ENV") fi virtualenvwrapper_run_hook "get_env_details" "$env_name" echo } # Show help for workon function virtualenvwrapper_workon_help { echo "Usage: workon env_name" echo "" echo " Deactivate any currently activated virtualenv" echo " and activate the named environment, triggering" echo " any hooks in the process." echo "" echo " workon" echo "" echo " Print a list of available environments." echo " (See also lsvirtualenv -b)" echo "" echo " workon (-h|--help)" echo "" echo " Show this help message." echo "" } # List or change working virtual environments # # Usage: workon [environment_name] # function workon { in_args=( "$@" ) if [ -n "$ZSH_VERSION" ] then i=1 tst="-le" else i=0 tst="-lt" fi while [ $i $tst $# ] do a="${in_args[$i]}" case "$a" in -h|--help) virtualenvwrapper_workon_help; return 0;; esac i=$(( $i + 1 )) done typeset env_name="$1" if [ "$env_name" = "" ] then lsvirtualenv -b return 1 fi virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_workon_environment $env_name || return 1 activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" if [ ! -f "$activate" ] then echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2 return 1 fi # Deactivate any current environment "destructively" # before switching so we use our override function, # if it exists. type deactivate >/dev/null 2>&1 if [ $? -eq 0 ] then deactivate unset -f deactivate >/dev/null 2>&1 fi virtualenvwrapper_run_hook "pre_activate" "$env_name" source "$activate" # Save the deactivate function from virtualenv under a different name virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'` eval "$virtualenvwrapper_original_deactivate" unset -f deactivate >/dev/null 2>&1 # Replace the deactivate() function with a wrapper. eval 'deactivate () { typeset env_postdeactivate_hook typeset old_env # Call the local hook before the global so we can undo # any settings made by the local postactivate first. virtualenvwrapper_run_hook "pre_deactivate" env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate" old_env=$(basename "$VIRTUAL_ENV") # Call the original function. virtualenv_deactivate $1 virtualenvwrapper_run_hook "post_deactivate" "$old_env" if [ ! "$1" = "nondestructive" ] then # Remove this function unset -f virtualenv_deactivate >/dev/null 2>&1 unset -f deactivate >/dev/null 2>&1 fi }' virtualenvwrapper_run_hook "post_activate" return 0 } # Prints the Python version string for the current interpreter. function virtualenvwrapper_get_python_version { # Uses the Python from the virtualenv rather than # VIRTUALENVWRAPPER_PYTHON because we're trying to determine the # version installed there so we can build up the path to the # site-packages directory. "$VIRTUAL_ENV/bin/python" -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d. } # Prints the path to the site-packages directory for the current environment. function virtualenvwrapper_get_site_packages_dir { "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())" } # Path management for packages outside of the virtual env. # Based on a contribution from James Bennett and Jannis Leidel. # # add2virtualenv directory1 directory2 ... # # Adds the specified directories to the Python path for the # currently-active virtualenv. This will be done by placing the # directory names in a path file named # "virtualenv_path_extensions.pth" inside the virtualenv's # site-packages directory; if this file does not exist, it will be # created first. function add2virtualenv { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 site_packages="`virtualenvwrapper_get_site_packages_dir`" if [ ! -d "${site_packages}" ] then echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2 return 1 fi # Prefix with _ to ensure we are loaded as early as possible, # and at least before easy_install.pth. path_file="$site_packages/_virtualenv_path_extensions.pth" if [ "$*" = "" ] then echo "Usage: add2virtualenv dir [dir ...]" if [ -f "$path_file" ] then echo echo "Existing paths:" cat "$path_file" | grep -v "^import" fi return 1 fi remove=0 if [ "$1" = "-d" ] then remove=1 shift fi if [ ! -f "$path_file" ] then echo "import sys; sys.__plen = len(sys.path)" > "$path_file" || return 1 echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file" || return 1 fi for pydir in "$@" do absolute_path="$(virtualenvwrapper_absolutepath "$pydir")" if [ "$absolute_path" != "$pydir" ] then echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2 fi if [ $remove -eq 1 ] then sed -i.tmp "\:^$absolute_path$: d" "$path_file" else sed -i.tmp '1 a\ '"$absolute_path"' ' "$path_file" fi rm -f "${path_file}.tmp" done return 0 } # Does a ``cd`` to the site-packages directory of the currently-active # virtualenv. function cdsitepackages { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 typeset site_packages="`virtualenvwrapper_get_site_packages_dir`" virtualenvwrapper_cd "$site_packages"/$1 } # Does a ``cd`` to the root of the currently-active virtualenv. function cdvirtualenv { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 virtualenvwrapper_cd $VIRTUAL_ENV/$1 } # Shows the content of the site-packages directory of the currently-active # virtualenv function lssitepackages { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 typeset site_packages="`virtualenvwrapper_get_site_packages_dir`" ls $@ "$site_packages" path_file="$site_packages/_virtualenv_path_extensions.pth" if [ -f "$path_file" ] then echo echo "_virtualenv_path_extensions.pth:" cat "$path_file" fi } # Toggles the currently-active virtualenv between having and not having # access to the global site-packages. function toggleglobalsitepackages { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" if [ -f $no_global_site_packages_file ]; then rm $no_global_site_packages_file [ "$1" = "-q" ] || echo "Enabled global site-packages" else touch $no_global_site_packages_file [ "$1" = "-q" ] || echo "Disabled global site-packages" fi } # Duplicate the named virtualenv to make a new one. function cpvirtualenv { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_virtualenv_clone || return 1 typeset src_name="$1" typeset trg_name="$2" typeset src typeset trg # without a source there is nothing to do if [ "$src_name" = "" ]; then echo "Please provide a valid virtualenv to copy." return 1 else # see if its already in workon if [ ! -e "$WORKON_HOME/$src_name" ]; then # so its a virtualenv we are importing # make sure we have a full path # and get the name src="$(virtualenvwrapper_expandpath "$src_name")" # final verification if [ ! -e "$src" ]; then echo "Please provide a valid virtualenv to copy." return 1 fi src_name="$(basename "$src")" else src="$WORKON_HOME/$src_name" fi fi if [ "$trg_name" = "" ]; then # target not given, assume # same as source trg="$WORKON_HOME/$src_name" trg_name="$src_name" else trg="$WORKON_HOME/$trg_name" fi trg="$(virtualenvwrapper_expandpath "$trg")" # validate trg does not already exist # catch copying virtualenv in workon home # to workon home if [ -e "$trg" ]; then echo "$trg_name virtualenv already exists." return 1 fi echo "Copying $src_name as $trg_name..." ( [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT virtualenvwrapper_cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" "$src" "$trg" [ -d "$trg" ] && virtualenvwrapper_run_hook "pre_cpvirtualenv" "$src" "$trg_name" && virtualenvwrapper_run_hook "pre_mkvirtualenv" "$trg_name" ) typeset RC=$? [ $RC -ne 0 ] && return $RC [ ! -d "$WORKON_HOME/$trg_name" ] && return 1 # Now activate the new environment workon "$trg_name" virtualenvwrapper_run_hook "post_mkvirtualenv" virtualenvwrapper_run_hook "post_cpvirtualenv" } # # virtualenvwrapper project functions # # Verify that the PROJECT_HOME directory exists function virtualenvwrapper_verify_project_home { if [ -z "$PROJECT_HOME" ] then echo "ERROR: Set the PROJECT_HOME shell variable to the name of the directory where projects should be created." >&2 return 1 fi if [ ! -d "$PROJECT_HOME" ] then [ "$1" != "-q" ] && echo "ERROR: Project directory '$PROJECT_HOME' does not exist. Create it or set PROJECT_HOME to an existing directory." >&2 return 1 fi return 0 } # Given a virtualenv directory and a project directory, # set the virtualenv up to be associated with the # project function setvirtualenvproject { typeset venv="$1" typeset prj="$2" if [ -z "$venv" ] then venv="$VIRTUAL_ENV" fi if [ -z "$prj" ] then prj="$(pwd)" fi echo "Setting project for $(basename $venv) to $prj" echo "$prj" > "$venv/$VIRTUALENVWRAPPER_PROJECT_FILENAME" } # Show help for mkproject function virtualenvwrapper_mkproject_help { echo "Usage: mkproject [-t template] [virtualenv options] project_name" echo "" echo "Multiple templates may be selected. They are applied in the order" echo "specified on the command line." echo; echo "mkvirtualenv help:" echo mkvirtualenv -h; echo echo "Available project templates:" echo "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' -l project.template } # Create a new project directory and its associated virtualenv. function mkproject { typeset -a in_args typeset -a out_args typeset -i i typeset tst typeset a typeset t typeset templates in_args=( "$@" ) if [ -n "$ZSH_VERSION" ] then i=1 tst="-le" else i=0 tst="-lt" fi while [ $i $tst $# ] do a="${in_args[$i]}" case "$a" in -h|--help) virtualenvwrapper_mkproject_help; return;; -t) i=$(( $i + 1 )); templates="$templates ${in_args[$i]}";; *) if [ ${#out_args} -gt 0 ] then out_args=( "${out_args[@]-}" "$a" ) else out_args=( "$a" ) fi;; esac i=$(( $i + 1 )) done set -- "${out_args[@]}" # echo "templates $templates" # echo "remainder $@" # return 0 eval "typeset envname=\$$#" virtualenvwrapper_verify_project_home || return 1 if [ -d "$PROJECT_HOME/$envname" ] then echo "Project $envname already exists." >&2 return 1 fi mkvirtualenv "$@" || return 1 cd "$PROJECT_HOME" virtualenvwrapper_run_hook "project.pre_mkproject" $envname echo "Creating $PROJECT_HOME/$envname" mkdir -p "$PROJECT_HOME/$envname" setvirtualenvproject "$VIRTUAL_ENV" "$PROJECT_HOME/$envname" cd "$PROJECT_HOME/$envname" for t in $templates do echo echo "Applying template $t" # For some reason zsh insists on prefixing the template # names with a space, so strip them out before passing # the value to the hook loader. virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" "$envname" "$PROJECT_HOME/$envname" done virtualenvwrapper_run_hook "project.post_mkproject" } # Change directory to the active project function cdproject { virtualenvwrapper_verify_workon_home || return 1 virtualenvwrapper_verify_active_environment || return 1 if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] then typeset project_dir="$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")" if [ ! -z "$project_dir" ] then cd "$project_dir" else echo "Project directory $project_dir does not exist" 1>&2 return 1 fi else echo "No project set in $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" 1>&2 return 1 fi return 0 } # # Temporary virtualenv # # Originally part of virtualenvwrapper.tmpenv plugin # function mktmpenv { typeset tmpenvname typeset RC # Generate a unique temporary name tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid,sys; sys.stdout.write(uuid.uuid4()+"\n")' 2>/dev/null) if [ -z "$tmpenvname" ] then # This python does not support uuid tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random,sys; sys.stdout.write(hex(random.getrandbits(64))[2:-1]+"\n")' 2>/dev/null) fi # Create the environment mkvirtualenv "$@" "$tmpenvname" RC=$? if [ $RC -ne 0 ] then return $RC fi # Change working directory cdvirtualenv # Create the tmpenv marker file echo "This is a temporary environment. It will be deleted when you run 'deactivate'." | tee "$VIRTUAL_ENV/README.tmpenv" # Update the postdeactivate script cat - >> "$VIRTUAL_ENV/bin/postdeactivate" < "$req_file" if [ -n "$(cat "$req_file")" ] then echo "Uninstalling packages:" cat "$req_file" echo pip uninstall -y $(cat "$req_file" | sed 's/>/=/g' | cut -f1 -d=) else echo "Nothing to remove." fi rm -f "$req_file" } # # Run a command in each virtualenv # function allvirtualenv { virtualenvwrapper_verify_workon_home || return 1 typeset d virtualenvwrapper_show_workon_options | while read d do [ ! -d "$WORKON_HOME/$d" ] && continue echo "$d" echo "$d" | sed 's/./=/g' # Activate the environment, but not with workon # because we don't want to trigger any hooks. (source "$WORKON_HOME/$d/bin/activate"; cd "$VIRTUAL_ENV"; $@) echo done } # # Invoke the initialization functions # virtualenvwrapper_initialize virtualenvwrapper-4.1.1/virtualenvwrapper_lazy.sh0000644000101700007650000000260412145750513024444 0ustar dhellmanndhellmann00000000000000#!/bin/sh # Alternative startup script for faster login times. export _VIRTUALENVWRAPPER_API="$_VIRTUALENVWRAPPER_API mkvirtualenv rmvirtualenv lsvirtualenv showvirtualenv workon add2virtualenv cdsitepackages cdvirtualenv lssitepackages toggleglobalsitepackages cpvirtualenv setvirtualenvproject mkproject cdproject mktmpenv" if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ] then export VIRTUALENVWRAPPER_SCRIPT="$(which virtualenvwrapper.sh)" fi if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ] then echo "ERROR: virtualenvwrapper_lazy.sh: Could not find virtualenvwrapper.sh" 1>&2 fi # Load the real implementation of the API from virtualenvwrapper.sh function virtualenvwrapper_load { source "$VIRTUALENVWRAPPER_SCRIPT" } # Set up "alias" functions based on the API definition. function virtualenvwrapper_setup_lazy_loader { typeset venvw_name for venvw_name in $(echo ${_VIRTUALENVWRAPPER_API}) do eval " function $venvw_name { virtualenvwrapper_load ${venvw_name} \"\$@\" } " done } # Set up completion functions to virtualenvwrapper_load function virtualenvwrapper_setup_lazy_completion { if [ -n "$BASH" ] ; then complete -o nospace -F virtualenvwrapper_load $(echo ${_VIRTUALENVWRAPPER_API}) elif [ -n "$ZSH_VERSION" ] ; then compctl -K virtualenvwrapper_load $(echo ${_VIRTUALENVWRAPPER_API}) fi } virtualenvwrapper_setup_lazy_loader virtualenvwrapper_setup_lazy_completion