gforsyth / xonda

DEPRECATED: (previously a thin wrapper around conda for xonsh)
BSD 3-Clause "New" or "Revised" License
11 stars 9 forks source link

tab completion creates exception #39

Closed michaelaye closed 5 years ago

michaelaye commented 5 years ago

I'm not sure this is supported, but I'm trying env-name tab completion, and whenever I try it I get this:

Unhandled exception in event loop:
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
    new_f = coroutine.throw(exc)
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1648, in new_coroutine
    yield From(coroutine(*a, **kw))
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
    new_f = coroutine.throw(exc)
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1500, in async_completer
    cancel=lambda: not proceed()))
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py", line 86, in step_next
    new_f = coroutine.send(None)
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/eventloop/async_generator.py", line 114, in consume_async_generator
    item = iterator.send(send)
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 166, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/xonsh/ptk2/completer.py", line 45, in get_completions
    prefix, line_ex, begidx + expand_offset, endidx + expand_offset, self.ctx
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 125, in complete
    out = func(prefix, line, begidx, endidx, ctx)
  File "/Users/klay6683/src/xonda/xontrib/xonda.xsh", line 156, in _xonda_completer
    possible = set([env.name for env in _get_envs()])
  File "/Users/klay6683/src/xonda/xontrib/xonda.xsh", line 38, in _get_envs
    for envs_dir in config.envs_dirs:
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 317, in __getattribute__
    obj = self._lazy_obj()
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 309, in _lazy_obj
    obj = d["load"]()
  File "/Users/klay6683/src/xonda/xontrib/xonda.xsh", line 19, in config
    return importlib.import_module('conda.config')
  File "/Users/klay6683/miniconda3/envs/py37/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked

Exception No module named 'conda'
Press ENTER to continue...

I did type: conda act<tab> which completes to conda activate I then added conda activate p<tab> to get a list of my environments starting with p, at which point the above Exception occurred. I have 0.8.0 installed, says xpip, on my macOS 10.13.6, using a conda 3.7 env.

michaelaye commented 5 years ago

I just realized that it doesn't seem to work at all:

(py37) klay6683@MacL2938 ~/src/xonda master $ conda activate py36
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
ModuleNotFoundError: No module named 'conda'

and that's with XONSH_SHOW_TRACEBACK==True already.

gforsyth commented 5 years ago

Thanks for reporting @michaelaye -- can you post the output of which conda from within the py37 environment?

michaelaye commented 5 years ago

before loading xonda:

(py37) klay6683@MacL2938 ~/Dropbox/src $ which -v conda
/Users/klay6683/miniconda3/bin/conda (from PATH element 0)

after loading xonda:

(py37) klay6683@MacL2938 ~/Dropbox/src $ which -v conda
Type:             function
String form:      <function _xonda at 0x10b3d3ae8>
File:             /Users/klay6683/src/xonda/xontrib/xonda.xsh
Definition:       (args, stdin=None)
Source:
def _xonda(args, stdin=None):
    """
    If command is neither _activate nor _deactivate, just shell out to conda"""
    if len(args) == 2 and args[0] in ['activate', 'select']:
        _activate(args[1])
    elif len(args) == 1 and args[0] is 'deactivate':
        _deactivate()
    elif len(args) > 0:
        @$(which -s conda) @(args)
    elif len(args) == 0:
        @$(which -s conda) -h
    else:
        return

Class docstring:
Create a function object.

code
  a code object
globals
  the globals dictionary
name
  a string that overrides the name from the code object
argdefs
  a tuple that specifies the default argument values
closure
  a tuple that supplies the bindings for free variables

/Users/klay6683/miniconda3/envs/py37/lib/python3.7/site-packages/xonsh/__amalgam__.py:18196: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
  hdef = oname + inspect.formatargspec(*getargspec(obj))
aliases['conda'] = <function _xonda at 0x10b3d3ae8>
gforsyth commented 5 years ago

Ahh, ok -- I think I see what's going on. There's a sort of implicit assumption that xonda is installed into the root conda environment. But that's easy to work around I think

Can you conda install conda inside of the py37 environment? Or if that raises an error, you can do a conda install -n py37 conda from the base environment.

michaelaye commented 5 years ago

hm, that's an added complexity i'm not sure i'm willing to add to my work process. i'm keeping the base environment (formerly known as 'root') at the defaults channel, but all my envs are from conda-forge. Sometimes the conda's offered at conda-forge go out of sync with the defaults channel, but I don't want to deal with differently behaving condas per [edit:] env, that's just too much.

michaelaye commented 5 years ago

would it help if I add xonda to the 'base' env instead?

gforsyth commented 5 years ago

Yes, that should do it

michaelaye commented 5 years ago

no change. still getting same error as described above.

gforsyth commented 5 years ago

You need to have a conda installed in the same environment as xonsh is installed. There's not really any way around that given how it's written right now.

michaelaye commented 5 years ago

but that's the case now. Both conda and xonda are installed in the 'base' env.

michaelaye commented 5 years ago
# packages in environment at /Users/klay6683/miniconda3:
#
# Name                    Version                   Build  Channel
asn1crypto                0.24.0                   py36_0  
ca-certificates           2018.03.07                    0  
certifi                   2018.8.24                py36_1  
cffi                      1.11.5           py36h6174b99_1  
chardet                   3.0.4                    py36_1  
conda                     4.5.11                   py36_0  
conda-env                 2.6.0                         1  
cryptography              2.3.1            py36hdbc3d79_0  
idna                      2.7                      py36_0  
libcxx                    4.0.1                h579ed51_0  
libcxxabi                 4.0.1                hebd6815_0  
libedit                   3.1.20170329         hb402a30_2  
libffi                    3.2.1                h475c297_4  
ncurses                   6.1                  h0a44026_0  
openssl                   1.0.2p               h1de35cc_0  
pip                       10.0.1                   py36_0  
pycosat                   0.6.3            py36h1de35cc_0  
pycparser                 2.19                     py36_0  
pyopenssl                 18.0.0                   py36_0  
pysocks                   1.6.8                    py36_0  
python                    3.6.6                hc167b69_0  
python.app                2                        py36_9  
readline                  7.0                  h1de35cc_5  
requests                  2.19.1                   py36_0  
ruamel_yaml               0.15.46          py36h1de35cc_0  
setuptools                40.4.3                   py36_0  
six                       1.11.0                   py36_1  
sqlite                    3.25.2               ha441bb4_0  
tk                        8.6.8                ha441bb4_0  
urllib3                   1.23                     py36_0  
wheel                     0.32.1                   py36_0  
xonda                     0.8.0                     <pip>
xz                        5.2.4                h1de35cc_4  
yaml                      0.1.7                hc338f04_2  
zlib                      1.2.11               hf3cbc9b_2  
gforsyth commented 5 years ago

Is xonsh also installed in that environment?

michaelaye commented 5 years ago

wow, what a mess. I added xonsh, which dragged these packages from 'defaults' channel into 'conda-forge':

ca-certificates
certifi
conda
openssl

then wanted to get xonda from 'conda-forge' to be consistent. Then realized that the conda-forge package of xonda still has the deprecation warning and hence I guess won't work with xonsh 0.8.0? So, then I wanted to remove xonda again, and it wants to uninstall those packages, even so they are dependents of xonsh?

$ conda remove xonda                                                           (base)
Solving environment: done

## Package Plan ##

  environment location: /Users/klay6683/miniconda3

  removed specs:
    - xonda

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2018.8.24          |           py36_1         139 KB

The following packages will be REMOVED:

    xonda:           0.2.5-py_0           conda-forge

The following packages will be DOWNGRADED:

    ca-certificates: 2018.8.24-ha4d7672_0 conda-forge --> 2018.03.07-0
    certifi:         2018.8.24-py36_1001  conda-forge --> 2018.8.24-py36_1
    conda:           4.5.11-py36_1000     conda-forge --> 4.5.11-py36_0
    openssl:         1.0.2p-h470a237_1    conda-forge --> 1.0.2p-h1de35cc_0

Bizarre.

gforsyth commented 5 years ago

I just merged the conda-forge PR for the updated xonda so that should be available soonish (depending on what the conda-forge build queues are like right now).

michaelaye commented 5 years ago

ha, almost there! The environment now was found and I could activate it, but it threw another deprecation warning (with xonda installed from today's GH master):

(base) klay6683@MacL2938 ~/Dropbox/src $ conda activate p/Users/klay6683/miniconda3/lib/python3.6/site-packages/xonsh/__amalgam__.py:22538: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  rtn = self.loader.exec_module(module)
michaelaye commented 5 years ago

Found another bug, but that's a new issue.

michaelaye commented 5 years ago

after this deprecation warning was issued, i now can cleanly change envs with using tab, thanks! (Just the 'base' env is missing).

gforsyth commented 5 years ago

Ok! So it should work now and it will only throw that warning the first time -- that's an issue with xonsh right now that we need to limit the deprecation warnings to only xonsh-related stuff

gforsyth commented 5 years ago

Sorry for the environment mess, but I'm glad it's working!

michaelaye commented 5 years ago

There's a caveat to this solution: If I come from my py37 environment in fish and launch xonsh there, it still throws the initial error. I have to activate the base env in fish first and THEN launch fish to make things work. No changes in the PATH definition here. Maybe I can force things to work somehow with the PATH? But the miniconda/bin is already first thing in the PATH, don't know what else could be done.