jnoortheen / xontrib-avox-poetry

auto-activate venv as one cd into a poetry project
MIT License
3 stars 2 forks source link

Missing deactivation #3

Open brechtm opened 3 years ago

brechtm commented 3 years ago

I was assuming avox-poetry would automatically deactivate the virtual environment in line with similar utilities. Is this planned?

Without this, I'm left wondering how I can manually deactivate the virtualenv since no avox-poetry doesn't seem to provide a deactivate function/alias.

Thanks!

jnoortheen commented 3 years ago

When I leave the parent/project directory, I don't think deactivating virtualenv is necessary. I have a shortcut to assigned to execute vox deactivate. This helps when creating new venv while another venv is active. But PR is welcome to implement this feature. Something that is optional and can be enabled with a setting/env-variable.

brechtm commented 3 years ago

I just discovered that the .venv autovox policy example from the xonsh documentation deactivates the virtualenv on leaving the project directory[1]. Since I have set virtualenvs.in-project = true, this works well enough for me.

[1] Just paste the autovox policy code into .xonshrc

rpdelaney commented 2 years ago

@brechtm Is that still true? Adding that policy doesn't seem to help. Perhaps the page changed? Can you paste the code you used?

brechtm commented 2 years ago

@rpdelaney It doesn't look like the code snippet changed. I did add support for other venv directory names though:

@events.autovox_policy
def dotvenv_policy(path, **_):
    for dirname in ['.venv', 'venv', 'env']:
        venv_path = path / dirname
        if venv_path.exists():
            return venv_path

Note that you do need to load the vox and autovox xontribs as well:

xontrib load vox autovox
rpdelaney commented 2 years ago

Thank you. My problem was that I had not loaded the vox xontrib.

It might be reasonable for xontribs to load their own dependencies, but I'm not sure. It's something worth considering. What do you think, @jnoortheen ?

jnoortheen commented 2 years ago

I didn't wanted to use avox for poetry, it recursively scans all parent folders and was slow on my system. So I ended up creating my own implementation. As I have told earlier, I am happy to accept PRs implementing a deactivate function. But that will complicate when the user has left the directory. If that is completely optional and doesn't affect the prompt performance, then it will be good.