Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): add auto venv activation #12248

Merged
merged 4 commits into from Mar 3, 2024
Merged

Conversation

rcrews
Copy link
Contributor

@rcrews rcrews commented Mar 1, 2024

Standards checklist:

  • The PR title is descriptive.
  • The PR doesn't replicate another PR which is already open.
  • I have read the contribution guide and followed all the instructions.
  • The code follows the code style guide detailed in the wiki.
  • The code is mine or it's from somewhere with an MIT-compatible license.
  • The code is efficient, to the best of my ability, and does not waste computer resources.
  • The code is stable and I have tested it myself, to the best of my abilities.
  • If the code introduces new aliases, I provide a valid use case for all plugin users down below.

Changes:

  • Adds and runs a function that listens for directory changes. When cd'ing into a directory
    containing venv/bin/activate, it automatically activates the virtual environment.
    When cd'ing out of the directory, it automatically deactivates the virtual environment.
  • It supports two global environment variables,
    • VENV_NAME where a name different from venv can be specified. (For example,
      .venv is also suggested by the Python docs.)
    • Also, if anyone doesn't want this, they can simply set DISABLE_AUTO_VRUN and the listener
      will always exit without making any changes.

Other comments:

Auto-activating the environment is a feature of the Ruby Version Manager (rvm). I really like that feature,
and researched till I could add it to my Python environments. I've been running this on my computer for
about six months without issues.

@ohmyzsh ohmyzsh bot added Area: plugin Issue or PR related to a plugin Type: documentation Documentation issue or Pull Request labels Mar 1, 2024
@rcrews
Copy link
Contributor Author

rcrews commented Mar 1, 2024

Providing at-mentions to people who have contributed to the python plug-in in the last year: @gautamkrishnar @MikuHatsune39 @carlosala

Copy link
Member

@carlosala carlosala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Could you make it opt-in instead of out-out? Thanks!

@carlosala carlosala self-assigned this Mar 2, 2024
@rcrews
Copy link
Contributor Author

rcrews commented Mar 3, 2024

Thanks for your kind reaction, @carlosala! I added two commits. One does as you requested and makes the new feature opt-in, and improves the description of the new feature in the README.
Since the new feature introduces a couple new configuration environment variables, I updated the two existing venv functions -- vrun and mkv -- to also use PYTHON_VENV_NAME, if it is set.
Let me know if you want me to squash these into a single commit, or if you want me to add "feat(python):" to the commit messages for all of the commits.

Copy link
Member

@carlosala carlosala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@carlosala
Copy link
Member

I made some changes to simplify the code and align it with our usual design.
Thanks for your contribution!

@carlosala carlosala changed the title feat(python): Auto-activate venv when cd'ing into directory feat(python): add auto venv activation Mar 3, 2024
@carlosala carlosala merged commit 12cd3b3 into ohmyzsh:master Mar 3, 2024
2 checks passed
@robbyrussell
Copy link
Member

Hey @rcrews -- we really appreciate the contribution! ✌️

lesterchan added a commit to lesterchan/oh-my-zsh that referenced this pull request Mar 16, 2024
* upstream/master: (90 commits)
  feat(gradle): update completion to version 25da917c (ohmyzsh#12287)
  fix(dependencies): copy gradle LICENSE
  feat(dependencies): enable gradle plugin
  docs: fix typos (ohmyzsh#12284)
  docs(pyenv): fix typo (ohmyzsh#12283)
  feat(extract): prefer using `pbzip2` instead of `bunzip2` (ohmyzsh#12280)
  docs(readme): add contributor list (ohmyzsh#12236)
  feat(fzf): add default fzf_base for msys2 (ohmyzsh#12274)
  fix(async): register the git prompt async handler correctly (ohmyzsh#12267)
  fix(git): disable temporarely async prompt
  feat(async)!: implement async prompt API and apply to git prompt (ohmyzsh#12257)
  feat(tools): update `supports_hyperlinks` (ohmyzsh#12258)
  chore(gitfast): remove update script (ohmyzsh#12262)
  perf(nvm): don't call `nvm version` on every cd
  feat(nvm)!: make `lazy` and `autoload` options compatible
  fix(nvm): remove zsh completion
  fix(terraform): fix completion repeating flags with value (ohmyzsh#12256)
  fix(terraform): pass `-chdir` to completion commands (ohmyzsh#12254)
  feat(python): add auto venv activation (ohmyzsh#12248)
  feat(terraform): update completion to `v1.7` (ohmyzsh#12252)
  ...
gerardo pushed a commit to gerardo/oh-my-zsh that referenced this pull request Mar 19, 2024
* upstream/master: (212 commits)
  fix(docker-compose): completion regression (ohmyzsh#12288)
  feat(gradle): update completion to version 25da917c (ohmyzsh#12287)
  fix(dependencies): copy gradle LICENSE
  feat(dependencies): enable gradle plugin
  docs: fix typos (ohmyzsh#12284)
  docs(pyenv): fix typo (ohmyzsh#12283)
  feat(extract): prefer using `pbzip2` instead of `bunzip2` (ohmyzsh#12280)
  docs(readme): add contributor list (ohmyzsh#12236)
  feat(fzf): add default fzf_base for msys2 (ohmyzsh#12274)
  fix(async): register the git prompt async handler correctly (ohmyzsh#12267)
  fix(git): disable temporarely async prompt
  feat(async)!: implement async prompt API and apply to git prompt (ohmyzsh#12257)
  feat(tools): update `supports_hyperlinks` (ohmyzsh#12258)
  chore(gitfast): remove update script (ohmyzsh#12262)
  perf(nvm): don't call `nvm version` on every cd
  feat(nvm)!: make `lazy` and `autoload` options compatible
  fix(nvm): remove zsh completion
  fix(terraform): fix completion repeating flags with value (ohmyzsh#12256)
  fix(terraform): pass `-chdir` to completion commands (ohmyzsh#12254)
  feat(python): add auto venv activation (ohmyzsh#12248)
  ...
fdelacruz pushed a commit to fdelacruz/ohmyzsh that referenced this pull request Mar 27, 2024
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
pull bot pushed a commit to kis87988/ohmyzsh that referenced this pull request Mar 27, 2024
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
lukaselmer pushed a commit to lukaselmer/ohmyzsh that referenced this pull request Apr 16, 2024
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
cschuyle pushed a commit to cschuyle/ohmyzsh that referenced this pull request Apr 18, 2024
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: plugin Issue or PR related to a plugin Type: documentation Documentation issue or Pull Request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants