jnoortheen / xontrib-avox-poetry

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

Default virtualenv dir doesn't look right #5

Closed Queuecumber closed 2 years ago

Queuecumber commented 2 years ago

Poetry configures something like:

~/.cache/pypoetry/virtualenvs

as the default virtualenv dir not ~/.virtualenvs

So if you try to load this plugin it wont work with a vanilla poetry setup.

  1. Does it make sense to change this?
  2. Does it make sense to add some error messages about this? I had no idea what was going wrong until I starting working through the code with print statements
  3. I think falling back to poetry env info -p if you know the user is in a poetry project directory but can't find anything manually is probably a good idea. Right now I don't know if the code can ever hit this option because the "no venvs" option will get hit first and return

Also I'm pretty sure line 64 should explicitly return None instead of just being a return statement

jnoortheen commented 2 years ago
  1. it is the directory used by vox by default as well. I don't want to change this. It is better set explicitly to change poetry's behavior
  2. It would be better to do the "3" and find the venv path using poetry env info -p
Queuecumber commented 2 years ago

for (1) I may be misunderstanding the purpose of this plugin, I thought it was to automatically activate poetry venv when CDing into a poetry controlled project folder, in which case why would we care about the default vox folder, we would only care about the default poetry folder

For (2/3) I agree with you

jnoortheen commented 2 years ago
  1. I see this as a vox plugin that supports poetry created environments. I personally use the vox commands to delete/upgrade the poetry environments. It auto-completes when kept in the same place.
jnoortheen commented 2 years ago

I have released a new version with the fix. It will fallback to poetry env.

Queuecumber commented 2 years ago

This fails with the following exception (which was initially hidden by a contextmanager that I had to comment out)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.10/subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'

poetry commands work fine when run in the xsh shell

Queuecumber commented 2 years ago

Seems like it needs a full path, changing it to p = Path(run("/home/max/.local/bin/poetry", "env", "info", "-p")) works

Queuecumber commented 2 years ago

Seems like you want from xonsh.lib.subprocess import check_output instead of the one from pythons subprocess library so that it gets resolved using the $PATH set in xonsh

Queuecumber commented 2 years ago

I see this as a vox plugin that supports poetry created environments. I personally use the vox commands to delete/upgrade the poetry environments. It auto-completes when kept in the same place.

Cant the existing autovox plugin handle that? I haven't used xonsh long so I don't know for sure how it works. How do you use the vox commands to create poetry environments?

jnoortheen commented 2 years ago

The env is created by poetry but under $VIRTUALENV_HOME, and it is detected by this plugin. Autovox was slow in my case, so I created this one.