[
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non:\n  push:\n    branches:\n      - master\n  pull_request:\n    branches:\n      - master\n  schedule:\n    - cron: '0 0 7 * *'  # run tests every month just to check for funny business if things are quiet\n\njobs:\n  test:\n    name: Test with ${{ matrix.emacs_version }}\n    runs-on: ubuntu-18.04\n    strategy:\n      matrix:\n        emacs_version: [emacs25, emacs26]\n    \n    steps:\n    - uses: actions/checkout@v1\n    - uses: actions/setup-python@v1\n      with:\n        python-version: '3.x'\n    - name: Install and setup preliminary tools\n      run: |\n        sudo add-apt-repository ppa:kelleyk/emacs\n        sudo apt update\n        sudo apt install -y ${{ matrix.emacs_version }}\n        pip install virtualenv\n        curl -fsSkL https://raw.github.com/cask/cask/master/go | python\n        export PATH=\"~/.cask/bin:$PATH\"\n        cask exec emacs --version\n    - name: Install emacs deps and run tests with cask\n      run: |\n        export PATH=\"~/.cask/bin:$PATH\"\n        cask install\n        cask exec ert-runner\n"
  },
  {
    "path": ".gitignore",
    "content": ".cask"
  },
  {
    "path": ".travis.yml",
    "content": "language: generic\nsudo: false\ndist: trusty\naddons:\n  apt:\n    packages:\n      - python-pip\nenv:\n  global:\n    - PATH=~/.evm/bin:~/.cask/bin:$PATH\n  matrix:\n    - EVM_EMACS=emacs-24.5-travis\n    - EVM_EMACS=emacs-25.1-travis\n    - EVM_EMACS=emacs-25.2-travis\n    - EVM_EMACS=emacs-25.3-travis\n    # - EVM_EMACS=emacs-git-snapshot-travis\nbefore_install:\n  - pip install -U --user virtualenv\n  - curl -fsSkL https://raw.github.com/rejeep/evm/master/go | bash\n  - evm config path /tmp\n  - evm install $EVM_EMACS\n  - evm use $EVM_EMACS\n  - hash -r\n  - curl -fsSkL https://raw.github.com/cask/cask/master/go | python\n  - cask exec emacs --version\n  - cask install\nscript:\n  - cask exec ert-runner\n"
  },
  {
    "path": "Cask",
    "content": "(source gnu)\n(source melpa)\n\n(package \"virtualenvwrapper\" \"20140315\" \"a featureful virtualenv tool for Emacs\")\n\n(depends-on \"s\" \"1.6.1\")\n(depends-on \"dash\" \"1.5.0\")\n\n(development\n (depends-on \"ert-runner\")\n (depends-on \"noflet\")\n (depends-on \"with-simulated-input\"))\n"
  },
  {
    "path": "LICENSE",
    "content": "\nCopyright (C) 2013 James J. Porter\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# virtualenvwrapper.el\n\n[![Travis Build Status](https://travis-ci.org/porterjamesj/virtualenvwrapper.el.svg?branch=master)](https://travis-ci.org/porterjamesj/virtualenvwrapper.el) \n[![Github Build Status](https://github.com/porterjamesj/virtualenvwrapper.el/workflows/CI/badge.svg)](https://github.com/porterjamesj/virtualenvwrapper.el/actions)\n\n[![MELPA](http://melpa.org/packages/virtualenvwrapper-badge.svg)](http://melpa.org/#/virtualenvwrapper)\n[![MELPA Stable](https://stable.melpa.org/packages/virtualenvwrapper-badge.svg)](https://stable.melpa.org/#/virtualenvwrapper)\n\nA featureful virtualenv tool for Emacs. Emulates\nmuch of the functionality of Doug Hellmann's\n[virtualenvwrapper](https://bitbucket.org/dhellmann/virtualenvwrapper/).\n\n## Features\n\n* Works with the new\n  [python.el](https://github.com/fgallina/python.el), which is the\n  default on Emacs 24.3 and up. Does not support the older python\n  modes.\n* Python shells, interactive shells, eshell, and any other subprocesses can\n  be made aware of your virtualenvs.\n* Implements a large subset of the functionality of virtualenvwrapper.\n\n## Basic Usage\n\n* Obviously make sure you have\n  [virtualenv](http://www.virtualenv.org/en/latest/) installed. You\n  don't actually need virtualenvwrapper.sh, this is a reimplementation\n  in Emacs lisp.\n* Install from MELPA (`M-x package-install virtualenvwrapper`),\n  or just put `virtualenvwrapper.el` on your load path somewhere.\n* Put\n\n  ```lisp\n  (require 'virtualenvwrapper)\n  (venv-initialize-interactive-shells) ;; if you want interactive shell support\n  (venv-initialize-eshell) ;; if you want eshell support\n  ;; note that setting `venv-location` is not necessary if you\n  ;; use the default location (`~/.virtualenvs`), or if the\n  ;; the environment variable `WORKON_HOME` points to the right place\n  (setq venv-location \"/path/to/your/virtualenvs/\")\n  ```\n  in your config somewhere.\n\n\n\n* Use `M-x venv-workon` to activate virtualenvs and `M-x\n  venv-deactivate` deactivate them.\n* If you have your virtualenvs spread around the filesystem rather\n  than in one directory, just set venv-location to be a list of\n  paths to each virtualenv. For example:\n\n  ```lisp\n  (setq venv-location '(\"/path/to/project1-env/\"\n                        \"/path/to/ptoject2-env/\"))\n  ```\n\n  Notice that the final directory of each path has a different name.\n  The mode uses this fact to disambiguate virtualenvs from each other,\n  so for now it is required.\n* You can also change easily the virtual environment location with\n  `M-x venv-set-location`. This is particularly useful when working with\n  tools such as [tox](https://testrun.org/tox/latest/) that generate virtual\n  environments dynamically.\n\n## What do activating and deactivating actually do?\n\nMany virtual environment support tools describe their functionality as\n\"it just works\" or \"it's so simple\". This is not descriptive enough to\nfigure out what's wrong when something inevitably breaks, so here I\nwill describe *exactly* what happens when you activate a virtualenv:\n\n1. `python-shell-virtualenv-path` is set to the virtualenv's directory\n   so that when you open a new python shell, it is aware of the\n   virtual environment's installed packages and modules.\n2. The virtualenv's `bin` directory is prepended to the `PATH`\n   environment variable so that when a process is launched from Emacs\n   it is aware of any executables installed in the virtualenv (such as\n   `nosetests`, `pep8`, etc.). This comes in handy because you can do\n   `M-! nosetests` to run your tests, for example.\n3. The `VIRTUAL_ENV` environment variable is set to the virtualenv's\n   directory so that any tools that depend on this variable function\n   correctly (one such tool is\n   [jedi](http://tkf.github.io/emacs-jedi/)).\n4. The virtualenv's `bin` directory is added to the `exec-path`, so that\n   Emacs itself can find the environment's installed executables. This is\n   useful, for example, if you want to have Emacs spawn a subprocess\n   running an executable installed in a virtualenv.\n5. [`gud`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Debuggers.html#Debuggers)\n   is configured to run pdb as `python -m pdb` rather than the default\n   `pdb`, which is necessary for virtualenvs to be detected.\n\nWhen you deactivate, all these things are undone. You can safely\nmodify your `PATH` and `exec-path` while a virtualenv is active and\nexpect the changes not to be destroyed by deactivating.\n\nThis covers everything except interactive shells, which are\ncovered in the next section.\n\n## Shells\n\nThis thing supports two types of interactive shells, the\n[eshell](https://www.gnu.org/software/emacs/manual/html_mono/eshell.html)\nand the\n[interactive subshell](https://www.gnu.org/software/emacs/manual/html_node/emacs/Interactive-Shell.html)\n(what you get when you do `M-x shell`).\n\n### Interactive shell\n\nSupport for interactive shell is turned on by calling\n`venv-initialize-interactive-shell`. After this is done, whenever you\ncall `shell`, the shell will start in the correct virtualenv. This\ndetects whether or not you have virtualenvwrapper.sh installed and does\nthe right thing in either case.  Note that changing the virtualenv in\nEmacs will not affect any running shells and vice-versa; they are\nindependent processes.\n\n#### WARNINGS\n\nThis feature is a pretty big hack and works by\n[advising](https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html)\nthe `shell` function. This works fine if you haven't otherwise tricked\nout or advised it, but if this is the case it may break. Please file\nan issue if you encounter any bugs with this functionality, I am\ninterested to see how robust it is.\n\n### Eshell\n\nsupport for eshell is turned on by calling `venv-initialize-eshell`.\nAfter doing this, any new eshells you launch will be in the correct\nvirtualenv and have access to installed executables, etc. The mode\nalso provides a variety of virtualenvwrapper commands that work\nidentically to their bash/zsh counterparts (described in detail\nbelow). Note that in contrast to how interactive shells work, Eshell\nshares an environment with Emacs, so if you activate or deactivate in\none, the other is affected as well. Note that this requires the\nvariable `eshell-modify-global-environment` to be set to true. Running\n`venv-initialize-eshell` causes this to occur. If this doesn't work for\nyou, open an issue! It's technically possible to separate the two, but\nit requires some hacking around with the different namespaces that I\nwon't bother to do unless someone really needs it.\n\n## Command Reference\n\nThe commands this mode provides are prefixed with `venv-`\nAll commands can be called interactively using `M-x`. All of these\ncomamnds have also been aliased without prefixes as eshell functions,\nso you can call them on the eshell just as you would in bash or zsh.\nFor example:\n\n```\neshell> workon myenv\neshell> deactivate\neshell> cpvirtualenv env copy\neshell> mkvirtualenv newenv\n```\n\nAll will do what would expect.\n\n#### `venv-workon`\n\nPrompts for the name of a virtualenv and activates it as described\nabove. Can also be called noninteractively as `(venv-workon \"name\")`.\n\nWhen called, it sets `gud-pdb-command-name` to `python -m pdb` so that\n`M-x pdb` can be used inside the virtual environment.\n\n#### `venv-deactivate`\n\nDeactivates your current virtualenv, undoing everything that `venv-workon`\ndid. This can also be called noninteractively as `(venv-deactivate)`.\n\nWhen called, it sets `gud-pdb-command-name` to its default value\n(usually `pdb`).\n\n#### `venv-mkvirtualenv`\n\nPrompt for a name and create a new virtualenv. If your virtualenvs are\nall kept in the same directory (i.e. `venv-location` is a string),\nthen the new virtualenv will be created in that directory. If you keep\nyour virtualenvs in different places (i.e. `venv-location` is a\nlist), then the new virtualenv will be created in the current default\ndirectory. Also callable noninteractively as `(venv-mkvirtualenv\n\"name\")`.\n\n#### `venv-mkvirtualenv-using`\n\nSupplying a prefix command (`C-u`) to `venv-mkvirtualenv` will prompt\nfor a Python interpreter to use. You can use this function to specify\nthe interpreter noninteractively.\n\n#### `venv-rmvirtualenv`\n\nPrompt for the name of a virutalenv and delete it. Also callable\nnoninteractively as `(venv-rmvirtualenv \"name\")`.\n\n#### `venv-lsvirtualenv`\n\nDisplay all available virtualenvs in a help buffer. Also callable\nnoninteractively as `(venv-list-virtualenvs)`.\n\n#### `venv-cdvirtualenv`\n\nChange the current default directory to the current virtualenv's\ndirectory. If called noninteractively, you can optionally provide an\nargument, which is interpreted as a subdirectory. For example, to go\nto the `bin` directory of the currently active virtualenv, call\n`(venv-cdvirtualenv \"bin\")`.\n\n#### `venv-cpvirtualenv`\n\nMakes a new virtualenv that is a copy of an existing one. Prompts for\nthe names of both. *WARNING* This comes with the same caveat as the\ncorresponding command in the original virtualenvwrapper, which is that\nsome packages hardcode their locations when being installed, so\ncreating new virtualenvs in this manner may cause them to break. Use\nwith caution.\n\n\n## Useful Macros\n\nThere is a `venv-with-virtualenv` macro, which takes the name of a\nvirtualenv and then any number of forms and executes those forms with\nthat virtualenv active, in that virtualenv's directory.  For example:\n\n```lisp\n(venv-with-virtualenv \"myenv\" (message default-directory))\n```\n\nWill message the path of `myenv`'s directory. There's also a\n`venv-all-virtualenv` macro, which takes a series of forms, activates\neach virtualenv in turn, moves to its directory, and executes the\ngiven forms.\n\nSince it's common to want to execute shell commands, there are\nconvenience macros, `venv-with-virtualenv-shell-command` and\n`venv-allvirtualenv-shell-command`, which take a string, interpreted\nas a shell command, and do exactly what you'd expect. So for example,\nyou can do `(venv-allvirtualenv-shell-command \"pip install pep8\")` to\ninstall `pep8` in all virtualenvs. `venv-allvirtualenv-shell-command`\ncan also be called interactively and will prompt for a command to run\nif so.\n\nThe eshell supports using this command just like in bash or zsh, so at\nan eshell prompt, you can just do:\n\n```\neshell> allvirtualenv pip install pep8\n```\n\nAnd it will do what you expect.\n\n\n## Extras\n\nThis mode doesn't screw with things you probably have customized\nyourself, such as your mode line, keybindings, mode-hooks, etc. in\norder to provide stuff like automatically turning on virtualenvs in\ncertain projects, show the virtualenv on the mode line, etc. Instead,\nyou can do all these things pretty easily using tools already provided\nby Emacs. How to do some of them are described below.\n\n### Keybindings\n\nThis mode doesn't provide any. I don't presume to know how you want\nyour keybindings, you can bind them to whatever you want! Go crazy!\n\n### Hooks\n\nVirtualenvwrapper lets you write shell scripts that run as hooks after\nyou take certain actions, such as creating or deleting a\nvirtualenv. This package provides Emacs\n[hooks](https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html),\nto achieve the same thing. The complete list of hooks is:\n\n```\nvenv-premkvirtualenv-hook\nvenv-postmkvirtualenv-hook\nvenv-prermvirtualenv-hook\nvenv-postrmvirtualenv-hook\nvenv-preactivate-hook\nvenv-postactivate-hook\nvenv-predeactivate-hook\nvenv-postdeactivate-hook\n```\n\neach of which is run when you would expect based on the name.\n\nFor example, to install commonly used packages when a new virtualenv is\ncreated you could modify the `venv-postmkvirtualenv-hook` as follows:\n\n```lisp\n(add-hook 'venv-postmkvirtualenv-hook\n          (lambda () (shell-command \"pip install nose flake8 jedi\")))\n```\n\n### Automatically activating a virtualenv in a particular project\n\nIt's also common to want to have a virtualenv automatically activated\nwhen you open a file in a certain project. This mode provides no\nspecial way to do this because once again Emacs has already done it in\nthe form of\n[per-directory local variables](https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html).\nIn order to have a virtualenv automatically activated when you open a\npython file in a particular project, you could put a `.dir-locals.el` in the\nproject's root directory with something like:\n\n```lisp\n((python-mode . ((eval . (venv-workon \"myproject-env\")))))\n```\n\n### Automatically activating a virtualenv when using projectile\n\nIf you're using [projectile](https://github.com/bbatsov/projectile)\nthere's an easier way to automatically activate a virtualenv when\nentering a project.\n\nYou just have to call `(venv-projectile-auto-workon)` after switching\nprojects, this can be achieved hooking the call to the action\n`projectile-switch-project-action` like this:\n\n```lisp\n(setq projectile-switch-project-action 'venv-projectile-auto-workon)\n```\n\nIf you relay on another use for this action, then just add a `lambda`\ninstead:\n\n```lisp\n(setq projectile-switch-project-action\n      '(lambda ()\n         (venv-projectile-auto-workon)\n         (projectile-find-file)))\n```\n\nAs long as a virtualenv is found in the `projectile-project-root` and\nwhose name is in the list `venv-dirlookup-names` it will be\nautomatically activated. By default, it's value is `'(\".venv\", \"venv\")'`,\nbut you can set if however you like to match your naming conventions:\n\n```lisp\n(setq venv-dirlookup-names '(\".venv\" \"pyenv\" \".virtual\"))\n```\n\nYou can add as many names you need, the first one found in the current\nproject will be activated.\n\n### Displaying the currently active virtualenv on the mode line\n\nThe name of the currently active virtualenv is stored in the variable\n`venv-current-name`. If you want to have it displayed on your custom\nmode line you can just add `(:exec (list venv-current-name)))`\nsomewhere in your `mode-line-format`. If you don't customize your mode\nline and just want to have the current virtualenv displayed, you can\ndo:\n\n```lisp\n(setq-default mode-line-format (cons '(:exec venv-current-name) mode-line-format))\n```\n\n### Eshell prompt customization\n\nYou also might want to have the name of your current virtualenv appear\non the eshell prompt. You can do this by a pretty similar mechanism,\njust include `venv-current-name` in your `eshell-prompt-function`\nsomewhere. Here is a simple example of a prompt that includes the\ncurrent virtualenv name followed by a dollar sign:\n\n```lisp\n(setq eshell-prompt-function\n    (lambda ()\n      (concat venv-current-name \" $ \")))\n```\n\nMake sure you also adjust your `eshell-prompt-regexp` if you do this.\n\nMore about customizing the eshell prompt\n[on the EmacsWiki](http://www.emacswiki.org/emacs/EshellPrompt).\n\n### Bugs / Comments / Contributions\n\nOpen an issue or a PR! I'm happy to pull in contributions or take\nsuggestions for improvements.\n\n### Hacking\n\nI use [Cask](http://cask.readthedocs.io/en/latest/) to manage dependencies and\n[ert-runner](https://github.com/rejeep/ert-runner.el) for testing. To\nget started:\n\n1. [install cask](http://cask.readthedocs.io/en/latest/guide/installation.html)\n2. Install dependacies with `cask install --dev`\n3. Verify that the tests pass with `cask exec ert-runner`\n\nThe tests are pretty rudimentary integration tests but they verify that\nall the basic functionality works.\n\nIf you're planning on submitting a PR, please make sure that the tests pass\nbefore you do so. Thanks!\n\n\n### License\n\nCopyright (C) 2013 James J. Porter\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "contrib/helm-virtualenvwrapper.el",
    "content": ";;; helm-virtualenvwrapper.el --- A helm-source for virtualenvwrapper.el\n\n;; Copyright (C) 2014 Javier Olaechea\n\n;;; Commentary:\n\n;; To start using define a python-local keybinding or a global one such as:\n;;\n;; (define-key python-mode-map (kbd \"C-c v\") 'helm-venv-workon)\n;; (global-set-key (kbd \"C-c v\") 'helm-venv-workon)\n;;\n;; Then C-c v away\n\n\n;;;###autoload\n(defun helm-venv-workon ()\n  \"Like venv-work, for helm.\"\n  (interactive)\n  (helm :sources '(helm-source-venv)))\n\n(defvar helm-source-venv\n  `((name . \"Virtual env completion\")\n    (candidates . ,(cl-loop\n                    for venv in (venv-get-candidates)\n                    collect (cons venv venv)))\n    (action . ((\"activate\" . venv-workon)))\n    (persistent-action . venv-workon)\n    (persistent-help . \"Activate the virtualenv.\")))\n"
  },
  {
    "path": "test/virtualenvwrapper-test.el",
    "content": ";; Rudimentary test suite for virtualenvwrapper.el\n\n(load (expand-file-name \"virtualenvwrapper.el\" default-directory))\n(require 's)\n(require 'noflet)\n(require 'with-simulated-input)\n\n;; unclear why this is required, we get `(void-function string-trim)'\n;; errors without, probably has something to do with byte-compiling\n(require 'subr-x)\n\n(setq venv-tmp-env \"emacs-venvwrapper-test\")\n\n(defmacro with-temp-location (&rest forms)\n  `(let ((venv-location temporary-file-directory))\n     (unwind-protect\n         (progn\n           ,@forms))))\n\n\n(defmacro with-temp-env (name &rest forms)\n  `(let ((venv-location temporary-file-directory))\n     (unwind-protect\n         (progn\n           (venv-mkvirtualenv ,name)\n           ,@forms)\n       (venv-rmvirtualenv ,name))))\n\n\n(defmacro with-temp-dir (&rest forms)\n  `(let ((temp-dir (file-name-as-directory (make-temp-file nil t))))\n     (unwind-protect\n         (progn\n           ,@forms)\n       (delete-directory temp-dir t))))\n\n\n(defun assert-venv-activated ()\n  \"Runs various assertions to check if a venv is activated.\"\n  ;; M-x pdb should ask to run \"python -m pdb\"\n  (should (equal gud-pdb-command-name \"python -m pdb\"))\n  ;; we store the name correctly\n  (should (s-contains? venv-tmp-env venv-current-name))\n  ;; assert that the current dir exists and is asbolute\n  (should (file-name-absolute-p venv-current-dir))\n  (should (file-directory-p venv-current-dir))\n  ;; we change the path for python mode\n  (should (s-contains? venv-tmp-env python-shell-virtualenv-path))\n  ;; we set PATH for shell and subprocesses\n  (should (s-contains? venv-tmp-env (getenv \"PATH\")))\n  ;; we set VIRTUAL_ENV for jedi and whoever else needs it\n  (should (s-contains? venv-tmp-env (getenv \"VIRTUAL_ENV\")))\n  ;; we add our dir to exec-path\n  (should (s-contains? venv-tmp-env (car exec-path))))\n\n(ert-deftest venv-mkvirtualenv-works ()\n  (with-temp-location\n   (venv-mkvirtualenv venv-tmp-env)\n   (should (equal venv-current-name venv-tmp-env))\n   (venv-deactivate)\n   (venv-rmvirtualenv venv-tmp-env)))\n\n(ert-deftest venv-rmvirtualenv-works ()\n  (let ((venv-location temporary-file-directory))\n    (venv-mkvirtualenv venv-tmp-env)\n    (venv-deactivate)\n    (venv-rmvirtualenv venv-tmp-env)\n    (should-error (venv-workon venv-tmp-env))))\n\n(ert-deftest venv-mkvirtualenv-select-default-interpreter ()\n  (with-temp-location\n   (let ((current-prefix-arg '(4)))\n     (with-simulated-input\n      \"RET\"\n      (venv-mkvirtualenv venv-tmp-env))\n     (should (equal venv-current-name venv-tmp-env))\n     (venv-deactivate)\n     (venv-rmvirtualenv venv-tmp-env))))\n\n(ert-deftest venv-mkvirtualenv-select-different-interpreter ()\n  (with-temp-location\n   (let ((current-prefix-arg '(4)))\n     (with-simulated-input\n         '((insert (executable-find \"python\")) \"RET\")\n       (venv-mkvirtualenv venv-tmp-env))\n     (should (equal venv-current-name venv-tmp-env))\n     (venv-deactivate)\n     (venv-rmvirtualenv venv-tmp-env))))\n\n(ert-deftest venv-mkvirtualenv-using-default-interpreter-works ()\n  (with-temp-location\n   (venv-mkvirtualenv-using nil venv-tmp-env)\n   (should (equal venv-current-name venv-tmp-env))\n   (venv-deactivate)\n   (venv-rmvirtualenv venv-tmp-env)))\n\n(ert-deftest venv-mkvirtualenv-using-different-interpreter-works ()\n  (with-temp-location\n   (venv-mkvirtualenv-using (executable-find \"python\") venv-tmp-env)\n   (should (equal venv-current-name venv-tmp-env))\n   (venv-deactivate)\n   (venv-rmvirtualenv venv-tmp-env)))\n\n(ert-deftest venv-mkvirtualenv-using-select-default-interpreter ()\n  (with-temp-location\n   (with-simulated-input\n    \"RET\"\n   (let ((current-prefix-arg '(4)))\n     (venv-mkvirtualenv-using \"some invalid interpreter\" venv-tmp-env)))\n   (should (equal venv-current-name venv-tmp-env))\n   (venv-deactivate)\n   (venv-rmvirtualenv venv-tmp-env)))\n\n(ert-deftest venv-mkvirtualenv-using-select-different-interpreter ()\n  (with-temp-location\n   (with-simulated-input\n       '((insert (executable-find \"python\")) \"RET\")\n     (let ((current-prefix-arg '(4)))\n       (venv-mkvirtualenv-using \"some invalid interpreter\" venv-tmp-env)))\n   (should (equal venv-current-name venv-tmp-env))\n   (venv-deactivate)\n   (venv-rmvirtualenv venv-tmp-env)))\n\n(ert-deftest venv-workon-works ()\n  (with-temp-env\n   venv-tmp-env\n   (venv-deactivate)\n   (venv-workon venv-tmp-env)\n   (assert-venv-activated)))\n\n(ert-deftest venv-deactivate-works ()\n  (with-temp-env\n   venv-tmp-env\n   (venv-deactivate)\n   ;; M-x pdb should ask to run \"pdb\"\n   (should (equal gud-pdb-command-name \"pdb\"))\n   ;; we remove the name correctly\n   (should (equal venv-current-name nil))\n   ;; we change the python path back\n   (should (equal python-shell-virtualenv-path nil)))\n   ;; we reset the PATH correctly\n   (should (not (s-contains? venv-tmp-env (getenv \"PATH\"))))\n   ;; we reset VIRTUAL_ENV\n   (should (equal nil (getenv \"VIRTUAL_ENV\")))\n   ;; we remove out dir to exec-path\n   (should (not (s-contains? venv-tmp-env (car exec-path)))))\n\n(ert-deftest venv-workon-errors-for-nonexistence ()\n  (should-error (venv-workon \"i-hopefully-do-not-exist\")))\n\n(ert-deftest venv-list-virtualenvs-works ()\n  (with-temp-env\n   venv-tmp-env\n   (should (s-contains? venv-tmp-env (venv-list-virtualenvs)))))\n\n(ert-deftest venv-cdvirtualenv-works ()\n  (with-temp-env\n   venv-tmp-env\n   (let ((old-wd default-directory))\n     (unwind-protect\n         (progn\n           (venv-cdvirtualenv)\n           (should (s-contains? venv-tmp-env default-directory)))\n       (cd old-wd)))))\n\n(ert-deftest venv-cpvirtualenv-works ()\n  (with-temp-env\n   venv-tmp-env\n   (unwind-protect\n       (progn\n         (venv-cpvirtualenv venv-tmp-env \"copy-of-tmp-env\")\n         (should (s-contains? \"copy-of-tmp-env\" (venv-list-virtualenvs))))\n     (venv-rmvirtualenv \"copy-of-tmp-env\"))))\n\n\n;; tests for hooks\n\n\n(ert-deftest venv-activate-hooks ()\n  (let ((preactivate nil)\n        (postactivate nil)\n        (venv-preactivate-hook '((lambda () (setq preactivate \"yes\"))))\n        (venv-postactivate-hook '((lambda () (setq postactivate \"yes\")))))\n  (with-temp-env\n   venv-tmp-env\n   (should (equal preactivate \"yes\"))\n   (should (equal postactivate \"yes\")))))\n\n(ert-deftest venv-mkvenv-hooks ()\n  (let ((venv-premkvirtualenv-hook '((lambda ()\n                                       (setq preactivated \"yes\"))))\n        (venv-postmkvirtualenv-hook '((lambda ()\n                                        (setq postactivated \"yes\")\n                                        (setq name venv-current-name)))))\n    (with-temp-env\n     venv-tmp-env\n     (venv-deactivate)\n     (should (equal preactivated \"yes\"))\n     (should (equal postactivated \"yes\"))\n     (should (equal name venv-tmp-env)))))\n\n(ert-deftest venv-set-location-works ()\n  (let ((expected-venv-location \"test location\")\n        (original-venv-location venv-location))\n    (venv-set-location expected-venv-location)\n    (should (equal venv-location expected-venv-location))\n    (setq venv-location original-venv-location)))\n\n(ert-deftest venv-projectile-auto-workon-works ()\n  (with-temp-env\n    venv-tmp-env\n    ;; the reason for setting a bogus venv-location here is that the\n    ;; venv-location shouldn't matter, projectile-auto-workon should happen\n    ;; indepedent of it's being set or not\n    (let ((venv-location \"bogus\"))\n      (noflet ((projectile-project-root () temporary-file-directory))\n        (setq venv-dirlookup-names (list venv-tmp-env))\n        (venv-deactivate)\n        (venv-projectile-auto-workon)\n        (assert-venv-activated)))))\n\n(ert-deftest venv-test-auto-cd-to-project-dir-works ()\n  (with-temp-env\n    venv-tmp-env\n    (with-temp-dir\n      (venv-deactivate)\n      (should (not (equal default-directory temp-dir)))\n      ;; set the project dir to be `temp-dir'\n      (append-to-file temp-dir nil\n        (s-concat (venv-name-to-dir venv-tmp-env) \".project\"))\n      (venv-workon venv-tmp-env)\n      ;; TODO should probably set these up to reset current-directory\n      ;; when done for hygeine purposes\n      (should (equal default-directory temp-dir)))))\n\n(ert-deftest venv-test-workon-does-not-cd-to-project-when-disabled ()\n  (with-temp-env\n    venv-tmp-env\n    (with-temp-dir\n      (let ((venv-workon-cd nil))\n        (venv-deactivate)\n        (should (not (equal default-directory temp-dir)))\n        ;; set the project dir to be `temp-dir'\n        (append-to-file temp-dir nil\n          (s-concat (venv-name-to-dir venv-tmp-env) \".project\"))\n        (venv-workon venv-tmp-env)\n        (should (not (equal default-directory temp-dir)))))))\n"
  },
  {
    "path": "virtualenvwrapper.el",
    "content": ";;; virtualenvwrapper.el --- a featureful virtualenv tool for Emacs\n\n;; Copyright (C) 2013 - 2015 James J Porter and [contributors](https://github.com/porterjamesj/virtualenvwrapper.el/graphs/contributors)\n\n;; Author: James J Porter <porterjamesj@gmail.com>\n;; URL: http://github.com/porterjamesj/virtualenvwrapper.el\n;; Version: 20151123\n;; Keywords: python, virtualenv, virtualenvwrapper\n;; Package-Requires: ((dash \"1.5.0\") (s \"1.6.1\"))\n\n;;; Commentary:\n\n;; A featureful virtualenv tool for Emacs. Emulates much of the\n;; functionality of Doug Hellmann's\n;; [virtualenvwrapper](https://bitbucket.org/dhellmann/virtualenvwrapper/)\n;; See documentation at\n;; https://github.com/porterjamesj/virtualenvwrapper.el for more details.\n\n;;; Code:\n\n(require 'dash)\n(require 's)\n\n;; needed to set gud-pdb-command-name\n(require 'gud)\n\n;; customizable variables\n\n(defgroup virtualenvwrapper nil\n  \"Virtualenvwrapper for Emacs.\"\n  :group 'python)\n\n(defcustom venv-virtualenv-command \"virtualenv\"\n  \"The command to use to run virtualenv.\"\n  :type '(string)\n  :group 'virtualenvwrapper)\n\n(defcustom venv-location\n  (expand-file-name (or (getenv \"WORKON_HOME\") \"~/.virtualenvs/\"))\n  \"The location(s) of your virtualenvs. This\ncan be either a string, which indicates a single directory in which\nyou keep all your virtualenvs, or a list of strings, in which case it\nspecifies disparate locations in which all your virtualenvs are kept.\nThe default location is ~/.virtualenvs/, which is where your virtualenvs\nare stored if you use virtualenvwrapper in the shell.\"\n  :group 'virtualenvwrapper)\n\n(defcustom venv-dirlookup-names\n  '(\".venv\" \"venv\")\n  \"Virtualenvs to search in the projectile-project-root\nto activate when one of them is found.\"\n  :type '(repeat file)\n  :group 'virtualenvwrapper)\n\n\n(defcustom venv-workon-cd\n  t\n  \"If set to t, cd to the virtualenv's project root when\nactivating it. Analgous to the VIRTUALENVWRAPPER_WORKON_CD\nenviornment variable in the original virtualenvwrapper\"\n  :type '(boolean)\n  :group 'virtualenvwrapper)\n\n\n;; hooks\n\n(defvar venv-premkvirtualenv-hook nil\n  \"Hook run before creating a new virtualenv.\")\n\n(defvar venv-postmkvirtualenv-hook nil\n  \"Hook run after creating a new virtualenv.\")\n\n(defvar venv-prermvirtualenv-hook nil\n  \"Hook run before deleting a virtualenv.\")\n\n(defvar venv-postrmvirtualenv-hook nil\n  \"Hook run after deleting a virtualenv.\")\n\n(defvar venv-preactivate-hook nil\n  \"Hook run before a virtualenv is activated.\")\n\n(defvar venv-postactivate-hook nil\n  \"Hook run after a virtualenv is activated.\")\n\n(defvar venv-predeactivate-hook nil\n  \"Hook run before a virtualenv is deactivated.\")\n\n(defvar venv-postdeactivate-hook nil\n  \"Hook run after a virtualenv is deactivated.\")\n\n\n;; internal variables that you probably shouldn't mess with\n\n(defvar venv-history nil \"The history of venvs we have worked on.\")\n\n(defvar venv-current-name nil \"Name of current virtualenv.\")\n\n(defvar venv-current-dir nil \"Directory of current virtualenv.\")\n\n(defvar venv-system-gud-pdb-command-name gud-pdb-command-name\n  \"Whatever `gud-pdb-command-name' is (usually \\\\[pdb]).\")\n\n;; copy from virtualenv.el\n(defvar venv-executables-dir\n  (if (eq system-type 'windows-nt) \"Scripts\" \"bin\")\n  \"The name of the directory containing executables. It is system dependent.\")\n\n;;;###autoload\n(defun venv-projectile-auto-workon ()\n  \"If a venv in the projetile root exists, activates it.\nSet your common venvs names in `venv-dirlookup-names'\"\n  (let ((path (--first\n                (file-exists-p it)\n                (--map (concat (projectile-project-root) it)\n                        venv-dirlookup-names))))\n    (when path\n      (setq venv-current-name path) ;; there's really nothing that feels good to do here ;_;\n      (venv--activate-dir path))))\n\n\n;; internal utility functions\n\n(defun venv--set-venv-gud-pdb-command-name ()\n  \"When in a virtual env, call pdb as \\\\[python -m pdb].\"\n  (setq gud-pdb-command-name \"python -m pdb\"))\n\n(defun venv--set-system-gud-pdb-command-name ()\n  \"Set the system \\\\[pdb] command.\"\n  (setq gud-pdb-command-name venv-system-gud-pdb-command-name))\n\n(defun venv-clear-history ()\n  (setq venv-history nil))\n\n(defun venv-dir-to-name (dir)\n  \"Extract the name of a virtualenv from a path.\"\n  (car (last (--filter (not (s-blank? it))\n                 (s-split \"/\" dir)))))\n\n(defun venv-name-to-dir (name)\n  \"Given the name of a virtualenv, translate it\nto the directory where that virtualenv is located.\"\n  (file-name-as-directory\n   (let ((potential-dir\n          (if (stringp venv-location)\n              (concat (file-name-as-directory\n                       (expand-file-name venv-location)) name)\n            (car (-filter\n                  (lambda (d)\n                    (s-equals? name (venv-dir-to-name d)))\n                  venv-location)))))\n     (if (and potential-dir\n              (file-exists-p\n               (concat (file-name-as-directory\n                        (expand-file-name potential-dir)) venv-executables-dir)))\n         (file-name-as-directory\n          (expand-file-name potential-dir))\n       (error (concat \"No such virtualenv: \" name))))))\n\n(defun venv-get-candidates ()\n  \"Wrapper to call get-candidates-list or\nget-candidates-string depending on which\nis appropriate for how venv-location is\nspecified.\"\n  (let ((candidates\n         (if (stringp venv-location)\n             (venv-get-candidates-dir venv-location)\n           (venv-get-candidates-list venv-location))))\n    (when (not (eq (length (-distinct candidates))\n                   (length candidates)))\n      (error \"Some virtualenvs have the same name!\"))\n    candidates))\n\n(defun venv-get-candidates-list (list)\n  \"Given LIST of virtualenv directories,\nreturn a list of names that can be used in, e.g.\na completing read. This trusts the caller to only\npass directories with are actually virtualenvs.\"\n   (-map (lambda (dir)\n           (car (last (-filter (lambda (s) (not (s-blank? s)))\n                               (s-split \"/\" dir)))))\n         (-filter\n          (lambda (s) (car (file-attributes\n                            (concat (file-name-as-directory\n                                     (expand-file-name s)) venv-executables-dir))))\n                  list)))\n\n(defun venv-get-candidates-dir (dir)\n  \"Given a directory DIR containing virtualenvs, return a list\nof names that can be used in the completing read.\"\n  (let ((proper-dir (file-name-as-directory (expand-file-name dir))))\n    (-filter (lambda (s)\n               (let ((subdir (concat proper-dir s)))\n                 (car (file-attributes\n                       (concat (file-name-as-directory subdir) venv-executables-dir)))))\n             (directory-files proper-dir nil \"^[^.]\"))))\n\n(defun venv-get-stripped-path (path)\n  \"Return what the PATH would look like if we weren't in a\nvirtualenv. PATH should be a list of strings specifiying directories.\"\n  (-filter\n    (lambda (s) (not (s-equals? s (concat venv-current-dir venv-executables-dir))))\n    path))\n\n\n(defun venv--purge-history (candidates)\n  \"Remove history candidates that are not present in the list CANDIDATES\"\n  (setq venv-history (-filter (lambda (s) (-contains? candidates s))\n                              venv-history)))\n\n(defun venv-is-valid (name)\n  \"Test if NAME is a valid virtualenv specifier\"\n  (-contains? (venv-get-candidates) name))\n\n(defun venv-read-name (prompt)\n  \"Do a completing read to get the name of a candidate,\nprompting the user with the string PROMPT\"\n  (let ((candidates (venv-get-candidates)))\n    ;; purge history of no longer existant candidates first\n    (venv--purge-history candidates)\n    (completing-read prompt\n                     candidates nil t nil\n                     'venv-history\n                     (or (car venv-history)\n                         (car candidates)))))\n\n(defun venv-list-virtualenvs ()\n  (s-join \"\\n\" (venv-get-candidates)))\n\n(defun venv--activate-dir (dir)\n  \"Given a directory corresponding to a virtualenv, activate it\"\n  (run-hooks 'venv-preactivate-hook)\n  (setq venv-current-dir (file-name-as-directory dir))\n  ;; setup the python shell\n  (setq python-shell-virtualenv-path venv-current-dir)\n  ;; setup emacs exec-path\n  (add-to-list 'exec-path (concat venv-current-dir venv-executables-dir))\n  ;; setup the environment for subprocesses\n  (let ((path (concat venv-current-dir\n               venv-executables-dir\n               path-separator\n               (getenv \"PATH\"))))\n    (setenv \"PATH\" path)\n    ;; keep eshell path in sync\n    (setq eshell-path-env path))\n  (setenv \"VIRTUAL_ENV\" venv-current-dir)\n  (if venv-workon-cd\n    (venv--switch-to-project-dir))\n  (venv--set-venv-gud-pdb-command-name)\n  (run-hooks 'venv-postactivate-hook))\n\n(defun venv--switch-to-project-dir ()\n  \"If we find the project file, cd into that directory\"\n  (let ((proj-file (expand-file-name \".project\" venv-current-dir)))\n    (when (file-exists-p proj-file)\n      (cd (with-temp-buffer\n            (insert-file-contents proj-file)\n            (string-trim (buffer-string)))))))\n\n;; potentially interactive user-exposed functions\n\n;;;###autoload\n(defun venv-deactivate ()\n  \"Deactivate the current venv.\"\n  (interactive)\n  (run-hooks 'venv-predeactivate-hook)\n  (setq python-shell-virtualenv-path nil)\n  (setq exec-path (venv-get-stripped-path exec-path))\n  (setenv \"PATH\" (s-join path-separator\n                  (venv-get-stripped-path\n                   (s-split path-separator (getenv \"PATH\")))))\n  (setenv \"VIRTUAL_ENV\" nil)\n  (setq venv-current-name nil)\n  (setq venv-current-dir nil)\n  (setq eshell-path-env (getenv \"PATH\"))\n  (venv--set-system-gud-pdb-command-name)\n  (run-hooks 'venv-postdeactivate-hook)\n  (when (called-interactively-p 'interactive)\n    (message \"virtualenv deactivated\")))\n\n;;;###autoload\n(defun venv-set-location (&optional location)\n  \"Set where to look for virtual environments to LOCATION.\nThis is useful e.g. when using tox.\"\n  (interactive)\n  (when (not location)\n    (setq location (read-directory-name \"New virtualenv location: \" venv-location)))\n  (venv-deactivate)\n  (setq venv-location location)\n  (when (called-interactively-p 'interactive)\n    (message (concat \"Virtualenv location: \" location))))\n\n;;;###autoload\n(defun venv-workon (&optional name)\n  \"Interactively switch to virtualenv NAME. Prompts for name if called\ninteractively.\"\n  (interactive)\n  ;; if without argument, read from user\n  (unless name\n    (setq name (venv-read-name\n                (if venv-current-name\n                    (format \"Choose a virtualenv (currently %s): \" venv-current-name)\n                  \"Choose a virtualenv: \"))))\n  ;; validate name\n  (when (not (venv-is-valid name))\n    (error (format \"Invalid virtualenv %s specified!\" name)))\n  ;; then deactivate\n  (venv-deactivate)\n  ;; then switch\n  (setq venv-current-name name)\n  ;; push it onto the history\n  (add-to-list 'venv-history venv-current-name)\n  ;; actually activate it\n  (venv--activate-dir (venv-name-to-dir venv-current-name))\n  (when (called-interactively-p 'interactive)\n    (message (concat \"Switched to virtualenv: \" venv-current-name))))\n\n;; for hilarious reasons to do with bytecompiling, this has to be here\n;; instead of below\n(defmacro venv-with-virtualenv (name &rest forms)\n  \"Evaluate FORMS with venv NAME active. NAME must be a string\nidentifying a virtualenv.\"\n  `(progn\n     (let ((prev-dir default-directory)\n           (prev-env venv-current-name))\n       (venv-workon ,name) ;; switch it up\n       (cd venv-current-dir)\n       (unwind-protect\n           (progn\n             ,@forms) ;; evalulate forms\n         (if prev-env ;; switch back\n             (venv-workon prev-env)\n           (venv-deactivate))\n         (cd prev-dir)))))\n\n(defun venv--check-executable ()\n  \"Verify that there is a virtualenv executable available,\nthrowing an error if not\"\n  (unless (executable-find venv-virtualenv-command)\n    (error \"There doesn't appear to be a virtualenv executable on\n    your exec path. Ensure that you have virtualenv installed and\n    that the exec-path variable is set such that virtualenv can\n    be found. A common cause of problems like this is GUI Emacs\n    not having environment variables set up like the shell. Check\n    out https://github.com/purcell/exec-path-from-shell for a\n    robust solution to this problem.\")))\n\n(defun venv-get-python-executable ()\n  \"Do a completing read for a python executable to use in mkvirtualenv\"\n  )\n\n;;;###autoload\n(defun venv-mkvirtualenv-using (interpreter &rest names)\n  \"Create new virtualenvs NAMES using INTERPRETER. If venv-location\nis a single directory, the new virtualenvs are made there; if it\nis a list of directories, the new virtualenvs are made in the\ncurrent `default-directory'.\"\n  (interactive)\n  (venv--check-executable)\n  (let* ((foo (if current-prefix-arg\n                         (read-string \"Python executable: \")\n                       interpreter))\n        (parent-dir (if (stringp venv-location)\n                        (file-name-as-directory\n                         (expand-file-name venv-location))\n                      default-directory))\n        (python-exe-arg (when foo\n                          (concat \"--python=\" foo)))\n        (names (if names names\n                 (list (read-from-minibuffer \"New virtualenv: \")))))\n    ;; map over all the envs we want to make\n    (--each names\n      ;; error if this env already exists\n      (when (-contains? (venv-get-candidates) it)\n        (error \"A virtualenv with this name already exists!\"))\n      (run-hooks 'venv-premkvirtualenv-hook)\n      (shell-command (concat venv-virtualenv-command \" \" python-exe-arg \" \" parent-dir it))\n      (when (listp venv-location)\n        (add-to-list 'venv-location (concat parent-dir it)))\n      (venv-with-virtualenv it\n                            (run-hooks 'venv-postmkvirtualenv-hook))\n      (when (called-interactively-p 'interactive)\n        (message (concat \"Created virtualenv: \" it))))\n    ;; workon the last venv we made\n    (venv-workon (car (last names)))))\n\n;;;###autoload\n(defun venv-mkvirtualenv (&rest names)\n  \"Create new virtualenvs NAMES. If venv-location is a single\ndirectory, the new virtualenvs are made there; if it is a list of\ndirectories, the new virtualenvs are made in the current\n`default-directory'.\"\n  (interactive)\n  (apply #'venv-mkvirtualenv-using nil names))\n\n;;;###autoload\n(defun venv-rmvirtualenv (&rest names)\n  \"Delete virtualenvs NAMES.\"\n  (interactive)\n  ;; deactivate first\n  (venv-deactivate)\n  ;; check validity and read names if necessary\n  (if names\n      (--map (when (not (venv-is-valid it))\n               (error \"Invalid virtualenv specified!\"))\n             names)\n    (setq names (list (venv-read-name \"Virtualenv to delete: \"))))\n  ;; map over names, deleting the appropriate directory\n  (--each names\n    (run-hooks 'venv-prermvirtualenv-hook)\n    (delete-directory (venv-name-to-dir it) t)\n    ;; get it out of the history so it doesn't show up in completing reads\n    (setq venv-history (-filter\n                        (lambda (s) (not (s-equals? s it))) venv-history))\n    ;; if location is a list, delete it from the list\n    (when (listp venv-location)\n      (setq venv-location\n            (-filter (lambda (locs) (not (s-equals?\n                                          it\n                                          (venv-dir-to-name locs))))\n                     venv-location)))\n    (run-hooks 'venv-postrmvirtualenv-hook)\n    (when (called-interactively-p)\n      (message (concat \"Deleted virtualenv: \" it)))))\n\n;;;###autoload\n(defun venv-lsvirtualenv ()\n  \"List all available virtualenvs in a temp buffer.\"\n  (interactive)\n  (with-output-to-temp-buffer\n      \"*Virtualenvs*\"\n      (princ (venv-list-virtualenvs))))\n\n;;;###autoload\n(defun venv-cdvirtualenv (&optional subdir)\n  \"Change to the directory of current virtualenv. If\nSUBDIR is passed, append that to the path such that\nwe are immediately in that directory.\"\n  (interactive)\n  (if venv-current-dir\n      (let ((going-to (concat (file-name-as-directory\n                               (expand-file-name venv-current-dir))\n                              subdir)))\n        (cd going-to)\n        (when (called-interactively-p 'interactive)\n          (message (concat \"Now in directory: \" going-to))))\n    (error \"No virtualenv is currently active.\")))\n\n;;;###autoload\n(defun venv-cpvirtualenv (&optional name newname)\n  \"Copy virtualenv NAME to NEWNAME. Any arguments not passed will be\nprompted for This comes with the same caveat as cpvirtualenv in the\noriginal virtualenvwrapper, which is that is far from guarenteed to\nwork well. Many packages hardcode absolute paths in various places an\nwill break if moved to a new location. Use with caution. If used with\na single virtualenv directory, behaves just like cpvirtualenv in\nvirtualenvwrapper.sh.  If used with virtualenvs spread around the\nfilesystem, creates the new virtualenv in the current default\ndirectory.\"\n  (interactive)\n  (let ((parent-dir (if (stringp venv-location)\n                        (file-name-as-directory\n                         (expand-file-name venv-location))\n                      default-directory)))\n    (when (not name) (setq name (venv-read-name \"Virtualenv to copy from: \")))\n    (when (not newname) (setq newname\n                              (read-from-minibuffer \"Virtualenv to copy to: \")))\n    ;; throw an error if newname already exists\n    (when (file-exists-p (concat parent-dir newname))\n      (error \"A virtualenv with the proposed name already exists!\"))\n    ;; make the copy\n    (copy-directory (venv-name-to-dir name)\n                    (concat parent-dir newname))\n    ;; if the location specifier is a list, add to it.\n    (when (listp venv-location)\n      (add-to-list 'venv-location (concat parent-dir newname)))\n    (when (called-interactively-p 'interactive)\n      (message (format \"Copied virtualenv %s to %s\" name newname)))\n    (venv-workon newname)))\n\n\n;; macros and functions supporting executing elisp or\n;; shell commands in a particular venv\n\n(defmacro venv-allvirtualenv (&rest forms)\n  \"For each virtualenv, activate it, switch to its directory,\nand then evaluate FORMS.\"\n  `(progn\n     (--each (venv-get-candidates)\n             (venv-with-virtualenv it\n                                   ,@forms))))\n\n(defun venv-with-virtualenv-shell-command (name command)\n  \"Execute the string COMMAND in virtualenv NAME.\"\n  (venv-with-virtualenv name\n                        (shell-command command)))\n\n(defun venv-allvirtualenv-shell-command (&optional command)\n  \"Just like venv-allvirtulenv, but executes a shell\ncommand (COMMAND) rather than elisp forms.\"\n  (interactive)\n  (when (not command)\n    (setq command (read-from-minibuffer \"Shell command to execute: \")))\n  (-map (lambda (name)\n          (venv-with-virtualenv-shell-command name command))\n        (venv-get-candidates))\n  (message (concat \"Executed \" command \" in all virtualenvs\")))\n\n\n;; Code for setting up interactive shell and eshell\n\n;; interactive shell\n\n;;;###autoload\n(defun venv-shell-init (process)\n  \"Activate the current virtualenv in a newly opened shell.\"\n  (comint-send-string\n   process\n   (concat \"if command -v workon >/dev/null 2>&1; then workon \"\n           venv-current-name\n           \"; else source \"\n           venv-current-dir venv-executables-dir\n           \"/activate; fi \\n\")))\n\n;;;###autoload\n(defun venv-initialize-interactive-shells ()\n  \"Configure interactive shells for use with\nvirtualenvwrapper.el.\"\n    (defadvice shell (around strip-env ())\n      \"Use the environment without the venv to start up a new shell.\"\n      (let* ((buffer-name (or buffer \"*shell*\"))\n             (buffer-exists-already (get-buffer buffer-name)))\n        (if (or buffer-exists-already (not venv-current-name))\n            ad-do-it\n          (progn (setenv \"PATH\" (s-join path-separator (venv-get-stripped-path\n                                         (s-split path-separator (getenv \"PATH\")))))\n                 (setenv \"VIRTUAL_ENV\" nil)\n                 ad-do-it\n                 (venv-shell-init buffer-name)\n               (setenv \"PATH\" (concat venv-current-dir venv-executables-dir path-separator (getenv \"PATH\")))\n               (setenv \"VIRTUAL_ENV\" venv-current-dir)))))\n    (ad-activate 'shell))\n\n\n;; eshell\n\n(eval-and-compile\n  (defun venv--gen-fun (command)\n    `(defun ,(intern (format \"pcomplete/eshell-mode/%s\" command)) ()\n       (pcomplete-here* (venv-get-candidates)))))\n\n(defmacro venv--make-pcompletions (commands)\n  `(progn ,@(-map #'venv--gen-fun commands)))\n\n;;;###autoload\n(defun venv-initialize-eshell ()\n  \"Configure eshell for use with virtualenvwrapper.el.\"\n  ;; make emacs and eshell share an environment\n  (setq eshell-modify-global-environment t)\n  ;; set eshell path\n  (setq eshell-path-env (getenv \"PATH\"))\n  ;; alias functions\n  (defun eshell/workon (arg) (venv-workon arg))\n  (defun eshell/deactivate () (venv-deactivate))\n  (defun eshell/rmvirtualenv (&rest args) (apply #'venv-rmvirtualenv args))\n  (defun eshell/mkvirtualenv (&rest args) (apply #'venv-mkvirtualenv args))\n  (defun eshell/cpvirtualenv (&rest args) (apply #'venv-cpvirtualenv args))\n  (defun eshell/cdvirtualenv (&optional arg) (venv-cdvirtualenv arg))\n  (defun eshell/lsvirtualenv () (venv-list-virtualenvs))\n  (defun eshell/allvirtualenv (&rest command)\n    (venv-allvirtualenv-shell-command\n     (s-join \" \" (eshell-stringify-list command))))\n  ;; make completions work\n  (venv--make-pcompletions (\"workon\" \"rmvirtualenv\"\n                            \"cdvirtualenv\" \"cpvirtualenv\"))\n  (message \"Eshell virtualenv support initialized.\"))\n\n(provide 'virtualenvwrapper)\n;;; virtualenvwrapper.el ends here\n"
  }
]