Advertisement
Guest User

Untitled

a guest
May 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. " import xonsh.execer, importnb, IPython\n",
  10. "\n",
  11. " execer = xonsh.execer.Execer()\n",
  12. "\n",
  13. " shell = get_ipython()\n",
  14. "\n",
  15. " "
  16. ]
  17. },
  18. {
  19. "cell_type": "code",
  20. "execution_count": 2,
  21. "metadata": {},
  22. "outputs": [],
  23. "source": [
  24. " class Xonsh(importnb.Notebook):\n",
  25. " extensions = '.xo.ipynb',\n",
  26. " def parse(self, body): return execer._parse_ctx_free(body, 'exec', self.path)[0]\n",
  27. " "
  28. ]
  29. },
  30. {
  31. "cell_type": "code",
  32. "execution_count": 4,
  33. "metadata": {},
  34. "outputs": [
  35. {
  36. "data": {
  37. "text/plain": [
  38. "<module 'thingy' from '/Users/tonyfast/pidgin/thingy.xo.ipynb'>"
  39. ]
  40. },
  41. "execution_count": 4,
  42. "metadata": {},
  43. "output_type": "execute_result"
  44. }
  45. ],
  46. "source": [
  47. " with Xonsh():\n",
  48. " import thingy\n",
  49. " \n",
  50. " thingy"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 2,
  56. "metadata": {},
  57. "outputs": [],
  58. "source": [
  59. " class CachingCompiler(IPython.core.compilerop.CachingCompiler):\n",
  60. " def ast_parse(self, source, filename='<unknown>', symbol='exec'):\n",
  61. " global execer\n",
  62. " return execer._parse_ctx_free(source, symbol, filename)[0]"
  63. ]
  64. },
  65. {
  66. "cell_type": "code",
  67. "execution_count": 3,
  68. "metadata": {},
  69. "outputs": [],
  70. "source": [
  71. " def load_ipython_extension(shell): shell.compile = CachingCompiler()\n",
  72. "\n",
  73. " def unload_ipython_extension(shell): shell.compile = IPython.core.compilerop.CachingCompiler\n",
  74. " if __name__ == '__main__':\n",
  75. " load_ipython_extension(shell)"
  76. ]
  77. },
  78. {
  79. "cell_type": "code",
  80. "execution_count": 4,
  81. "metadata": {},
  82. "outputs": [
  83. {
  84. "data": {
  85. "text/plain": [
  86. "'/Users/tonyfast'"
  87. ]
  88. },
  89. "execution_count": 4,
  90. "metadata": {},
  91. "output_type": "execute_result"
  92. }
  93. ],
  94. "source": [
  95. " $HOME"
  96. ]
  97. },
  98. {
  99. "cell_type": "code",
  100. "execution_count": 7,
  101. "metadata": {},
  102. "outputs": [
  103. {
  104. "name": "stdout",
  105. "output_type": "stream",
  106. "text": [
  107. "hi\n"
  108. ]
  109. },
  110. {
  111. "data": {
  112. "text/plain": []
  113. },
  114. "execution_count": 7,
  115. "metadata": {},
  116. "output_type": "execute_result"
  117. }
  118. ],
  119. "source": [
  120. "echo hi"
  121. ]
  122. }
  123. ],
  124. "metadata": {
  125. "kernelspec": {
  126. "display_name": "p6",
  127. "language": "python",
  128. "name": "other-env"
  129. },
  130. "language_info": {
  131. "codemirror_mode": {
  132. "name": "ipython",
  133. "version": 3
  134. },
  135. "file_extension": ".py",
  136. "mimetype": "text/x-python",
  137. "name": "python",
  138. "nbconvert_exporter": "python",
  139. "pygments_lexer": "ipython3",
  140. "version": "3.6.8"
  141. }
  142. },
  143. "nbformat": 4,
  144. "nbformat_minor": 4
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement