gforsyth / xonda

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

Use `os.scandir` to list the environments directories #6

Closed StreakyCobra closed 7 years ago

StreakyCobra commented 7 years ago

This fix a bug when ls is aliased by the user.

Signed-off-by: Fabien Dubosson fabien.dubosson@gmail.com

gforsyth commented 7 years ago

Thanks for putting this in @StreakyCobra! Trouble in the context manager, though...

conda activate Exception in thread Thread-50:
Traceback (most recent call last):
  File "/home/gil/miniconda3/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/home/gil/miniconda3/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/gil/miniconda3/lib/python3.5/site-packages/prompt_toolkit/interface.py", line 840, in run
    completions = list(buffer.completer.get_completions(document, complete_event))
  File "/home/gil/miniconda3/lib/python3.5/site-packages/xonsh/ptk/completer.py", line 49, in get_compls
    self.ctx)
  File "/home/gil/miniconda3/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 122, in complete
    out = func(prefix, line, begidx, endidx, ctx)
  File "/home/gil/git/xonda/xontrib/xonda.xsh", line 118, in _xonda_completer
    possible = set([env.name for env in _get_envs()])
  File "/home/gil/git/xonda/xontrib/xonda.xsh", line 31, in _get_envs
    for env_name in _list_dirs(envs_dir):
  File "/home/gil/git/xonda/xontrib/xonda.xsh", line 12, in _list_dirs
    with os.scandir(path) as it:
AttributeError: __exit__
StreakyCobra commented 7 years ago

Uh? I don't have this. It is due to python version (3.5 vs 3.6)?

gforsyth commented 7 years ago

Ahh, I bet that's a 3.5 v 3.6 thing, yes. How about

for entry in os.scandir(path):
    if not entry.name.startswith('.') and entry.is_dir():
        yield entry.name

?

gforsyth commented 7 years ago

That works on my end on 3.5 and we do want to maintain compatibility.

StreakyCobra commented 7 years ago

Would be fine for me, I just copy/pasted foolishly the code from the python3.6 os doc page ^^

gforsyth commented 7 years ago

Ok -- would you like to put in the change?

StreakyCobra commented 7 years ago

Done :D (I'm so fast) :joy:


Kidding, I was already pushing it in :-)

gforsyth commented 7 years ago

Thanks, @StreakyCobra !