Commit graph

81 commits

Author SHA1 Message Date
Jeff Widman e3a9583f33 Support virtualenvwrapper with / without pyenv virtualenv-init or virtualenvwrapper plugins
The desired logic is:

For the `pyenv` plugins `virtualenv-init` and `virtualenvwrapper`:
1. If either plugin is present, activate it
2. If `virtualenvwrapper` plugin is not present, then
   [fallback to standard
   `virtualenvwrapper`](https://github.com/sorin-ionescu/prezto/pull/1414#issuecomment-320306421).
3. If `virtualenvwrapper` plugin is present, then [don't fallback to
   standard `virtualenvwrapper`, regardless of whether `virtualenv-init`
   is
   present](https://github.com/sorin-ionescu/prezto/pull/1981#issue-1123766676).

Previously, if the `virtualenv` command was present but `pyenv` was
missing, then the fallback wouldn't be hit. This bug was introduced by
https://github.com/sorin-ionescu/prezto/pull/1981/ which ensured that
the `pyenv` `virtualenvwrapper` plugin was activated if present,
regardless of the presence of the `virtualenv-init` plugin.

As an optimization, the check for the `pyenv` plugins are skipped if
`pyenv` itself isn't found.

Since we only want to fallback if the `pyenv` `virtualenvwrapper` plugin
is missing, but that's buried within the `pyenv` logic and we also need
to handle when `pyenv` itself is missing, this switches to using a flag
variable.

I also renamed the `virtualenv_sources` var to
`virtualenvwrapper_sources` as `virtualenv` is distinct from
`virtualenvwrapper`, so using one name for a var that is really about
the other is confusing.

Looking at `git blame`, there's a _lot_ of prior art here around trying
to support all the permutations of `pyenv` and various plugins:
* https://github.com/sorin-ionescu/prezto/issues/1413
* https://github.com/sorin-ionescu/prezto/pull/1414
* https://github.com/sorin-ionescu/prezto/pull/1433
* https://github.com/sorin-ionescu/prezto/pull/1434

So we need to be extremely careful to continue to support all these
permutations.

Fix https://github.com/sorin-ionescu/prezto/issues/2022
2022-10-26 22:03:42 -07:00
Jeff Widman ca9012c776 Set EXTENDED_GLOB in the python module
This is needed to find python. 

It is often already set because a user has the directory or completion module loaded before this, but that's not always true.

See extensive debugging / further explanation here: https://github.com/sorin-ionescu/prezto/issues/1949

This does not fully resolve that issue, as there's another enhancement that I'll put up as a separate PR.
2022-10-25 15:54:00 -07:00
zbirenbaum d840f0fc7b Fix crash on open caused by incorrect conditional in python module 2022-02-03 22:08:36 -05:00
Thomas Blaschke 866d5dfccd Add conda to the list of requirements
If conda is not in the list of requirements, the scripts exit too early in case pyenv is not installed and the module is configured with:

 zstyle ':prezto:module:python' skip-virtualenvwrapper-init 'on' 
 zstyle ':prezto:module:python' conda-init 'on'

Tested on Amazon EC2 Linux for Deeplearning AMI 47.0 and MacOS 11.4
2021-06-23 23:22:09 -05:00
Indrajit Raychaudhuri afe59b293b python: Update pyenv initialization flow per pyenv 2.0
In pyenv 2.0 onwards, it is not enough anymore to initialize pyenv in
shell by just calling `pyenv init -`. We also need to update `path` to
include pyenv shims by calling `pyenv init --path`.

Also, honor `$PYENV_ROOT` if set but, no need to set it explicitly if
not set. Instead, let the initialization script take care of that.
2021-06-01 14:29:39 -05:00
Indrajit Raychaudhuri f0942e6dda python: Optimize completion for loading lazily on demand
Move `pip` to separate completion definition delegating to pip to do
all the completion work.

Since the completion is loaded lazily on-demand, it avoids the
performance overhead during Zsh initialization.

Implementation note:
The helper function `_pip_completion` implementation is based on the
official pip completion function (which can be generated with
`pip completion --zsh`) adhering to the newer compsys style.

See: 'man zshcompsys' for more details.
2021-06-01 14:29:39 -05:00
Indrajit Raychaudhuri d686da3c03 python: Reformat and apply visual cleanup
Changes:
- Fallback to `virtualenvwrapper` without `pyenv` wrapper if `python` is
  available in path, regardless of whether `brew` is available.
- Look up for availability of `python2` and `python3`, not just `python`.
- Check for existence of path before adding to global `$path` array.
- Adhere to more idiomatic Zsh operation and minimize redundant syntaxes.
- Prefer looking up `$functions` for fully initialized `pyenv`.
2021-06-01 14:29:39 -05:00
Indrajit Raychaudhuri 1ff9421f7b general: Update documentation better qualifying runcom paths
Zsh and Prezto files don't always reside in `~/`. Instead, they have
a more spec compliant location (`${ZDOTDIR:-$HOME}/`). Make them
unambiguous in the documentation. Likewise, for `$GNUPGHOME`.

Further, add instruction for optionally setting up Prezto in
`$XDG_CONFIG_HOME`.

While at this, also add clarification on relative ordering of some of
the modules, apply more formatting tweaks and doc improvements.
2021-05-21 12:31:02 -05:00
Indrajit Raychaudhuri d80e393f78 general: Reformat documentation with better formatting and wording
General purpose reformating and rewording in (a few places). This should
also make markdown linting happier.

Prefer back-ticks wherever useful and use `console` for code blocks to
be executed on terminal.

Also, update references links wherever possible (including update from
'http://' to 'https://').
2021-05-05 12:21:04 -05:00
Olaf Conradi e9197234cf
Add check for empty WORKON_HOME (#1861)
When $WORKON_HOME is not set and $ENV_NAME is equal to
$PROJECT_ROOT/.venv which contains bin/activate then
the code wrongly assumes workon is available.

It should execute the second branch to source bin/activate.
2020-07-27 12:49:40 -07:00
Joost Cassee 2d3763380c
Ask pyenv whether pip exists if installed (#1848)
Pyenv will install shims for commands that exist in any interpreter, even if it is not the current one. This means that a command may technically exist, but when executed will tell the user to try a different interpreter. The original check for pip in the Python module can fail for this reason, in particular on Ubuntu 20.04.

This change checks with pyenv whether pip really exists in the current interpreter to work around this problem and fixes a bug in pip command detection.
2020-06-29 10:25:15 -07:00
Texas Toland ff91c8d410
Make .zcomp* location configurable (#1842) 2020-06-04 13:53:44 -07:00
Charith Amarasinghe d5bef142d4
Fix missing dependency on helper module for helpers added in #1793 (#1811)
PR #1793 introduced helper functions for OS detection in some modules.
These helpers require a module dependency on the 'helper' module.
2020-03-29 12:49:35 -07:00
Kaspar Vollenweider f4ca9ebfc9 feat(helper): add os-type helper functions
Add the following functions:

- is-darwin
- is-linux
- is-bsd
- is-cygwin

And apply them everywhere I found code doing that what these functions do.
2020-03-19 11:49:11 -07:00
Kaleb Elwert 75b112bcd0 node, python, ruby: update docs about new envars 2019-09-10 09:10:31 -07:00
laggardkernel f596d5d1d6 python: improve PYENV_ROOT detection 2019-09-10 09:00:11 -07:00
Indrajit Raychaudhuri a338cba805 python: Use brace expansion for pip compctl match
Just use brace expansion only (and not a mix of brace expansion and
path expansion) to expand `sed` match for more variants of 'pip*' (pip,
pip2, pip3, pip2.7, pip3.7 etc.) in `compctl` assignment
2018-12-18 14:19:07 -06:00
Indrajit Raychaudhuri 9d3e2f0204
python: Expand compctl matches for pip variants
Expand `sed` match for more variants of 'pip*' (pip, pip2, pip3, pip2.7, 
pip3.7 etc.) for `compctl` assignment
2018-12-14 21:32:10 -06:00
Indrajit Raychaudhuri a987c8bc8a
python: Fix pip compctl file match pattern
Make `sed` match more reliable while replacing the whole of 'pip*' with 
'pip pip2 pip3' for `compctl` assignment
2018-12-12 16:18:58 -06:00
Indrajit Raychaudhuri e7fea3343f python: Use more apropriate filename for pip completion 2018-12-11 08:11:44 -06:00
Indrajit Raychaudhuri 53286ebbdb python: Make cached completion file mangling more reliable
While mangling cached completion file, we cannot just assume that
`$pip_command` would resolve to `pip` -- it might be `pip2` or `pip3`
depending on the relative position in zsh `$commands` array. Thus
replace the whole of 'pip*' with 'pip pip2 pip3' for compctl assignment.
2018-12-11 08:11:44 -06:00
Indrajit Raychaudhuri 992b9de505 doc: More copyediting and formatting for consistency 2018-10-12 12:04:49 -05:00
Kaleb Elwert e9387a177e python: respect PYENV_ROOT if already set
Fixes #1578
2018-09-28 14:24:30 -07:00
Kaleb Elwert ee885d42de python: use pure's magic value for VIRTUAL_ENV_DISABLE_PROMPT
Fixes #1627
2018-09-28 14:04:24 -07:00
Steven Loria dacef14214 Improve startup time by skipping pyenv rehash
After profiling startup time, I found that "pyenv rehash" is
by far the slowest piece. This change skips rehashing on init.

See https://github.com/pyenv/pyenv/issues/784#issuecomment-404850327

Also pass the shell explicitly, as suggested in
https://github.com/pyenv/pyenv/issues/784#issuecomment-404944318,
which provides a modest improvement.

In total, this improves startup time from 1s to 0.3s on my machine.
Using the following command:
python -m timeit "__import__('subprocess').Popen(['zsh', '-i', '-c', 'echo']).communicate()"

Result before this change:
10 loops, best of 3: 1 sec per loop

Result after this change:
10 loops, best of 3: 334 msec per loop
2018-08-01 13:52:52 -04:00
Casey McGinty 2995b7d0c8 Update cache files when .zpreztorc file is modified
Fixes #1581
2018-05-06 13:22:22 -07:00
Casey McGinty 6e179f24ab Export VIRTUAL_ENV_DISABLE_PROMPT when enabling virutalenv
Adding `export` ensures the define is available in the shell so pyenv
or virtualenvwrapper do not duplicate the virtualenv name on the
prompt.
2018-05-01 08:53:16 -07:00
Ashish Gandhi b6b43eb331 Rename "Mac OS X" to "macOS" in comments
This only changes references in text for human consumption. It leaves
out renaming paths because that can cause breaking changes.

Related issue https://github.com/sorin-ionescu/prezto/issues/1449.
2018-04-16 15:53:48 -07:00
bryndin e00562e7cf python: autoload add-zsh-hook when needed (#1549)
Fixes #1550
2018-02-23 13:39:45 -08:00
Kaleb Elwert 83085e5231 python: remove zstyle setting in favor of third party environment variable
Refs #1519, #1520
2017-12-14 17:23:44 -08:00
Kaleb Elwert 4c31107e3b python: only override virtualenv python if not set
Fixes #1520
2017-12-14 17:11:06 -08:00
Kaleb Elwert d8d6b4d70a python: only override virtualenvwrapper python when needed
Fixes #1519
2017-12-12 23:11:55 -08:00
Kaleb Elwert e021adeb4a python: make a reasonable guess about virtualenvwrapper python location
Fixes #1416
2017-12-11 11:01:42 -08:00
Kaleb Elwert 3ab569ff78 python-info: add support for pyenv and only do extra work if the prompt needs it 2017-12-04 15:08:58 -08:00
Kaleb Elwert 64d57ec71f python-info: avoid setting python_info[version] if python is not on the PATH 2017-12-04 12:08:45 -08:00
Kaleb Elwert b407ba0c3a python-info: provide python version info for theming
Closes #1173
Closes #958
2017-12-04 12:05:21 -08:00
ickc 96bbb31cc8 Added conda virtualenv support to python module. (#1505)
* Added conda virtualenv support to python module
* Added instructions for Python module options to README

Thanks to @egpbos for the original feature and @ickc for fixing the merge conflicts.
2017-11-12 16:20:52 -08:00
Kaleb Elwert 948d9b3aa5 Store cache files in a user-writable location
Fixes #1122
2017-11-10 11:37:14 -08:00
Jeff Widman 727f094b0f [python] cleanup readme formatting
Anyone want some backticks? :-)
2017-08-29 16:51:27 -07:00
Jeff Widman 8fa14ed72f Drop easy_install in docs, everyone now uses pip (#1436) 2017-08-29 16:04:44 -07:00
Greg Anders 9c528efa60 Explicitly set PYENV_ROOT 2017-08-26 16:21:45 -05:00
Indrajit Raychaudhuri 83ab314b77 [python] Refine pyenv based virtualenv management
Now that pyenv plugins availability is detected by directly probing
'pyenv', we need to rely on the same mechanism consistently.

Further, we perform available pyenv plugin scan with native zsh
techniques instead of relying on external commands.
2017-08-18 09:35:52 -05:00
Indrajit Raychaudhuri 5ffc8a07f1 [python] Ensure availability of virtualenvwrapper file before sourcing it 2017-08-18 07:56:10 -05:00
Zach Whaley 3194442759 Edit pyenv virtualenv-init check to support non-brew installations
If the pyenv virtualenv plugin is installed using the [pyenv-installer][1]
app script or directly via a [Git clone][2], then the pyenv-virtualenv-init
executable, that the `pyenv virtualenv-init` command uses, will not
exist in the user's PATH and therefore cannot be found using
`$commands[pyenv-virtualenv-init]`.
Installing the pyenv-virtualenv plugin in this manner is common among Linux users.

Using the pyenv `commands` command, which lists all commands pyenv can
run, we can find if the virtualenv-init command is available to pyenv
and subsequently the virtualenv plugin, without relying on
pyenv-virtualenv-init to exist in the user's PATH.

[1]: https://github.com/pyenv/pyenv-installer
[2]: https://github.com/pyenv/pyenv-virtualenv#installing-as-a-pyenv-plugin
2017-08-17 22:50:17 -05:00
Indrajit Raychaudhuri 8d7e3e27c7 [python] Detect availability of virtualenv plugins as well as pyenv
Just having 'pyenv' available doesn't imply availability of virtualenv pyenv
plugins. Check for availability of virtualenv plugins as well before attempting
to use pyenv wrapper for virtualenv.
2017-08-04 13:46:14 -05:00
Indrajit Raychaudhuri 19435b16ea [python] Improve and document virtualenvwrapper initialization flow
Changes:
* Simplify zstyle name `skip-virtualenvwrapper-init` to `initialize`
  avoiding double negation in name
* Always perform `eval (pyenv virtualenv-init -)` at initialization
* Prefer `virtualenvwrapper_lazy` over `virtualenvwrapper` when available
* Honor `VIRTUALENVWRAPPER_VIRTUALENV` if it is defined.
* Document about `VIRTUALENVWRAPPER_PYTHON` and `VIRTUALENVWRAPPER_VIRTUALENV`
  (this would be particularly important in macOS after recent homebrew update)
* Add additional documentation for `initialize` in _README.md_ and _zpreztorc_
* Add aliases `py2`, `py3` as shortcut for `python2`, `python3` respectively
2017-07-26 01:42:31 -05:00
Indrajit Raychaudhuri ac628c9059 [general] Switch code block formatting to use fence formatting
Changes:
* Indented code block doesn't support syntax highlighting, use fenced
formatting (```) instead for better syntax highlighting
* Wrap commands/functions in backticks
* Typo fixes
2017-07-22 13:11:29 -05:00
Indrajit Raychaudhuri bcbaea27af [python] Detect actual pip command available for generating completion cache
We cannot always assume availability of `pip`, it can be `pip2` or `pip3`
instead. We detect the first available one and use it for generating the
completion cache.
2017-07-22 13:08:33 -05:00
Kaleb Elwert 899c176942 python: add ubuntu locations for virtualenvwrapper.sh 2017-07-10 00:03:36 -07:00
Kaleb Elwert 7d5beeab51 Add comments into each of the function files to make them easier to find 2017-07-06 16:13:36 -07:00