dyuri / xontrib-langenv Goto Github PK
View Code? Open in Web Editor NEWpyenv integration for xonsh
License: MIT License
pyenv integration for xonsh
License: MIT License
While checking why pyenv init is so slow, I've realized that your xontrib runs it twice for no reason since the full init already provides PATH
PYENV_PATH = $(@(PYENV) init --path) # this is not needed since โ already includes `export PATH`
PYENV_ENV = $(@(PYENV) init -)
Also there is another trick to speed it up via pyenv init - --no-rehash
instead of the regular init
pyenv/pyenv#1970
DEPRECATION: xontrib-langenv is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at pypa/pip#8559
pyenv shell
is supposed to echo "$PYENV_VERSION"
for bash to print the actual version (if the version is defined), but in this plugin nothing is printed
It might be xonsh-related, not specific to this plugin since
source-bash --suppress-skip-message -n "echo 1"
doesn't print 1
(asked this question in xonsh discussions xonsh/xonsh#5019)I tried installing this in my latest ubuntu 22.04 and I added it in .xonshrc
file.
Now if I open the terminal it immediately closes within a blink of an eye.
However, I managed to get the output:
(Actually in order to make it work I added source-bash ~/.bashrc
& .profile
on top of the .xonshrc) but without them I was getting source-foreign error
I forked and now have nodenv and goenv working (tackling rbenv
now).
Would you like to rename yours and included these in a generic pygonerb
env repo?
I could do the others as separate pip packages, but I'd prefer to collaborate with you.
Here's my changes
(check this fork https://github.com/eugenesvk/xontrib-langenv/tree/repy_skip_bash
it further improves the branch mentioned in #13)
Given that all the langenv tools are the same and only need two special 'rehash','shell'
alias commands it's better to just set the alias directly in xonsh instead of calling those slow bash shells to get this information
Also, the two /shims
path and PYENV_SHELL
can be set directly as we know what the output for our shell will be and the shims are at the PYENV_ROOT
or a known default
So I've adjusted the base/pyenv functions to completely avoid calling bash in the init stage with a good startup speedup due to this. Now bash is only called when you invoke the two sh-
commands
See xonsh/xonsh#3610
pierre@kth ~ $ source-bash ~/Dev/env_xonsh/bin/activate
(env_xonsh) pierre@kth ~ $ $XONSH_DEBUG=1
(env_xonsh) pierre@kth ~ $ $XONSH_SHOW_TRACEBACK = True
(env_xonsh) pierre@kth ~ $ xonsh
Hello Pierre!
^Z
(env_xonsh) pierre@kth ~ $ xontrib load pyenv
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22033, in _run_binary
p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 14147, in __init__
self.proc = proc = subprocess.Popen(
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pyenv\n'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 15421, in __init__
proc = spec.run(pipeline_group=pipeline_group)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22022, in run
p = self._run_binary(kwargs)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22046, in _run_binary
sug = suggest_commands(cmd0, env, builtins.aliases)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 5293, in suggest_commands
c = command_not_found(cmd)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 5241, in command_not_found
s = subprocess.check_output(
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '/usr/lib/command-not-found pyenv
; exit 0' returned non-zero exit status 2.
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22033, in _run_binary
p = self.cls(self.cmd, bufsize=bufsize, **kwargs)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 14147, in __init__
self.proc = proc = subprocess.Popen(
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pyenv\n'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 15421, in __init__
proc = spec.run(pipeline_group=pipeline_group)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22022, in run
p = self._run_binary(kwargs)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 22046, in _run_binary
sug = suggest_commands(cmd0, env, builtins.aliases)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 5293, in suggest_commands
c = command_not_found(cmd)
File "/usr/lib/python3/dist-packages/xonsh/__amalgam__.py", line 5241, in command_not_found
s = subprocess.check_output(
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '/usr/lib/command-not-found pyenv
; exit 0' returned non-zero exit status 2.
Since xonsh xontribs are not compiled unlike the .py ones, so take slower to start xonsh/xonsh#3953, it might make sense to rewrite this xontrib in Python?
I've taken a stab at it by changing the pyenv
version (and the langenv_common
) in this fork https://github.com/eugenesvk/xontrib-langenv/tree/repy, besides conversion I've also didn't understand why there is a need to search for tools themselves (not their shims) that are supposed to be in PATH already if they're properly installed, so just replaced it ;) with a lazy search of known xonsh binaries
upd: seems to be working, also #14 is fixed
However, I don't get how source-bash
works, it doesn't print anything even in the regular subprocess, e.g. source-bash --suppress-skip-message -n "echo 1"
doesn't print 1
, so in the create_alias
function when you do pyenv shell
which ultimately goes to source-bash
to source echo $PYTHON_VERSION
, nothing is printed even if said variable exists
asked this question in xonsh discussions xonsh/xonsh#5019
Thanks for resolving the last issue, I was facing. After the latest version and the new system I am getting mentioned error:
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh: subprocess mode: command not found: ForeignShellFunctionAlias(extra_args=(), funcname='pyenv', shell='bash')
foreignshellfunctionalias(extra_args=(), funcname='pyenv', shell='bash'): command not found
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh: subprocess mode: command not found: ForeignShellFunctionAlias(extra_args=(), funcname='pyenv', shell='bash')
foreignshellfunctionalias(extra_args=(), funcname='pyenv', shell='bash'): command not found
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh: subprocess mode: command not found: ForeignShellFunctionAlias(extra_args=(), funcname='pyenv', shell='bash')
foreignshellfunctionalias(extra_args=(), funcname='pyenv', shell='bash'): command not found
Any guesses?
Thanks :)
I think this also needs -n
to skip the loading bash environment (not only is it slow, but can override your env vars)
The error when starting shell:
usage: source-bash [-h] [-n] [-l] [--envcmd ENVCMD] [--aliascmd ALIASCMD]
[--extra-args EXTRA_ARGS] [-u] [-p PREVCMD]
[--postcmd POSTCMD] [--funcscmd FUNCSCMD]
[--sourcer SOURCER] [--use-tmpfile]
[--seterrprevcmd SETERRPREVCMD]
[--seterrpostcmd SETERRPOSTCMD] [--overwrite-aliases]
[--suppress-skip-message] [--show] [-d]
files_or_code [files_or_code ...]
source-bash: error: argument -l/--login: ignored explicit argument 'false'
Long form traceback
Traceback (most recent call last):
File "/home/mike/.xonshrc", line 101, in <module>
xontrib load coreutils distributed output_search docker_tabcomplete autovox pyenv # avox_poetry
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/built_ins.py", line 196, in subproc_captured_hiddenobject
return xonsh.procs.specs.run_subproc(cmds, captured="hiddenobject", envs=envs)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 3579, in run_subproc
command.end()
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 928, in end
self._end(tee_output=tee_output)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 936, in _end
for _ in self.tee_stdout():
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 838, in tee_stdout
for line in self.iterraw():
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 725, in iterraw
proc.wait()
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 2626, in wait
r = self.f(self.args, stdin, stdout, stderr, spec, spec.stack)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 767, in __call__
result = dispatch(
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 516, in dispatch
return _dispatch_func(func, ns)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 489, in _dispatch_func
return func(**kwargs)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 12521, in xontribs_load
update_context(name, ctx=ctx)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 12475, in update_context
modctx = xontrib_context(name)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 12440, in xontrib_context
m = importlib.import_module(spec.name)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xontrib/pyenv.xsh", line 39, in <module>
source-bash --login=false --interactive=false --suppress-skip-message @(PYENV_PATH) e>/dev/null
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/built_ins.py", line 196, in subproc_captured_hiddenobject
return xonsh.procs.specs.run_subproc(cmds, captured="hiddenobject", envs=envs)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 3579, in run_subproc
command.end()
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 928, in end
self._end(tee_output=tee_output)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 936, in _end
for _ in self.tee_stdout():
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 838, in tee_stdout
for line in self.iterraw():
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 725, in iterraw
proc.wait()
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/procs/__amalgam__.py", line 2626, in wait
r = self.f(self.args, stdin, stdout, stderr, spec, spec.stack)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 767, in __call__
result = dispatch(
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/site-packages/xonsh/__amalgam__.py", line 511, in dispatch
parsed = parser.parse_args(args)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 1818, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 1854, in parse_known_args
self.error(str(err))
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 2575, in error
self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 2562, in exit
_sys.exit(status)
SystemExit: 2
Traceback (most recent call last):
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 1851, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 2060, in _parse_known_args
start_index = consume_optional(start_index)
File "/home/mike/.pyenv/versions/3.9.6/lib/python3.9/argparse.py", line 1982, in consume_optional
raise ArgumentError(action, msg % explicit_arg)
argparse.ArgumentError: argument -l/--login: ignored explicit argument 'false'
My xonshrc:
https://github.com/meramsey/yadm-dotfiles/blob/main/.xonshrc
@ xonsh --version
xonsh/0.12.1
~ at 08:33:50
@
I was on xonsh v11 before with same file. I also uninstalled the legacy one and reinstalled the new one as outlined in
https://github.com/dyuri/xontrib-pyenv
Thanks in advance for your time.
Recent changes in pyenv require additional configuration besides sourcing pyenv init -
. See pyenv/pyenv#1906.
My workaround was to add the following to .xonshrc before xontrib load pyenv
:
source-bash --login=false --interactive=false $(pyenv init --path)
If pyenv-virtualenv is not installed, I get:
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
subprocess.CalledProcessError: Command '['bash', '-c', 'source "/home/pierre/.bashrc"\npyenv virtualenv-init -\n']' returned non-zero exit status 1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.