-
-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there a way to run xonsh from .py script as .xsh script? #2478
Comments
Xonsh scripts must be compiled as xonsh in order to run. However, importing |
I've found closest solution:
It works for both: Is there a better way without the |
Write a trampoline script that imports |
It's a bit strange to use |
If you want to execute xonsh scripts directly, you have to use xonsh. If you want to call xonsh code from python, you must first bootstrap the xonsh parser. |
I don't get the difference. Is that call is a call My point was to use single file of |
Xonsh can perfectly understand xonsh and python files. |
Then why i need to bootstrap anything? |
Your original question was to get |
Yes. But then i have to move a half of logic to another file with |
Sorry, we don't have a magic way to recompile the file in the middle of its own execution. |
But why not? Is there a function to do so? Or may be i am asking too much? |
In summary: That's a research thesis, and we're a small team of volunteers. |
I thought it could be solved somehow via on runtime self compilation to different bytecode w/o any injection to existing one and start execution a new one from beginning. But of cause it has sense only when the runtime runs from a script. |
If you know enough about Python interpreter internals to make it happen, pull requests are always welcome. |
Closing this as I believe the question is answered, but please re-open if there are further points/questions! |
There is no editor/ide support for xonsh xsh files. So is it possible to import some of the conveniences of xonsh into python, what I mean is eg:
So you don't get the convenient syntax of xonsh but just a few of it's convenient functions etc. |
This is somewhat undocumented, but if you want to start up a xonsh environment, for 3rd party packages, I often put the following in the from xonsh.main import setup
setup()
del setup This is safely reentrant and will set up the xonsh session object for you, if it hasn't been already. Here is an example in the wild: https://github.com/regro/rever/blob/master/rever/__init__.py |
Thank you, this works! |
Awesome! We should really add this to the docs.... |
Here my documentation effort: Can I call xonsh from my python project?Sure, suppose you have some xonsh files # __init__.py
from xonsh.main import setup
setup()
del setup in the directory
then you can import eg. # ./python_file.py
from my_xonsh_directory import file1 |
Thanks, I have already opened #3332 for more docs here |
I want to pack xonsh instructions under the
.py
extension to run xonsh as usual python script:python myscript.py
There
myscript.py
is something like this:Is there a way to do so?
The text was updated successfully, but these errors were encountered: