Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .DS_Store +0 -0
- .gitattributes +37 -0
- .venv/bin/debugpy +8 -0
- .venv/bin/f2py +8 -0
- .venv/bin/fonttools +8 -0
- .venv/bin/ipython +8 -0
- .venv/bin/ipython3 +8 -0
- .venv/bin/jsonschema +8 -0
- .venv/bin/jupyter +8 -0
- .venv/bin/jupyter-kernel +8 -0
- .venv/bin/jupyter-kernelspec +8 -0
- .venv/bin/jupyter-migrate +8 -0
- .venv/bin/jupyter-run +8 -0
- .venv/bin/jupyter-troubleshoot +8 -0
- .venv/bin/kaggle +8 -0
- .venv/bin/markdown-it +8 -0
- .venv/bin/numpy-config +8 -0
- .venv/bin/pyftmerge +8 -0
- .venv/bin/pyftsubset +8 -0
- .venv/bin/pygmentize +8 -0
- .venv/bin/slugify +8 -0
- .venv/bin/streamlit +8 -0
- .venv/bin/streamlit.cmd +16 -0
- .venv/bin/ttx +8 -0
- .venv/etc/jupyter/nbconfig/notebook.d/pydeck.json +5 -0
- .venv/lib/python3.9/site-packages/.DS_Store +0 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/AUTHORS +58 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/INSTALLER +1 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/LICENSE +29 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/METADATA +297 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/RECORD +82 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/WHEEL +5 -0
- .venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/top_level.txt +1 -0
- .venv/lib/python3.9/site-packages/IPython/__init__.py +162 -0
- .venv/lib/python3.9/site-packages/IPython/__main__.py +15 -0
- .venv/lib/python3.9/site-packages/IPython/conftest.py +87 -0
- .venv/lib/python3.9/site-packages/IPython/consoleapp.py +12 -0
- .venv/lib/python3.9/site-packages/IPython/core/__init__.py +0 -0
- .venv/lib/python3.9/site-packages/IPython/core/alias.py +258 -0
- .venv/lib/python3.9/site-packages/IPython/core/application.py +488 -0
- .venv/lib/python3.9/site-packages/IPython/core/async_helpers.py +156 -0
- .venv/lib/python3.9/site-packages/IPython/core/autocall.py +70 -0
- .venv/lib/python3.9/site-packages/IPython/core/builtin_trap.py +86 -0
- .venv/lib/python3.9/site-packages/IPython/core/compilerop.py +214 -0
- .venv/lib/python3.9/site-packages/IPython/core/completer.py +0 -0
- .venv/lib/python3.9/site-packages/IPython/core/completerlib.py +374 -0
- .venv/lib/python3.9/site-packages/IPython/core/crashhandler.py +236 -0
- .venv/lib/python3.9/site-packages/IPython/core/debugger.py +1120 -0
- .venv/lib/python3.9/site-packages/IPython/core/display.py +1290 -0
- .venv/lib/python3.9/site-packages/IPython/core/display_functions.py +391 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -35,3 +35,40 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
kiva_loans.csv filter=lfs diff=lfs merge=lfs -text
|
| 37 |
loan_theme_ids.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
kiva_loans.csv filter=lfs diff=lfs merge=lfs -text
|
| 37 |
loan_theme_ids.csv filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
.venv/lib/python3.9/site-packages/PIL/.dylibs/libfreetype.6.dylib filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
.venv/lib/python3.9/site-packages/PIL/.dylibs/libharfbuzz.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
.venv/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_x86.pdb filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
.venv/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_attach_to_process/inject_dll_amd64.pdb filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
.venv/lib/python3.9/site-packages/debugpy/_vendored/pydevd/pydevd_attach_to_process/inject_dll_x86.pdb filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
.venv/lib/python3.9/site-packages/hf_transfer/hf_transfer.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
.venv/lib/python3.9/site-packages/numpy/_core/_multiarray_umath.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
.venv/lib/python3.9/site-packages/pandas/_libs/algos.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
.venv/lib/python3.9/site-packages/pandas/_libs/groupby.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
.venv/lib/python3.9/site-packages/pandas/_libs/hashtable.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
.venv/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
.venv/lib/python3.9/site-packages/pandas/_libs/join.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
.venv/lib/python3.9/site-packages/pyarrow/_compute.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
.venv/lib/python3.9/site-packages/pyarrow/_dataset.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
.venv/lib/python3.9/site-packages/pyarrow/_flight.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
.venv/lib/python3.9/site-packages/pyarrow/lib.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow_acero.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow_dataset.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow_flight.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow_python.dylib filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
.venv/lib/python3.9/site-packages/pyarrow/libarrow_substrait.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
.venv/lib/python3.9/site-packages/pyarrow/libparquet.1700.dylib filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
.venv/lib/python3.9/site-packages/pydeck/nbextension/static/index.js.map filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
.venv/lib/python3.9/site-packages/scipy/.dylibs/libgfortran.5.dylib filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
.venv/lib/python3.9/site-packages/scipy/.dylibs/libopenblas.0.dylib filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
.venv/lib/python3.9/site-packages/scipy/io/_fast_matrix_market/_fmm_core.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
.venv/lib/python3.9/site-packages/scipy/linalg/_flapack.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
.venv/lib/python3.9/site-packages/scipy/misc/face.dat filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
.venv/lib/python3.9/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
.venv/lib/python3.9/site-packages/scipy/sparse/_sparsetools.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
.venv/lib/python3.9/site-packages/scipy/special/_ufuncs.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
.venv/lib/python3.9/site-packages/scipy/special/cython_special.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
.venv/lib/python3.9/site-packages/scipy/stats/_unuran/unuran_wrapper.cpython-39-darwin.so filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
.venv/lib/python3.9/site-packages/zmq/.dylibs/libzmq.5.dylib filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
.venv/share/jupyter/nbextensions/pydeck/index.js.map filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
Assignment-2.ipynb filter=lfs diff=lfs merge=lfs -text
|
.venv/bin/debugpy
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from debugpy.server.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/f2py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy.f2py.f2py2e import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/fonttools
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/ipython
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from IPython import start_ipython
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(start_ipython())
|
.venv/bin/ipython3
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from IPython import start_ipython
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(start_ipython())
|
.venv/bin/jsonschema
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jsonschema.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/jupyter
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_core.command import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/jupyter-kernel
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_client.kernelapp import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/jupyter-kernelspec
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_client.kernelspecapp import KernelSpecApp
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(KernelSpecApp.launch_instance())
|
.venv/bin/jupyter-migrate
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_core.migrate import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/jupyter-run
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_client.runapp import RunApp
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(RunApp.launch_instance())
|
.venv/bin/jupyter-troubleshoot
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jupyter_core.troubleshoot import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/kaggle
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from kaggle.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/markdown-it
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from markdown_it.cli.parse import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/numpy-config
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy._configtool import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pyftmerge
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.merge import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pyftsubset
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.subset import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/pygmentize
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pygments.cmdline import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/slugify
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from slugify.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/streamlit
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from streamlit.web.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/bin/streamlit.cmd
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rem Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
|
| 2 |
+
rem
|
| 3 |
+
rem Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
rem you may not use this file except in compliance with the License.
|
| 5 |
+
rem You may obtain a copy of the License at
|
| 6 |
+
rem
|
| 7 |
+
rem http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
rem
|
| 9 |
+
rem Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
rem distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
rem See the License for the specific language governing permissions and
|
| 13 |
+
rem limitations under the License.
|
| 14 |
+
|
| 15 |
+
@echo OFF
|
| 16 |
+
python -m streamlit %*
|
.venv/bin/ttx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/bin/python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.ttx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
.venv/etc/jupyter/nbconfig/notebook.d/pydeck.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"load_extensions": {
|
| 3 |
+
"pydeck/extension": true
|
| 4 |
+
}
|
| 5 |
+
}
|
.venv/lib/python3.9/site-packages/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/AUTHORS
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GitPython was originally written by Michael Trier.
|
| 2 |
+
GitPython 0.2 was partially (re)written by Sebastian Thiel, based on 0.1.6 and git-dulwich.
|
| 3 |
+
|
| 4 |
+
Contributors are:
|
| 5 |
+
|
| 6 |
+
-Michael Trier <mtrier _at_ gmail.com>
|
| 7 |
+
-Alan Briolat
|
| 8 |
+
-Florian Apolloner <florian _at_ apolloner.eu>
|
| 9 |
+
-David Aguilar <davvid _at_ gmail.com>
|
| 10 |
+
-Jelmer Vernooij <jelmer _at_ samba.org>
|
| 11 |
+
-Steve Frécinaux <code _at_ istique.net>
|
| 12 |
+
-Kai Lautaportti <kai _at_ lautaportti.fi>
|
| 13 |
+
-Paul Sowden <paul _at_ idontsmoke.co.uk>
|
| 14 |
+
-Sebastian Thiel <byronimo _at_ gmail.com>
|
| 15 |
+
-Jonathan Chu <jonathan.chu _at_ me.com>
|
| 16 |
+
-Vincent Driessen <me _at_ nvie.com>
|
| 17 |
+
-Phil Elson <pelson _dot_ pub _at_ gmail.com>
|
| 18 |
+
-Bernard `Guyzmo` Pratz <guyzmo+gitpython+pub@m0g.net>
|
| 19 |
+
-Timothy B. Hartman <tbhartman _at_ gmail.com>
|
| 20 |
+
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
|
| 21 |
+
-Peter Jones <pjones _at_ redhat.com>
|
| 22 |
+
-Anson Mansfield <anson.mansfield _at_ gmail.com>
|
| 23 |
+
-Ken Odegard <ken.odegard _at_ gmail.com>
|
| 24 |
+
-Alexis Horgix Chotard
|
| 25 |
+
-Piotr Babij <piotr.babij _at_ gmail.com>
|
| 26 |
+
-Mikuláš Poul <mikulaspoul _at_ gmail.com>
|
| 27 |
+
-Charles Bouchard-Légaré <cblegare.atl _at_ ntis.ca>
|
| 28 |
+
-Yaroslav Halchenko <debian _at_ onerussian.com>
|
| 29 |
+
-Tim Swast <swast _at_ google.com>
|
| 30 |
+
-William Luc Ritchie
|
| 31 |
+
-David Host <hostdm _at_ outlook.com>
|
| 32 |
+
-A. Jesse Jiryu Davis <jesse _at_ emptysquare.net>
|
| 33 |
+
-Steven Whitman <ninloot _at_ gmail.com>
|
| 34 |
+
-Stefan Stancu <stefan.stancu _at_ gmail.com>
|
| 35 |
+
-César Izurieta <cesar _at_ caih.org>
|
| 36 |
+
-Arthur Milchior <arthur _at_ milchior.fr>
|
| 37 |
+
-Anil Khatri <anil.soccer.khatri _at_ gmail.com>
|
| 38 |
+
-JJ Graham <thetwoj _at_ gmail.com>
|
| 39 |
+
-Ben Thayer <ben _at_ benthayer.com>
|
| 40 |
+
-Dries Kennes <admin _at_ dries007.net>
|
| 41 |
+
-Pratik Anurag <panurag247365 _at_ gmail.com>
|
| 42 |
+
-Harmon <harmon.public _at_ gmail.com>
|
| 43 |
+
-Liam Beguin <liambeguin _at_ gmail.com>
|
| 44 |
+
-Ram Rachum <ram _at_ rachum.com>
|
| 45 |
+
-Alba Mendez <me _at_ alba.sh>
|
| 46 |
+
-Robert Westman <robert _at_ byteflux.io>
|
| 47 |
+
-Hugo van Kemenade
|
| 48 |
+
-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
|
| 49 |
+
-Julien Mauroy <pro.julien.mauroy _at_ gmail.com>
|
| 50 |
+
-Patrick Gerard
|
| 51 |
+
-Luke Twist <itsluketwist@gmail.com>
|
| 52 |
+
-Joseph Hale <me _at_ jhale.dev>
|
| 53 |
+
-Santos Gallegos <stsewd _at_ proton.me>
|
| 54 |
+
-Wenhan Zhu <wzhu.cosmos _at_ gmail.com>
|
| 55 |
+
-Eliah Kagan <eliah.kagan _at_ gmail.com>
|
| 56 |
+
-Ethan Lin <et.repositories _at_ gmail.com>
|
| 57 |
+
|
| 58 |
+
Portions derived from other open source works and are clearly marked.
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (C) 2008, 2009 Michael Trier and contributors
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions
|
| 6 |
+
are met:
|
| 7 |
+
|
| 8 |
+
* Redistributions of source code must retain the above copyright
|
| 9 |
+
notice, this list of conditions and the following disclaimer.
|
| 10 |
+
|
| 11 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 12 |
+
notice, this list of conditions and the following disclaimer in the
|
| 13 |
+
documentation and/or other materials provided with the distribution.
|
| 14 |
+
|
| 15 |
+
* Neither the name of the GitPython project nor the names of
|
| 16 |
+
its contributors may be used to endorse or promote products derived
|
| 17 |
+
from this software without specific prior written permission.
|
| 18 |
+
|
| 19 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 20 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 21 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 22 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 23 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 24 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 25 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 26 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 27 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 28 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 29 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/METADATA
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: GitPython
|
| 3 |
+
Version: 3.1.43
|
| 4 |
+
Summary: GitPython is a Python library used to interact with Git repositories
|
| 5 |
+
Home-page: https://github.com/gitpython-developers/GitPython
|
| 6 |
+
Author: Sebastian Thiel, Michael Trier
|
| 7 |
+
Author-email: byronimo@gmail.com, mtrier@gmail.com
|
| 8 |
+
License: BSD-3-Clause
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Environment :: Console
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 13 |
+
Classifier: Operating System :: OS Independent
|
| 14 |
+
Classifier: Operating System :: POSIX
|
| 15 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 16 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 17 |
+
Classifier: Typing :: Typed
|
| 18 |
+
Classifier: Programming Language :: Python
|
| 19 |
+
Classifier: Programming Language :: Python :: 3
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 24 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 25 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 26 |
+
Requires-Python: >=3.7
|
| 27 |
+
Description-Content-Type: text/markdown
|
| 28 |
+
License-File: LICENSE
|
| 29 |
+
License-File: AUTHORS
|
| 30 |
+
Requires-Dist: gitdb <5,>=4.0.1
|
| 31 |
+
Requires-Dist: typing-extensions >=3.7.4.3 ; python_version < "3.8"
|
| 32 |
+
Provides-Extra: doc
|
| 33 |
+
Requires-Dist: sphinx ==4.3.2 ; extra == 'doc'
|
| 34 |
+
Requires-Dist: sphinx-rtd-theme ; extra == 'doc'
|
| 35 |
+
Requires-Dist: sphinxcontrib-applehelp <=1.0.4,>=1.0.2 ; extra == 'doc'
|
| 36 |
+
Requires-Dist: sphinxcontrib-devhelp ==1.0.2 ; extra == 'doc'
|
| 37 |
+
Requires-Dist: sphinxcontrib-htmlhelp <=2.0.1,>=2.0.0 ; extra == 'doc'
|
| 38 |
+
Requires-Dist: sphinxcontrib-qthelp ==1.0.3 ; extra == 'doc'
|
| 39 |
+
Requires-Dist: sphinxcontrib-serializinghtml ==1.1.5 ; extra == 'doc'
|
| 40 |
+
Requires-Dist: sphinx-autodoc-typehints ; extra == 'doc'
|
| 41 |
+
Provides-Extra: test
|
| 42 |
+
Requires-Dist: coverage[toml] ; extra == 'test'
|
| 43 |
+
Requires-Dist: ddt !=1.4.3,>=1.1.1 ; extra == 'test'
|
| 44 |
+
Requires-Dist: mypy ; extra == 'test'
|
| 45 |
+
Requires-Dist: pre-commit ; extra == 'test'
|
| 46 |
+
Requires-Dist: pytest >=7.3.1 ; extra == 'test'
|
| 47 |
+
Requires-Dist: pytest-cov ; extra == 'test'
|
| 48 |
+
Requires-Dist: pytest-instafail ; extra == 'test'
|
| 49 |
+
Requires-Dist: pytest-mock ; extra == 'test'
|
| 50 |
+
Requires-Dist: pytest-sugar ; extra == 'test'
|
| 51 |
+
Requires-Dist: typing-extensions ; (python_version < "3.11") and extra == 'test'
|
| 52 |
+
Requires-Dist: mock ; (python_version < "3.8") and extra == 'test'
|
| 53 |
+
|
| 54 |
+

|
| 55 |
+
[](https://readthedocs.org/projects/gitpython/?badge=stable)
|
| 56 |
+
[](https://repology.org/metapackage/python:gitpython/versions)
|
| 57 |
+
|
| 58 |
+
## [Gitoxide](https://github.com/Byron/gitoxide): A peek into the future…
|
| 59 |
+
|
| 60 |
+
I started working on GitPython in 2009, back in the days when Python was 'my thing' and I had great plans with it.
|
| 61 |
+
Of course, back in the days, I didn't really know what I was doing and this shows in many places. Somewhat similar to
|
| 62 |
+
Python this happens to be 'good enough', but at the same time is deeply flawed and broken beyond repair.
|
| 63 |
+
|
| 64 |
+
By now, GitPython is widely used and I am sure there is a good reason for that, it's something to be proud of and happy about.
|
| 65 |
+
The community is maintaining the software and is keeping it relevant for which I am absolutely grateful. For the time to come I am happy to continue maintaining GitPython, remaining hopeful that one day it won't be needed anymore.
|
| 66 |
+
|
| 67 |
+
More than 15 years after my first meeting with 'git' I am still in excited about it, and am happy to finally have the tools and
|
| 68 |
+
probably the skills to scratch that itch of mine: implement `git` in a way that makes tool creation a piece of cake for most.
|
| 69 |
+
|
| 70 |
+
If you like the idea and want to learn more, please head over to [gitoxide](https://github.com/Byron/gitoxide), an
|
| 71 |
+
implementation of 'git' in [Rust](https://www.rust-lang.org).
|
| 72 |
+
|
| 73 |
+
*(Please note that `gitoxide` is not currently available for use in Python, and that Rust is required.)*
|
| 74 |
+
|
| 75 |
+
## GitPython
|
| 76 |
+
|
| 77 |
+
GitPython is a python library used to interact with git repositories, high-level like git-porcelain,
|
| 78 |
+
or low-level like git-plumbing.
|
| 79 |
+
|
| 80 |
+
It provides abstractions of git objects for easy access of repository data often backed by calling the `git`
|
| 81 |
+
command-line program.
|
| 82 |
+
|
| 83 |
+
### DEVELOPMENT STATUS
|
| 84 |
+
|
| 85 |
+
This project is in **maintenance mode**, which means that
|
| 86 |
+
|
| 87 |
+
- …there will be no feature development, unless these are contributed
|
| 88 |
+
- …there will be no bug fixes, unless they are relevant to the safety of users, or contributed
|
| 89 |
+
- …issues will be responded to with waiting times of up to a month
|
| 90 |
+
|
| 91 |
+
The project is open to contributions of all kinds, as well as new maintainers.
|
| 92 |
+
|
| 93 |
+
### REQUIREMENTS
|
| 94 |
+
|
| 95 |
+
GitPython needs the `git` executable to be installed on the system and available in your
|
| 96 |
+
`PATH` for most operations. If it is not in your `PATH`, you can help GitPython find it
|
| 97 |
+
by setting the `GIT_PYTHON_GIT_EXECUTABLE=<path/to/git>` environment variable.
|
| 98 |
+
|
| 99 |
+
- Git (1.7.x or newer)
|
| 100 |
+
- Python >= 3.7
|
| 101 |
+
|
| 102 |
+
The list of dependencies are listed in `./requirements.txt` and `./test-requirements.txt`.
|
| 103 |
+
The installer takes care of installing them for you.
|
| 104 |
+
|
| 105 |
+
### INSTALL
|
| 106 |
+
|
| 107 |
+
GitPython and its required package dependencies can be installed in any of the following ways, all of which should typically be done in a [virtual environment](https://docs.python.org/3/tutorial/venv.html).
|
| 108 |
+
|
| 109 |
+
#### From PyPI
|
| 110 |
+
|
| 111 |
+
To obtain and install a copy [from PyPI](https://pypi.org/project/GitPython/), run:
|
| 112 |
+
|
| 113 |
+
```sh
|
| 114 |
+
pip install GitPython
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
(A distribution package can also be downloaded for manual installation at [the PyPI page](https://pypi.org/project/GitPython/).)
|
| 118 |
+
|
| 119 |
+
#### From downloaded source code
|
| 120 |
+
|
| 121 |
+
If you have downloaded the source code, run this from inside the unpacked `GitPython` directory:
|
| 122 |
+
|
| 123 |
+
```sh
|
| 124 |
+
pip install .
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
#### By cloning the source code repository
|
| 128 |
+
|
| 129 |
+
To clone the [the GitHub repository](https://github.com/gitpython-developers/GitPython) from source to work on the code, you can do it like so:
|
| 130 |
+
|
| 131 |
+
```sh
|
| 132 |
+
git clone https://github.com/gitpython-developers/GitPython
|
| 133 |
+
cd GitPython
|
| 134 |
+
./init-tests-after-clone.sh
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
On Windows, `./init-tests-after-clone.sh` can be run in a Git Bash shell.
|
| 138 |
+
|
| 139 |
+
If you are cloning [your own fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), then replace the above `git clone` command with one that gives the URL of your fork. Or use this [`gh`](https://cli.github.com/) command (assuming you have `gh` and your fork is called `GitPython`):
|
| 140 |
+
|
| 141 |
+
```sh
|
| 142 |
+
gh repo clone GitPython
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
Having cloned the repo, create and activate your [virtual environment](https://docs.python.org/3/tutorial/venv.html).
|
| 146 |
+
|
| 147 |
+
Then make an [editable install](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs):
|
| 148 |
+
|
| 149 |
+
```sh
|
| 150 |
+
pip install -e ".[test]"
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
In the less common case that you do not want to install test dependencies, `pip install -e .` can be used instead.
|
| 154 |
+
|
| 155 |
+
#### With editable *dependencies* (not preferred, and rarely needed)
|
| 156 |
+
|
| 157 |
+
In rare cases, you may want to work on GitPython and one or both of its [gitdb](https://github.com/gitpython-developers/gitdb) and [smmap](https://github.com/gitpython-developers/smmap) dependencies at the same time, with changes in your local working copy of gitdb or smmap immediatley reflected in the behavior of your local working copy of GitPython. This can be done by making editable installations of those dependencies in the same virtual environment where you install GitPython.
|
| 158 |
+
|
| 159 |
+
If you want to do that *and* you want the versions in GitPython's git submodules to be used, then pass `-e git/ext/gitdb` and/or `-e git/ext/gitdb/gitdb/ext/smmap` to `pip install`. This can be done in any order, and in separate `pip install` commands or the same one, so long as `-e` appears before *each* path. For example, you can install GitPython, gitdb, and smmap editably in the currently active virtual environment this way:
|
| 160 |
+
|
| 161 |
+
```sh
|
| 162 |
+
pip install -e ".[test]" -e git/ext/gitdb -e git/ext/gitdb/gitdb/ext/smmap
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
The submodules must have been cloned for that to work, but that will already be the case if you have run `./init-tests-after-clone.sh`. You can use `pip list` to check which packages are installed editably and which are installed normally.
|
| 166 |
+
|
| 167 |
+
To reiterate, this approach should only rarely be used. For most development it is preferable to allow the gitdb and smmap dependencices to be retrieved automatically from PyPI in their latest stable packaged versions.
|
| 168 |
+
|
| 169 |
+
### Limitations
|
| 170 |
+
|
| 171 |
+
#### Leakage of System Resources
|
| 172 |
+
|
| 173 |
+
GitPython is not suited for long-running processes (like daemons) as it tends to
|
| 174 |
+
leak system resources. It was written in a time where destructors (as implemented
|
| 175 |
+
in the `__del__` method) still ran deterministically.
|
| 176 |
+
|
| 177 |
+
In case you still want to use it in such a context, you will want to search the
|
| 178 |
+
codebase for `__del__` implementations and call these yourself when you see fit.
|
| 179 |
+
|
| 180 |
+
Another way assure proper cleanup of resources is to factor out GitPython into a
|
| 181 |
+
separate process which can be dropped periodically.
|
| 182 |
+
|
| 183 |
+
#### Windows support
|
| 184 |
+
|
| 185 |
+
See [Issue #525](https://github.com/gitpython-developers/GitPython/issues/525).
|
| 186 |
+
|
| 187 |
+
### RUNNING TESTS
|
| 188 |
+
|
| 189 |
+
_Important_: Right after cloning this repository, please be sure to have executed
|
| 190 |
+
the `./init-tests-after-clone.sh` script in the repository root. Otherwise
|
| 191 |
+
you will encounter test failures.
|
| 192 |
+
|
| 193 |
+
#### Install test dependencies
|
| 194 |
+
|
| 195 |
+
Ensure testing libraries are installed. This is taken care of already if you installed with:
|
| 196 |
+
|
| 197 |
+
```sh
|
| 198 |
+
pip install -e ".[test]"
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
If you had installed with a command like `pip install -e .` instead, you can still run
|
| 202 |
+
the above command to add the testing dependencies.
|
| 203 |
+
|
| 204 |
+
#### Test commands
|
| 205 |
+
|
| 206 |
+
To test, run:
|
| 207 |
+
|
| 208 |
+
```sh
|
| 209 |
+
pytest
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
To lint, and apply some linting fixes as well as automatic code formatting, run:
|
| 213 |
+
|
| 214 |
+
```sh
|
| 215 |
+
pre-commit run --all-files
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
This includes the linting and autoformatting done by Ruff, as well as some other checks.
|
| 219 |
+
|
| 220 |
+
To typecheck, run:
|
| 221 |
+
|
| 222 |
+
```sh
|
| 223 |
+
mypy
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
#### CI (and tox)
|
| 227 |
+
|
| 228 |
+
Style and formatting checks, and running tests on all the different supported Python versions, will be performed:
|
| 229 |
+
|
| 230 |
+
- Upon submitting a pull request.
|
| 231 |
+
- On each push, *if* you have a fork with GitHub Actions enabled.
|
| 232 |
+
- Locally, if you run [`tox`](https://tox.wiki/) (this skips any Python versions you don't have installed).
|
| 233 |
+
|
| 234 |
+
#### Configuration files
|
| 235 |
+
|
| 236 |
+
Specific tools are all configured in the `./pyproject.toml` file:
|
| 237 |
+
|
| 238 |
+
- `pytest` (test runner)
|
| 239 |
+
- `coverage.py` (code coverage)
|
| 240 |
+
- `ruff` (linter and formatter)
|
| 241 |
+
- `mypy` (type checker)
|
| 242 |
+
|
| 243 |
+
Orchestration tools:
|
| 244 |
+
|
| 245 |
+
- Configuration for `pre-commit` is in the `./.pre-commit-config.yaml` file.
|
| 246 |
+
- Configuration for `tox` is in `./tox.ini`.
|
| 247 |
+
- Configuration for GitHub Actions (CI) is in files inside `./.github/workflows/`.
|
| 248 |
+
|
| 249 |
+
### Contributions
|
| 250 |
+
|
| 251 |
+
Please have a look at the [contributions file][contributing].
|
| 252 |
+
|
| 253 |
+
### INFRASTRUCTURE
|
| 254 |
+
|
| 255 |
+
- [User Documentation](http://gitpython.readthedocs.org)
|
| 256 |
+
- [Questions and Answers](http://stackexchange.com/filters/167317/gitpython)
|
| 257 |
+
- Please post on Stack Overflow and use the `gitpython` tag
|
| 258 |
+
- [Issue Tracker](https://github.com/gitpython-developers/GitPython/issues)
|
| 259 |
+
- Post reproducible bugs and feature requests as a new issue.
|
| 260 |
+
Please be sure to provide the following information if posting bugs:
|
| 261 |
+
- GitPython version (e.g. `import git; git.__version__`)
|
| 262 |
+
- Python version (e.g. `python --version`)
|
| 263 |
+
- The encountered stack-trace, if applicable
|
| 264 |
+
- Enough information to allow reproducing the issue
|
| 265 |
+
|
| 266 |
+
### How to make a new release
|
| 267 |
+
|
| 268 |
+
1. Update/verify the **version** in the `VERSION` file.
|
| 269 |
+
2. Update/verify that the `doc/source/changes.rst` changelog file was updated. It should include a link to the forthcoming release page: `https://github.com/gitpython-developers/GitPython/releases/tag/<version>`
|
| 270 |
+
3. Commit everything.
|
| 271 |
+
4. Run `git tag -s <version>` to tag the version in Git.
|
| 272 |
+
5. _Optionally_ create and activate a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment). (Then the next step can install `build` and `twine`.)
|
| 273 |
+
6. Run `make release`.
|
| 274 |
+
7. Go to [GitHub Releases](https://github.com/gitpython-developers/GitPython/releases) and publish a new one with the recently pushed tag. Generate the changelog.
|
| 275 |
+
|
| 276 |
+
### Projects using GitPython
|
| 277 |
+
|
| 278 |
+
- [PyDriller](https://github.com/ishepard/pydriller)
|
| 279 |
+
- [Kivy Designer](https://github.com/kivy/kivy-designer)
|
| 280 |
+
- [Prowl](https://github.com/nettitude/Prowl)
|
| 281 |
+
- [Python Taint](https://github.com/python-security/pyt)
|
| 282 |
+
- [Buster](https://github.com/axitkhurana/buster)
|
| 283 |
+
- [git-ftp](https://github.com/ezyang/git-ftp)
|
| 284 |
+
- [Git-Pandas](https://github.com/wdm0006/git-pandas)
|
| 285 |
+
- [PyGitUp](https://github.com/msiemens/PyGitUp)
|
| 286 |
+
- [PyJFuzz](https://github.com/mseclab/PyJFuzz)
|
| 287 |
+
- [Loki](https://github.com/Neo23x0/Loki)
|
| 288 |
+
- [Omniwallet](https://github.com/OmniLayer/omniwallet)
|
| 289 |
+
- [GitViper](https://github.com/BeayemX/GitViper)
|
| 290 |
+
- [Git Gud](https://github.com/bthayer2365/git-gud)
|
| 291 |
+
|
| 292 |
+
### LICENSE
|
| 293 |
+
|
| 294 |
+
[3-Clause BSD License](https://opensource.org/license/bsd-3-clause/), also known as the New BSD License. See the [LICENSE file][license].
|
| 295 |
+
|
| 296 |
+
[contributing]: https://github.com/gitpython-developers/GitPython/blob/main/CONTRIBUTING.md
|
| 297 |
+
[license]: https://github.com/gitpython-developers/GitPython/blob/main/LICENSE
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/RECORD
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/__init__.cpython-39.pyc,,
|
| 2 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/cmd.cpython-39.pyc,,
|
| 3 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/compat.cpython-39.pyc,,
|
| 4 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/config.cpython-39.pyc,,
|
| 5 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/db.cpython-39.pyc,,
|
| 6 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/diff.cpython-39.pyc,,
|
| 7 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/exc.cpython-39.pyc,,
|
| 8 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/index/__init__.cpython-39.pyc,,
|
| 9 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/index/base.cpython-39.pyc,,
|
| 10 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/index/fun.cpython-39.pyc,,
|
| 11 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/index/typ.cpython-39.pyc,,
|
| 12 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/index/util.cpython-39.pyc,,
|
| 13 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/__init__.cpython-39.pyc,,
|
| 14 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/base.cpython-39.pyc,,
|
| 15 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/blob.cpython-39.pyc,,
|
| 16 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/commit.cpython-39.pyc,,
|
| 17 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/fun.cpython-39.pyc,,
|
| 18 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/submodule/__init__.cpython-39.pyc,,
|
| 19 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/submodule/base.cpython-39.pyc,,
|
| 20 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/submodule/root.cpython-39.pyc,,
|
| 21 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/submodule/util.cpython-39.pyc,,
|
| 22 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/tag.cpython-39.pyc,,
|
| 23 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/tree.cpython-39.pyc,,
|
| 24 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/objects/util.cpython-39.pyc,,
|
| 25 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/__init__.cpython-39.pyc,,
|
| 26 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/head.cpython-39.pyc,,
|
| 27 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/log.cpython-39.pyc,,
|
| 28 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/reference.cpython-39.pyc,,
|
| 29 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/remote.cpython-39.pyc,,
|
| 30 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/symbolic.cpython-39.pyc,,
|
| 31 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/refs/tag.cpython-39.pyc,,
|
| 32 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/remote.cpython-39.pyc,,
|
| 33 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/repo/__init__.cpython-39.pyc,,
|
| 34 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/repo/base.cpython-39.pyc,,
|
| 35 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/repo/fun.cpython-39.pyc,,
|
| 36 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/types.cpython-39.pyc,,
|
| 37 |
+
../../../../../../../Library/Caches/com.apple.python/Users/danielyammine/Desktop/AAU/CamillaBDS/.venv/lib/python3.9/site-packages/git/util.cpython-39.pyc,,
|
| 38 |
+
GitPython-3.1.43.dist-info/AUTHORS,sha256=h1TlPKfp05GA1eKQ15Yl4biR0C0FgivuGSeRA6Q1dz0,2286
|
| 39 |
+
GitPython-3.1.43.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 40 |
+
GitPython-3.1.43.dist-info/LICENSE,sha256=hvyUwyGpr7wRUUcTURuv3tIl8lEA3MD3NQ6CvCMbi-s,1503
|
| 41 |
+
GitPython-3.1.43.dist-info/METADATA,sha256=sAh3r1BMVw5_olGgDmpMS69zBpVr7UEOeRivNHKznfU,13376
|
| 42 |
+
GitPython-3.1.43.dist-info/RECORD,,
|
| 43 |
+
GitPython-3.1.43.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
| 44 |
+
GitPython-3.1.43.dist-info/top_level.txt,sha256=0hzDuIp8obv624V3GmbqsagBWkk8ohtGU-Bc1PmTT0o,4
|
| 45 |
+
git/__init__.py,sha256=w6fnS0QmwTfEFUSL6rfnpP0lUId2goSguZFOvVX3N3U,8899
|
| 46 |
+
git/cmd.py,sha256=qd-gIHSk4mfsYjd9YA08cPyO8TMxaibTXAbFnHK71uc,67659
|
| 47 |
+
git/compat.py,sha256=y1E6y6O2q5r8clSlr8ZNmuIWG9nmHuehQEsVsmBffs8,4526
|
| 48 |
+
git/config.py,sha256=Ald8Xc-G9Shcgx3QCISyXTkL4a6nbc3qll-xUw4YdyY,34924
|
| 49 |
+
git/db.py,sha256=vIW9uWSbqu99zbuU2ZDmOhVOv1UPTmxrnqiCtRHCfjE,2368
|
| 50 |
+
git/diff.py,sha256=IE5aeHL7aP9yxBluYj06IX8nZjoJ_TOM3gG31-Evf_8,27058
|
| 51 |
+
git/exc.py,sha256=Gc7g1pHpn8OmTse30NHmJVsBJ2CYH8LxaR8y8UA3lIM,7119
|
| 52 |
+
git/index/__init__.py,sha256=i-Nqb8Lufp9aFbmxpQBORmmQnjEVVM1Pn58fsQkyGgQ,406
|
| 53 |
+
git/index/base.py,sha256=A4q4cN_Ifxi8CsAR-7h4KsQ2d3JazBNFZ1ltbAKttgs,60734
|
| 54 |
+
git/index/fun.py,sha256=37cA3DBC9vpAnSVu5TGA072SnoF5XZOkOukExwlejHs,16736
|
| 55 |
+
git/index/typ.py,sha256=uuKNwitUw83FhVaLSwo4pY7PHDQudtZTLJrLGym4jcI,6570
|
| 56 |
+
git/index/util.py,sha256=fULi7GPG-MvprKrRCD5c15GNdzku_1E38We0d97WB3A,3659
|
| 57 |
+
git/objects/__init__.py,sha256=O6ZL_olX7e5-8iIbKviRPkVSJxN37WA-EC0q9d48U5Y,637
|
| 58 |
+
git/objects/base.py,sha256=0dqNkSRVH0mk0-7ZKIkGBK7iNYrzLTVxwQFUd6CagsE,10277
|
| 59 |
+
git/objects/blob.py,sha256=zwwq0KfOMYeP5J2tW5CQatoLyeqFRlfkxP1Vwx1h07s,1215
|
| 60 |
+
git/objects/commit.py,sha256=vLZNl1I9zp17Rpge7J66CvsryirEs90jyPTQzoP0JJs,30208
|
| 61 |
+
git/objects/fun.py,sha256=B4jCqhAjm6Hl79GK58FPzW1H9K6Wc7Tx0rssyWmAcEE,8935
|
| 62 |
+
git/objects/submodule/__init__.py,sha256=6xySp767LVz3UylWgUalntS_nGXRuVzXxDuFAv_Wc2c,303
|
| 63 |
+
git/objects/submodule/base.py,sha256=MQ-2xV8JznGwy2hLQv1aeQNgAkhBhgc5tdtClFL3DmE,63901
|
| 64 |
+
git/objects/submodule/root.py,sha256=5eTtYNHasqdPq6q0oDCPr7IaO6uAHL3b4DxMoiO2LhE,20246
|
| 65 |
+
git/objects/submodule/util.py,sha256=sQqAYaiSJdFkZa9NlAuK_wTsMNiS-kkQnQjvIoJtc_o,3509
|
| 66 |
+
git/objects/tag.py,sha256=gAx8i-DEwy_Z3R2zLkvetYRV8A56BCcTr3iLuTUTfEM,4467
|
| 67 |
+
git/objects/tree.py,sha256=jJH888SHiP4dGzE-ra1yenQOyya_0C_MkHr06c1gHpM,13849
|
| 68 |
+
git/objects/util.py,sha256=Ml2eqZPKO4y9Hc2vWbXJgpsK3nkN3KGMzbn8AlzLyYQ,23834
|
| 69 |
+
git/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 70 |
+
git/refs/__init__.py,sha256=DWlJNnsx-4jM_E-VycbP-FZUdn6iWhjnH_uZ_pZXBro,509
|
| 71 |
+
git/refs/head.py,sha256=GAZpD5EfqSciDXPtgjHY8ZbBixKExJRhojUB-HrrJPg,10491
|
| 72 |
+
git/refs/log.py,sha256=kXiuAgTo1DIuM_BfbDUk9gQ0YO-mutIMVdHv1_ES90o,12493
|
| 73 |
+
git/refs/reference.py,sha256=l6mhF4YLSEwtjz6b9PpOQH-fkng7EYWMaJhkjn-2jXA,5630
|
| 74 |
+
git/refs/remote.py,sha256=WwqV9T7BbYf3F_WZNUQivu9xktIIKGklCjDpwQrhD-A,2806
|
| 75 |
+
git/refs/symbolic.py,sha256=c8zOwaqzcg-J-rGrpuWdvh8zwMvSUqAHghd4vJoYG_s,34552
|
| 76 |
+
git/refs/tag.py,sha256=kgzV2vhpL4FD2TqHb0BJuMRAHgAvJF-TcoyWlaB-djQ,5010
|
| 77 |
+
git/remote.py,sha256=IHQ3BvXgoIN1EvHlyH3vrSaQoDkLOE6nooSC0w183sU,46561
|
| 78 |
+
git/repo/__init__.py,sha256=CILSVH36fX_WxVFSjD9o1WF5LgsNedPiJvSngKZqfVU,210
|
| 79 |
+
git/repo/base.py,sha256=mitfJ8u99CsMpDd7_VRyx-SF8omu2tpf3lqzSaQkKoQ,59353
|
| 80 |
+
git/repo/fun.py,sha256=tEsClpmbOrKMSNIdncOB_6JdikrL1-AfkOFd7xMpD8k,13582
|
| 81 |
+
git/types.py,sha256=xCwpp2Y01lhS0MapHhj04m0P_x34kwSD1Gsou_ZPWj8,10251
|
| 82 |
+
git/util.py,sha256=1E883mnPAFLyFk7ivwnEremsp-uJOTc3ks_QypyLung,43651
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.43.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
.venv/lib/python3.9/site-packages/GitPython-3.1.43.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
git
|
.venv/lib/python3.9/site-packages/IPython/__init__.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PYTHON_ARGCOMPLETE_OK
|
| 2 |
+
"""
|
| 3 |
+
IPython: tools for interactive and parallel computing in Python.
|
| 4 |
+
|
| 5 |
+
https://ipython.org
|
| 6 |
+
"""
|
| 7 |
+
#-----------------------------------------------------------------------------
|
| 8 |
+
# Copyright (c) 2008-2011, IPython Development Team.
|
| 9 |
+
# Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
|
| 10 |
+
# Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
|
| 11 |
+
# Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
|
| 12 |
+
#
|
| 13 |
+
# Distributed under the terms of the Modified BSD License.
|
| 14 |
+
#
|
| 15 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 16 |
+
#-----------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
#-----------------------------------------------------------------------------
|
| 19 |
+
# Imports
|
| 20 |
+
#-----------------------------------------------------------------------------
|
| 21 |
+
|
| 22 |
+
import sys
|
| 23 |
+
|
| 24 |
+
#-----------------------------------------------------------------------------
|
| 25 |
+
# Setup everything
|
| 26 |
+
#-----------------------------------------------------------------------------
|
| 27 |
+
|
| 28 |
+
# Don't forget to also update setup.py when this changes!
|
| 29 |
+
if sys.version_info < (3, 9):
|
| 30 |
+
raise ImportError(
|
| 31 |
+
"""
|
| 32 |
+
IPython 8.13+ supports Python 3.9 and above, following NEP 29.
|
| 33 |
+
IPython 8.0-8.12 supports Python 3.8 and above, following NEP 29.
|
| 34 |
+
When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
|
| 35 |
+
Python 3.3 and 3.4 were supported up to IPython 6.x.
|
| 36 |
+
Python 3.5 was supported with IPython 7.0 to 7.9.
|
| 37 |
+
Python 3.6 was supported with IPython up to 7.16.
|
| 38 |
+
Python 3.7 was still supported with the 7.x branch.
|
| 39 |
+
|
| 40 |
+
See IPython `README.rst` file for more information:
|
| 41 |
+
|
| 42 |
+
https://github.com/ipython/ipython/blob/main/README.rst
|
| 43 |
+
|
| 44 |
+
"""
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
#-----------------------------------------------------------------------------
|
| 48 |
+
# Setup the top level names
|
| 49 |
+
#-----------------------------------------------------------------------------
|
| 50 |
+
|
| 51 |
+
from .core.getipython import get_ipython
|
| 52 |
+
from .core import release
|
| 53 |
+
from .core.application import Application
|
| 54 |
+
from .terminal.embed import embed
|
| 55 |
+
|
| 56 |
+
from .core.interactiveshell import InteractiveShell
|
| 57 |
+
from .utils.sysinfo import sys_info
|
| 58 |
+
from .utils.frame import extract_module_locals
|
| 59 |
+
|
| 60 |
+
__all__ = ["start_ipython", "embed", "start_kernel", "embed_kernel"]
|
| 61 |
+
|
| 62 |
+
# Release data
|
| 63 |
+
__author__ = '%s <%s>' % (release.author, release.author_email)
|
| 64 |
+
__license__ = release.license
|
| 65 |
+
__version__ = release.version
|
| 66 |
+
version_info = release.version_info
|
| 67 |
+
# list of CVEs that should have been patched in this release.
|
| 68 |
+
# this is informational and should not be relied upon.
|
| 69 |
+
__patched_cves__ = {"CVE-2022-21699", "CVE-2023-24816"}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def embed_kernel(module=None, local_ns=None, **kwargs):
|
| 73 |
+
"""Embed and start an IPython kernel in a given scope.
|
| 74 |
+
|
| 75 |
+
If you don't want the kernel to initialize the namespace
|
| 76 |
+
from the scope of the surrounding function,
|
| 77 |
+
and/or you want to load full IPython configuration,
|
| 78 |
+
you probably want `IPython.start_kernel()` instead.
|
| 79 |
+
|
| 80 |
+
Parameters
|
| 81 |
+
----------
|
| 82 |
+
module : types.ModuleType, optional
|
| 83 |
+
The module to load into IPython globals (default: caller)
|
| 84 |
+
local_ns : dict, optional
|
| 85 |
+
The namespace to load into IPython user namespace (default: caller)
|
| 86 |
+
**kwargs : various, optional
|
| 87 |
+
Further keyword args are relayed to the IPKernelApp constructor,
|
| 88 |
+
such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
|
| 89 |
+
allowing configuration of the kernel (see :ref:`kernel_options`). Will only have an effect
|
| 90 |
+
on the first embed_kernel call for a given process.
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
(caller_module, caller_locals) = extract_module_locals(1)
|
| 94 |
+
if module is None:
|
| 95 |
+
module = caller_module
|
| 96 |
+
if local_ns is None:
|
| 97 |
+
local_ns = caller_locals
|
| 98 |
+
|
| 99 |
+
# Only import .zmq when we really need it
|
| 100 |
+
from ipykernel.embed import embed_kernel as real_embed_kernel
|
| 101 |
+
real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
|
| 102 |
+
|
| 103 |
+
def start_ipython(argv=None, **kwargs):
|
| 104 |
+
"""Launch a normal IPython instance (as opposed to embedded)
|
| 105 |
+
|
| 106 |
+
`IPython.embed()` puts a shell in a particular calling scope,
|
| 107 |
+
such as a function or method for debugging purposes,
|
| 108 |
+
which is often not desirable.
|
| 109 |
+
|
| 110 |
+
`start_ipython()` does full, regular IPython initialization,
|
| 111 |
+
including loading startup files, configuration, etc.
|
| 112 |
+
much of which is skipped by `embed()`.
|
| 113 |
+
|
| 114 |
+
This is a public API method, and will survive implementation changes.
|
| 115 |
+
|
| 116 |
+
Parameters
|
| 117 |
+
----------
|
| 118 |
+
argv : list or None, optional
|
| 119 |
+
If unspecified or None, IPython will parse command-line options from sys.argv.
|
| 120 |
+
To prevent any command-line parsing, pass an empty list: `argv=[]`.
|
| 121 |
+
user_ns : dict, optional
|
| 122 |
+
specify this dictionary to initialize the IPython user namespace with particular values.
|
| 123 |
+
**kwargs : various, optional
|
| 124 |
+
Any other kwargs will be passed to the Application constructor,
|
| 125 |
+
such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
|
| 126 |
+
allowing configuration of the instance (see :ref:`terminal_options`).
|
| 127 |
+
"""
|
| 128 |
+
from IPython.terminal.ipapp import launch_new_instance
|
| 129 |
+
return launch_new_instance(argv=argv, **kwargs)
|
| 130 |
+
|
| 131 |
+
def start_kernel(argv=None, **kwargs):
|
| 132 |
+
"""Launch a normal IPython kernel instance (as opposed to embedded)
|
| 133 |
+
|
| 134 |
+
`IPython.embed_kernel()` puts a shell in a particular calling scope,
|
| 135 |
+
such as a function or method for debugging purposes,
|
| 136 |
+
which is often not desirable.
|
| 137 |
+
|
| 138 |
+
`start_kernel()` does full, regular IPython initialization,
|
| 139 |
+
including loading startup files, configuration, etc.
|
| 140 |
+
much of which is skipped by `embed_kernel()`.
|
| 141 |
+
|
| 142 |
+
Parameters
|
| 143 |
+
----------
|
| 144 |
+
argv : list or None, optional
|
| 145 |
+
If unspecified or None, IPython will parse command-line options from sys.argv.
|
| 146 |
+
To prevent any command-line parsing, pass an empty list: `argv=[]`.
|
| 147 |
+
user_ns : dict, optional
|
| 148 |
+
specify this dictionary to initialize the IPython user namespace with particular values.
|
| 149 |
+
**kwargs : various, optional
|
| 150 |
+
Any other kwargs will be passed to the Application constructor,
|
| 151 |
+
such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
|
| 152 |
+
allowing configuration of the kernel (see :ref:`kernel_options`).
|
| 153 |
+
"""
|
| 154 |
+
import warnings
|
| 155 |
+
|
| 156 |
+
warnings.warn(
|
| 157 |
+
"start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`",
|
| 158 |
+
DeprecationWarning,
|
| 159 |
+
stacklevel=2,
|
| 160 |
+
)
|
| 161 |
+
from ipykernel.kernelapp import launch_new_instance
|
| 162 |
+
return launch_new_instance(argv=argv, **kwargs)
|
.venv/lib/python3.9/site-packages/IPython/__main__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PYTHON_ARGCOMPLETE_OK
|
| 2 |
+
# encoding: utf-8
|
| 3 |
+
"""Terminal-based IPython entry point.
|
| 4 |
+
"""
|
| 5 |
+
# -----------------------------------------------------------------------------
|
| 6 |
+
# Copyright (c) 2012, IPython Development Team.
|
| 7 |
+
#
|
| 8 |
+
# Distributed under the terms of the Modified BSD License.
|
| 9 |
+
#
|
| 10 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 11 |
+
# -----------------------------------------------------------------------------
|
| 12 |
+
|
| 13 |
+
from IPython import start_ipython
|
| 14 |
+
|
| 15 |
+
start_ipython()
|
.venv/lib/python3.9/site-packages/IPython/conftest.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import builtins
|
| 2 |
+
import inspect
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import shutil
|
| 6 |
+
import sys
|
| 7 |
+
import types
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
# Must register before it gets imported
|
| 12 |
+
pytest.register_assert_rewrite("IPython.testing.tools")
|
| 13 |
+
|
| 14 |
+
from .testing import tools
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def pytest_collection_modifyitems(items):
|
| 18 |
+
"""This function is automatically run by pytest passing all collected test
|
| 19 |
+
functions.
|
| 20 |
+
|
| 21 |
+
We use it to add asyncio marker to all async tests and assert we don't use
|
| 22 |
+
test functions that are async generators which wouldn't make sense.
|
| 23 |
+
"""
|
| 24 |
+
for item in items:
|
| 25 |
+
if inspect.iscoroutinefunction(item.obj):
|
| 26 |
+
item.add_marker("asyncio")
|
| 27 |
+
assert not inspect.isasyncgenfunction(item.obj)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_ipython():
|
| 31 |
+
from .terminal.interactiveshell import TerminalInteractiveShell
|
| 32 |
+
if TerminalInteractiveShell._instance:
|
| 33 |
+
return TerminalInteractiveShell.instance()
|
| 34 |
+
|
| 35 |
+
config = tools.default_config()
|
| 36 |
+
config.TerminalInteractiveShell.simple_prompt = True
|
| 37 |
+
|
| 38 |
+
# Create and initialize our test-friendly IPython instance.
|
| 39 |
+
shell = TerminalInteractiveShell.instance(config=config)
|
| 40 |
+
return shell
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@pytest.fixture(scope='session', autouse=True)
|
| 44 |
+
def work_path():
|
| 45 |
+
path = pathlib.Path("./tmp-ipython-pytest-profiledir")
|
| 46 |
+
os.environ["IPYTHONDIR"] = str(path.absolute())
|
| 47 |
+
if path.exists():
|
| 48 |
+
raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
|
| 49 |
+
path.mkdir()
|
| 50 |
+
yield
|
| 51 |
+
shutil.rmtree(str(path.resolve()))
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
|
| 55 |
+
if isinstance(strng, dict):
|
| 56 |
+
strng = strng.get("text/plain", "")
|
| 57 |
+
print(strng)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def xsys(self, cmd):
|
| 61 |
+
"""Replace the default system call with a capturing one for doctest.
|
| 62 |
+
"""
|
| 63 |
+
# We use getoutput, but we need to strip it because pexpect captures
|
| 64 |
+
# the trailing newline differently from commands.getoutput
|
| 65 |
+
print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
|
| 66 |
+
sys.stdout.flush()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# for things to work correctly we would need this as a session fixture;
|
| 70 |
+
# unfortunately this will fail on some test that get executed as _collection_
|
| 71 |
+
# time (before the fixture run), in particular parametrized test that contain
|
| 72 |
+
# yields. so for now execute at import time.
|
| 73 |
+
#@pytest.fixture(autouse=True, scope='session')
|
| 74 |
+
def inject():
|
| 75 |
+
|
| 76 |
+
builtins.get_ipython = get_ipython
|
| 77 |
+
builtins._ip = get_ipython()
|
| 78 |
+
builtins.ip = get_ipython()
|
| 79 |
+
builtins.ip.system = types.MethodType(xsys, ip)
|
| 80 |
+
builtins.ip.builtin_trap.activate()
|
| 81 |
+
from .core import page
|
| 82 |
+
|
| 83 |
+
page.pager_page = nopage
|
| 84 |
+
# yield
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
inject()
|
.venv/lib/python3.9/site-packages/IPython/consoleapp.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Shim to maintain backwards compatibility with old IPython.consoleapp imports.
|
| 3 |
+
"""
|
| 4 |
+
# Copyright (c) IPython Development Team.
|
| 5 |
+
# Distributed under the terms of the Modified BSD License.
|
| 6 |
+
|
| 7 |
+
from warnings import warn
|
| 8 |
+
|
| 9 |
+
warn("The `IPython.consoleapp` package has been deprecated since IPython 4.0."
|
| 10 |
+
"You should import from jupyter_client.consoleapp instead.", stacklevel=2)
|
| 11 |
+
|
| 12 |
+
from jupyter_client.consoleapp import *
|
.venv/lib/python3.9/site-packages/IPython/core/__init__.py
ADDED
|
File without changes
|
.venv/lib/python3.9/site-packages/IPython/core/alias.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 11 |
+
#-----------------------------------------------------------------------------
|
| 12 |
+
# Copyright (C) 2008-2011 The IPython Development Team
|
| 13 |
+
#
|
| 14 |
+
# Distributed under the terms of the BSD License.
|
| 15 |
+
#
|
| 16 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 17 |
+
#-----------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
#-----------------------------------------------------------------------------
|
| 20 |
+
# Imports
|
| 21 |
+
#-----------------------------------------------------------------------------
|
| 22 |
+
|
| 23 |
+
import os
|
| 24 |
+
import re
|
| 25 |
+
import sys
|
| 26 |
+
|
| 27 |
+
from traitlets.config.configurable import Configurable
|
| 28 |
+
from .error import UsageError
|
| 29 |
+
|
| 30 |
+
from traitlets import List, Instance
|
| 31 |
+
from logging import error
|
| 32 |
+
|
| 33 |
+
#-----------------------------------------------------------------------------
|
| 34 |
+
# Utilities
|
| 35 |
+
#-----------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
# This is used as the pattern for calls to split_user_input.
|
| 38 |
+
shell_line_split = re.compile(r'^(\s*)()(\S+)(.*$)')
|
| 39 |
+
|
| 40 |
+
def default_aliases():
|
| 41 |
+
"""Return list of shell aliases to auto-define.
|
| 42 |
+
"""
|
| 43 |
+
# Note: the aliases defined here should be safe to use on a kernel
|
| 44 |
+
# regardless of what frontend it is attached to. Frontends that use a
|
| 45 |
+
# kernel in-process can define additional aliases that will only work in
|
| 46 |
+
# their case. For example, things like 'less' or 'clear' that manipulate
|
| 47 |
+
# the terminal should NOT be declared here, as they will only work if the
|
| 48 |
+
# kernel is running inside a true terminal, and not over the network.
|
| 49 |
+
|
| 50 |
+
if os.name == 'posix':
|
| 51 |
+
default_aliases = [('mkdir', 'mkdir'), ('rmdir', 'rmdir'),
|
| 52 |
+
('mv', 'mv'), ('rm', 'rm'), ('cp', 'cp'),
|
| 53 |
+
('cat', 'cat'),
|
| 54 |
+
]
|
| 55 |
+
# Useful set of ls aliases. The GNU and BSD options are a little
|
| 56 |
+
# different, so we make aliases that provide as similar as possible
|
| 57 |
+
# behavior in ipython, by passing the right flags for each platform
|
| 58 |
+
if sys.platform.startswith('linux'):
|
| 59 |
+
ls_aliases = [('ls', 'ls -F --color'),
|
| 60 |
+
# long ls
|
| 61 |
+
('ll', 'ls -F -o --color'),
|
| 62 |
+
# ls normal files only
|
| 63 |
+
('lf', 'ls -F -o --color %l | grep ^-'),
|
| 64 |
+
# ls symbolic links
|
| 65 |
+
('lk', 'ls -F -o --color %l | grep ^l'),
|
| 66 |
+
# directories or links to directories,
|
| 67 |
+
('ldir', 'ls -F -o --color %l | grep /$'),
|
| 68 |
+
# things which are executable
|
| 69 |
+
('lx', 'ls -F -o --color %l | grep ^-..x'),
|
| 70 |
+
]
|
| 71 |
+
elif sys.platform.startswith('openbsd') or sys.platform.startswith('netbsd'):
|
| 72 |
+
# OpenBSD, NetBSD. The ls implementation on these platforms do not support
|
| 73 |
+
# the -G switch and lack the ability to use colorized output.
|
| 74 |
+
ls_aliases = [('ls', 'ls -F'),
|
| 75 |
+
# long ls
|
| 76 |
+
('ll', 'ls -F -l'),
|
| 77 |
+
# ls normal files only
|
| 78 |
+
('lf', 'ls -F -l %l | grep ^-'),
|
| 79 |
+
# ls symbolic links
|
| 80 |
+
('lk', 'ls -F -l %l | grep ^l'),
|
| 81 |
+
# directories or links to directories,
|
| 82 |
+
('ldir', 'ls -F -l %l | grep /$'),
|
| 83 |
+
# things which are executable
|
| 84 |
+
('lx', 'ls -F -l %l | grep ^-..x'),
|
| 85 |
+
]
|
| 86 |
+
else:
|
| 87 |
+
# BSD, OSX, etc.
|
| 88 |
+
ls_aliases = [('ls', 'ls -F -G'),
|
| 89 |
+
# long ls
|
| 90 |
+
('ll', 'ls -F -l -G'),
|
| 91 |
+
# ls normal files only
|
| 92 |
+
('lf', 'ls -F -l -G %l | grep ^-'),
|
| 93 |
+
# ls symbolic links
|
| 94 |
+
('lk', 'ls -F -l -G %l | grep ^l'),
|
| 95 |
+
# directories or links to directories,
|
| 96 |
+
('ldir', 'ls -F -G -l %l | grep /$'),
|
| 97 |
+
# things which are executable
|
| 98 |
+
('lx', 'ls -F -l -G %l | grep ^-..x'),
|
| 99 |
+
]
|
| 100 |
+
default_aliases = default_aliases + ls_aliases
|
| 101 |
+
elif os.name in ['nt', 'dos']:
|
| 102 |
+
default_aliases = [('ls', 'dir /on'),
|
| 103 |
+
('ddir', 'dir /ad /on'), ('ldir', 'dir /ad /on'),
|
| 104 |
+
('mkdir', 'mkdir'), ('rmdir', 'rmdir'),
|
| 105 |
+
('echo', 'echo'), ('ren', 'ren'), ('copy', 'copy'),
|
| 106 |
+
]
|
| 107 |
+
else:
|
| 108 |
+
default_aliases = []
|
| 109 |
+
|
| 110 |
+
return default_aliases
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class AliasError(Exception):
|
| 114 |
+
pass
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class InvalidAliasError(AliasError):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
class Alias(object):
|
| 121 |
+
"""Callable object storing the details of one alias.
|
| 122 |
+
|
| 123 |
+
Instances are registered as magic functions to allow use of aliases.
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
+
# Prepare blacklist
|
| 127 |
+
blacklist = {'cd','popd','pushd','dhist','alias','unalias'}
|
| 128 |
+
|
| 129 |
+
def __init__(self, shell, name, cmd):
|
| 130 |
+
self.shell = shell
|
| 131 |
+
self.name = name
|
| 132 |
+
self.cmd = cmd
|
| 133 |
+
self.__doc__ = "Alias for `!{}`".format(cmd)
|
| 134 |
+
self.nargs = self.validate()
|
| 135 |
+
|
| 136 |
+
def validate(self):
|
| 137 |
+
"""Validate the alias, and return the number of arguments."""
|
| 138 |
+
if self.name in self.blacklist:
|
| 139 |
+
raise InvalidAliasError("The name %s can't be aliased "
|
| 140 |
+
"because it is a keyword or builtin." % self.name)
|
| 141 |
+
try:
|
| 142 |
+
caller = self.shell.magics_manager.magics['line'][self.name]
|
| 143 |
+
except KeyError:
|
| 144 |
+
pass
|
| 145 |
+
else:
|
| 146 |
+
if not isinstance(caller, Alias):
|
| 147 |
+
raise InvalidAliasError("The name %s can't be aliased "
|
| 148 |
+
"because it is another magic command." % self.name)
|
| 149 |
+
|
| 150 |
+
if not (isinstance(self.cmd, str)):
|
| 151 |
+
raise InvalidAliasError("An alias command must be a string, "
|
| 152 |
+
"got: %r" % self.cmd)
|
| 153 |
+
|
| 154 |
+
nargs = self.cmd.count('%s') - self.cmd.count('%%s')
|
| 155 |
+
|
| 156 |
+
if (nargs > 0) and (self.cmd.find('%l') >= 0):
|
| 157 |
+
raise InvalidAliasError('The %s and %l specifiers are mutually '
|
| 158 |
+
'exclusive in alias definitions.')
|
| 159 |
+
|
| 160 |
+
return nargs
|
| 161 |
+
|
| 162 |
+
def __repr__(self):
|
| 163 |
+
return "<alias {} for {!r}>".format(self.name, self.cmd)
|
| 164 |
+
|
| 165 |
+
def __call__(self, rest=''):
|
| 166 |
+
cmd = self.cmd
|
| 167 |
+
nargs = self.nargs
|
| 168 |
+
# Expand the %l special to be the user's input line
|
| 169 |
+
if cmd.find('%l') >= 0:
|
| 170 |
+
cmd = cmd.replace('%l', rest)
|
| 171 |
+
rest = ''
|
| 172 |
+
|
| 173 |
+
if nargs==0:
|
| 174 |
+
if cmd.find('%%s') >= 1:
|
| 175 |
+
cmd = cmd.replace('%%s', '%s')
|
| 176 |
+
# Simple, argument-less aliases
|
| 177 |
+
cmd = '%s %s' % (cmd, rest)
|
| 178 |
+
else:
|
| 179 |
+
# Handle aliases with positional arguments
|
| 180 |
+
args = rest.split(None, nargs)
|
| 181 |
+
if len(args) < nargs:
|
| 182 |
+
raise UsageError('Alias <%s> requires %s arguments, %s given.' %
|
| 183 |
+
(self.name, nargs, len(args)))
|
| 184 |
+
cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
|
| 185 |
+
|
| 186 |
+
self.shell.system(cmd)
|
| 187 |
+
|
| 188 |
+
#-----------------------------------------------------------------------------
|
| 189 |
+
# Main AliasManager class
|
| 190 |
+
#-----------------------------------------------------------------------------
|
| 191 |
+
|
| 192 |
+
class AliasManager(Configurable):
|
| 193 |
+
|
| 194 |
+
default_aliases = List(default_aliases()).tag(config=True)
|
| 195 |
+
user_aliases = List(default_value=[]).tag(config=True)
|
| 196 |
+
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
|
| 197 |
+
|
| 198 |
+
def __init__(self, shell=None, **kwargs):
|
| 199 |
+
super(AliasManager, self).__init__(shell=shell, **kwargs)
|
| 200 |
+
# For convenient access
|
| 201 |
+
self.linemagics = self.shell.magics_manager.magics['line']
|
| 202 |
+
self.init_aliases()
|
| 203 |
+
|
| 204 |
+
def init_aliases(self):
|
| 205 |
+
# Load default & user aliases
|
| 206 |
+
for name, cmd in self.default_aliases + self.user_aliases:
|
| 207 |
+
if cmd.startswith('ls ') and self.shell.colors == 'NoColor':
|
| 208 |
+
cmd = cmd.replace(' --color', '')
|
| 209 |
+
self.soft_define_alias(name, cmd)
|
| 210 |
+
|
| 211 |
+
@property
|
| 212 |
+
def aliases(self):
|
| 213 |
+
return [(n, func.cmd) for (n, func) in self.linemagics.items()
|
| 214 |
+
if isinstance(func, Alias)]
|
| 215 |
+
|
| 216 |
+
def soft_define_alias(self, name, cmd):
|
| 217 |
+
"""Define an alias, but don't raise on an AliasError."""
|
| 218 |
+
try:
|
| 219 |
+
self.define_alias(name, cmd)
|
| 220 |
+
except AliasError as e:
|
| 221 |
+
error("Invalid alias: %s" % e)
|
| 222 |
+
|
| 223 |
+
def define_alias(self, name, cmd):
|
| 224 |
+
"""Define a new alias after validating it.
|
| 225 |
+
|
| 226 |
+
This will raise an :exc:`AliasError` if there are validation
|
| 227 |
+
problems.
|
| 228 |
+
"""
|
| 229 |
+
caller = Alias(shell=self.shell, name=name, cmd=cmd)
|
| 230 |
+
self.shell.magics_manager.register_function(caller, magic_kind='line',
|
| 231 |
+
magic_name=name)
|
| 232 |
+
|
| 233 |
+
def get_alias(self, name):
|
| 234 |
+
"""Return an alias, or None if no alias by that name exists."""
|
| 235 |
+
aname = self.linemagics.get(name, None)
|
| 236 |
+
return aname if isinstance(aname, Alias) else None
|
| 237 |
+
|
| 238 |
+
def is_alias(self, name):
|
| 239 |
+
"""Return whether or not a given name has been defined as an alias"""
|
| 240 |
+
return self.get_alias(name) is not None
|
| 241 |
+
|
| 242 |
+
def undefine_alias(self, name):
|
| 243 |
+
if self.is_alias(name):
|
| 244 |
+
del self.linemagics[name]
|
| 245 |
+
else:
|
| 246 |
+
raise ValueError('%s is not an alias' % name)
|
| 247 |
+
|
| 248 |
+
def clear_aliases(self):
|
| 249 |
+
for name, cmd in self.aliases:
|
| 250 |
+
self.undefine_alias(name)
|
| 251 |
+
|
| 252 |
+
def retrieve_alias(self, name):
|
| 253 |
+
"""Retrieve the command to which an alias expands."""
|
| 254 |
+
caller = self.get_alias(name)
|
| 255 |
+
if caller:
|
| 256 |
+
return caller.cmd
|
| 257 |
+
else:
|
| 258 |
+
raise ValueError('%s is not an alias' % name)
|
.venv/lib/python3.9/site-packages/IPython/core/application.py
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""
|
| 3 |
+
An application for IPython.
|
| 4 |
+
|
| 5 |
+
All top-level applications should use the classes in this module for
|
| 6 |
+
handling configuration and creating configurables.
|
| 7 |
+
|
| 8 |
+
The job of an :class:`Application` is to create the master configuration
|
| 9 |
+
object and then create the configurable objects, passing the config to them.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
# Copyright (c) IPython Development Team.
|
| 13 |
+
# Distributed under the terms of the Modified BSD License.
|
| 14 |
+
|
| 15 |
+
import atexit
|
| 16 |
+
from copy import deepcopy
|
| 17 |
+
import logging
|
| 18 |
+
import os
|
| 19 |
+
import shutil
|
| 20 |
+
import sys
|
| 21 |
+
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
from traitlets.config.application import Application, catch_config_error
|
| 25 |
+
from traitlets.config.loader import ConfigFileNotFound, PyFileConfigLoader
|
| 26 |
+
from IPython.core import release, crashhandler
|
| 27 |
+
from IPython.core.profiledir import ProfileDir, ProfileDirError
|
| 28 |
+
from IPython.paths import get_ipython_dir, get_ipython_package_dir
|
| 29 |
+
from IPython.utils.path import ensure_dir_exists
|
| 30 |
+
from traitlets import (
|
| 31 |
+
List, Unicode, Type, Bool, Set, Instance, Undefined,
|
| 32 |
+
default, observe,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if os.name == "nt":
|
| 36 |
+
programdata = os.environ.get("PROGRAMDATA", None)
|
| 37 |
+
if programdata is not None:
|
| 38 |
+
SYSTEM_CONFIG_DIRS = [str(Path(programdata) / "ipython")]
|
| 39 |
+
else: # PROGRAMDATA is not defined by default on XP.
|
| 40 |
+
SYSTEM_CONFIG_DIRS = []
|
| 41 |
+
else:
|
| 42 |
+
SYSTEM_CONFIG_DIRS = [
|
| 43 |
+
"/usr/local/etc/ipython",
|
| 44 |
+
"/etc/ipython",
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
ENV_CONFIG_DIRS = []
|
| 49 |
+
_env_config_dir = os.path.join(sys.prefix, 'etc', 'ipython')
|
| 50 |
+
if _env_config_dir not in SYSTEM_CONFIG_DIRS:
|
| 51 |
+
# only add ENV_CONFIG if sys.prefix is not already included
|
| 52 |
+
ENV_CONFIG_DIRS.append(_env_config_dir)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
_envvar = os.environ.get('IPYTHON_SUPPRESS_CONFIG_ERRORS')
|
| 56 |
+
if _envvar in {None, ''}:
|
| 57 |
+
IPYTHON_SUPPRESS_CONFIG_ERRORS = None
|
| 58 |
+
else:
|
| 59 |
+
if _envvar.lower() in {'1','true'}:
|
| 60 |
+
IPYTHON_SUPPRESS_CONFIG_ERRORS = True
|
| 61 |
+
elif _envvar.lower() in {'0','false'} :
|
| 62 |
+
IPYTHON_SUPPRESS_CONFIG_ERRORS = False
|
| 63 |
+
else:
|
| 64 |
+
sys.exit("Unsupported value for environment variable: 'IPYTHON_SUPPRESS_CONFIG_ERRORS' is set to '%s' which is none of {'0', '1', 'false', 'true', ''}."% _envvar )
|
| 65 |
+
|
| 66 |
+
# aliases and flags
|
| 67 |
+
|
| 68 |
+
base_aliases = {}
|
| 69 |
+
if isinstance(Application.aliases, dict):
|
| 70 |
+
# traitlets 5
|
| 71 |
+
base_aliases.update(Application.aliases)
|
| 72 |
+
base_aliases.update(
|
| 73 |
+
{
|
| 74 |
+
"profile-dir": "ProfileDir.location",
|
| 75 |
+
"profile": "BaseIPythonApplication.profile",
|
| 76 |
+
"ipython-dir": "BaseIPythonApplication.ipython_dir",
|
| 77 |
+
"log-level": "Application.log_level",
|
| 78 |
+
"config": "BaseIPythonApplication.extra_config_file",
|
| 79 |
+
}
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
base_flags = dict()
|
| 83 |
+
if isinstance(Application.flags, dict):
|
| 84 |
+
# traitlets 5
|
| 85 |
+
base_flags.update(Application.flags)
|
| 86 |
+
base_flags.update(
|
| 87 |
+
dict(
|
| 88 |
+
debug=(
|
| 89 |
+
{"Application": {"log_level": logging.DEBUG}},
|
| 90 |
+
"set log level to logging.DEBUG (maximize logging output)",
|
| 91 |
+
),
|
| 92 |
+
quiet=(
|
| 93 |
+
{"Application": {"log_level": logging.CRITICAL}},
|
| 94 |
+
"set log level to logging.CRITICAL (minimize logging output)",
|
| 95 |
+
),
|
| 96 |
+
init=(
|
| 97 |
+
{
|
| 98 |
+
"BaseIPythonApplication": {
|
| 99 |
+
"copy_config_files": True,
|
| 100 |
+
"auto_create": True,
|
| 101 |
+
}
|
| 102 |
+
},
|
| 103 |
+
"""Initialize profile with default config files. This is equivalent
|
| 104 |
+
to running `ipython profile create <profile>` prior to startup.
|
| 105 |
+
""",
|
| 106 |
+
),
|
| 107 |
+
)
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
class ProfileAwareConfigLoader(PyFileConfigLoader):
|
| 112 |
+
"""A Python file config loader that is aware of IPython profiles."""
|
| 113 |
+
def load_subconfig(self, fname, path=None, profile=None):
|
| 114 |
+
if profile is not None:
|
| 115 |
+
try:
|
| 116 |
+
profile_dir = ProfileDir.find_profile_dir_by_name(
|
| 117 |
+
get_ipython_dir(),
|
| 118 |
+
profile,
|
| 119 |
+
)
|
| 120 |
+
except ProfileDirError:
|
| 121 |
+
return
|
| 122 |
+
path = profile_dir.location
|
| 123 |
+
return super(ProfileAwareConfigLoader, self).load_subconfig(fname, path=path)
|
| 124 |
+
|
| 125 |
+
class BaseIPythonApplication(Application):
|
| 126 |
+
name = "ipython"
|
| 127 |
+
description = "IPython: an enhanced interactive Python shell."
|
| 128 |
+
version = Unicode(release.version)
|
| 129 |
+
|
| 130 |
+
aliases = base_aliases
|
| 131 |
+
flags = base_flags
|
| 132 |
+
classes = List([ProfileDir])
|
| 133 |
+
|
| 134 |
+
# enable `load_subconfig('cfg.py', profile='name')`
|
| 135 |
+
python_config_loader_class = ProfileAwareConfigLoader
|
| 136 |
+
|
| 137 |
+
# Track whether the config_file has changed,
|
| 138 |
+
# because some logic happens only if we aren't using the default.
|
| 139 |
+
config_file_specified = Set()
|
| 140 |
+
|
| 141 |
+
config_file_name = Unicode()
|
| 142 |
+
@default('config_file_name')
|
| 143 |
+
def _config_file_name_default(self):
|
| 144 |
+
return self.name.replace('-','_') + u'_config.py'
|
| 145 |
+
@observe('config_file_name')
|
| 146 |
+
def _config_file_name_changed(self, change):
|
| 147 |
+
if change['new'] != change['old']:
|
| 148 |
+
self.config_file_specified.add(change['new'])
|
| 149 |
+
|
| 150 |
+
# The directory that contains IPython's builtin profiles.
|
| 151 |
+
builtin_profile_dir = Unicode(
|
| 152 |
+
os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
config_file_paths = List(Unicode())
|
| 156 |
+
@default('config_file_paths')
|
| 157 |
+
def _config_file_paths_default(self):
|
| 158 |
+
return []
|
| 159 |
+
|
| 160 |
+
extra_config_file = Unicode(
|
| 161 |
+
help="""Path to an extra config file to load.
|
| 162 |
+
|
| 163 |
+
If specified, load this config file in addition to any other IPython config.
|
| 164 |
+
""").tag(config=True)
|
| 165 |
+
@observe('extra_config_file')
|
| 166 |
+
def _extra_config_file_changed(self, change):
|
| 167 |
+
old = change['old']
|
| 168 |
+
new = change['new']
|
| 169 |
+
try:
|
| 170 |
+
self.config_files.remove(old)
|
| 171 |
+
except ValueError:
|
| 172 |
+
pass
|
| 173 |
+
self.config_file_specified.add(new)
|
| 174 |
+
self.config_files.append(new)
|
| 175 |
+
|
| 176 |
+
profile = Unicode(u'default',
|
| 177 |
+
help="""The IPython profile to use."""
|
| 178 |
+
).tag(config=True)
|
| 179 |
+
|
| 180 |
+
@observe('profile')
|
| 181 |
+
def _profile_changed(self, change):
|
| 182 |
+
self.builtin_profile_dir = os.path.join(
|
| 183 |
+
get_ipython_package_dir(), u'config', u'profile', change['new']
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
add_ipython_dir_to_sys_path = Bool(
|
| 187 |
+
False,
|
| 188 |
+
"""Should the IPython profile directory be added to sys path ?
|
| 189 |
+
|
| 190 |
+
This option was non-existing before IPython 8.0, and ipython_dir was added to
|
| 191 |
+
sys path to allow import of extensions present there. This was historical
|
| 192 |
+
baggage from when pip did not exist. This now default to false,
|
| 193 |
+
but can be set to true for legacy reasons.
|
| 194 |
+
""",
|
| 195 |
+
).tag(config=True)
|
| 196 |
+
|
| 197 |
+
ipython_dir = Unicode(
|
| 198 |
+
help="""
|
| 199 |
+
The name of the IPython directory. This directory is used for logging
|
| 200 |
+
configuration (through profiles), history storage, etc. The default
|
| 201 |
+
is usually $HOME/.ipython. This option can also be specified through
|
| 202 |
+
the environment variable IPYTHONDIR.
|
| 203 |
+
"""
|
| 204 |
+
).tag(config=True)
|
| 205 |
+
@default('ipython_dir')
|
| 206 |
+
def _ipython_dir_default(self):
|
| 207 |
+
d = get_ipython_dir()
|
| 208 |
+
self._ipython_dir_changed({
|
| 209 |
+
'name': 'ipython_dir',
|
| 210 |
+
'old': d,
|
| 211 |
+
'new': d,
|
| 212 |
+
})
|
| 213 |
+
return d
|
| 214 |
+
|
| 215 |
+
_in_init_profile_dir = False
|
| 216 |
+
profile_dir = Instance(ProfileDir, allow_none=True)
|
| 217 |
+
@default('profile_dir')
|
| 218 |
+
def _profile_dir_default(self):
|
| 219 |
+
# avoid recursion
|
| 220 |
+
if self._in_init_profile_dir:
|
| 221 |
+
return
|
| 222 |
+
# profile_dir requested early, force initialization
|
| 223 |
+
self.init_profile_dir()
|
| 224 |
+
return self.profile_dir
|
| 225 |
+
|
| 226 |
+
overwrite = Bool(False,
|
| 227 |
+
help="""Whether to overwrite existing config files when copying"""
|
| 228 |
+
).tag(config=True)
|
| 229 |
+
auto_create = Bool(False,
|
| 230 |
+
help="""Whether to create profile dir if it doesn't exist"""
|
| 231 |
+
).tag(config=True)
|
| 232 |
+
|
| 233 |
+
config_files = List(Unicode())
|
| 234 |
+
@default('config_files')
|
| 235 |
+
def _config_files_default(self):
|
| 236 |
+
return [self.config_file_name]
|
| 237 |
+
|
| 238 |
+
copy_config_files = Bool(False,
|
| 239 |
+
help="""Whether to install the default config files into the profile dir.
|
| 240 |
+
If a new profile is being created, and IPython contains config files for that
|
| 241 |
+
profile, then they will be staged into the new directory. Otherwise,
|
| 242 |
+
default config files will be automatically generated.
|
| 243 |
+
""").tag(config=True)
|
| 244 |
+
|
| 245 |
+
verbose_crash = Bool(False,
|
| 246 |
+
help="""Create a massive crash report when IPython encounters what may be an
|
| 247 |
+
internal error. The default is to append a short message to the
|
| 248 |
+
usual traceback""").tag(config=True)
|
| 249 |
+
|
| 250 |
+
# The class to use as the crash handler.
|
| 251 |
+
crash_handler_class = Type(crashhandler.CrashHandler)
|
| 252 |
+
|
| 253 |
+
@catch_config_error
|
| 254 |
+
def __init__(self, **kwargs):
|
| 255 |
+
super(BaseIPythonApplication, self).__init__(**kwargs)
|
| 256 |
+
# ensure current working directory exists
|
| 257 |
+
try:
|
| 258 |
+
os.getcwd()
|
| 259 |
+
except:
|
| 260 |
+
# exit if cwd doesn't exist
|
| 261 |
+
self.log.error("Current working directory doesn't exist.")
|
| 262 |
+
self.exit(1)
|
| 263 |
+
|
| 264 |
+
#-------------------------------------------------------------------------
|
| 265 |
+
# Various stages of Application creation
|
| 266 |
+
#-------------------------------------------------------------------------
|
| 267 |
+
|
| 268 |
+
def init_crash_handler(self):
|
| 269 |
+
"""Create a crash handler, typically setting sys.excepthook to it."""
|
| 270 |
+
self.crash_handler = self.crash_handler_class(self)
|
| 271 |
+
sys.excepthook = self.excepthook
|
| 272 |
+
def unset_crashhandler():
|
| 273 |
+
sys.excepthook = sys.__excepthook__
|
| 274 |
+
atexit.register(unset_crashhandler)
|
| 275 |
+
|
| 276 |
+
def excepthook(self, etype, evalue, tb):
|
| 277 |
+
"""this is sys.excepthook after init_crashhandler
|
| 278 |
+
|
| 279 |
+
set self.verbose_crash=True to use our full crashhandler, instead of
|
| 280 |
+
a regular traceback with a short message (crash_handler_lite)
|
| 281 |
+
"""
|
| 282 |
+
|
| 283 |
+
if self.verbose_crash:
|
| 284 |
+
return self.crash_handler(etype, evalue, tb)
|
| 285 |
+
else:
|
| 286 |
+
return crashhandler.crash_handler_lite(etype, evalue, tb)
|
| 287 |
+
|
| 288 |
+
@observe('ipython_dir')
|
| 289 |
+
def _ipython_dir_changed(self, change):
|
| 290 |
+
old = change['old']
|
| 291 |
+
new = change['new']
|
| 292 |
+
if old is not Undefined:
|
| 293 |
+
str_old = os.path.abspath(old)
|
| 294 |
+
if str_old in sys.path:
|
| 295 |
+
sys.path.remove(str_old)
|
| 296 |
+
if self.add_ipython_dir_to_sys_path:
|
| 297 |
+
str_path = os.path.abspath(new)
|
| 298 |
+
sys.path.append(str_path)
|
| 299 |
+
ensure_dir_exists(new)
|
| 300 |
+
readme = os.path.join(new, "README")
|
| 301 |
+
readme_src = os.path.join(
|
| 302 |
+
get_ipython_package_dir(), "config", "profile", "README"
|
| 303 |
+
)
|
| 304 |
+
if not os.path.exists(readme) and os.path.exists(readme_src):
|
| 305 |
+
shutil.copy(readme_src, readme)
|
| 306 |
+
for d in ("extensions", "nbextensions"):
|
| 307 |
+
path = os.path.join(new, d)
|
| 308 |
+
try:
|
| 309 |
+
ensure_dir_exists(path)
|
| 310 |
+
except OSError as e:
|
| 311 |
+
# this will not be EEXIST
|
| 312 |
+
self.log.error("couldn't create path %s: %s", path, e)
|
| 313 |
+
self.log.debug("IPYTHONDIR set to: %s", new)
|
| 314 |
+
|
| 315 |
+
def load_config_file(self, suppress_errors=IPYTHON_SUPPRESS_CONFIG_ERRORS):
|
| 316 |
+
"""Load the config file.
|
| 317 |
+
|
| 318 |
+
By default, errors in loading config are handled, and a warning
|
| 319 |
+
printed on screen. For testing, the suppress_errors option is set
|
| 320 |
+
to False, so errors will make tests fail.
|
| 321 |
+
|
| 322 |
+
`suppress_errors` default value is to be `None` in which case the
|
| 323 |
+
behavior default to the one of `traitlets.Application`.
|
| 324 |
+
|
| 325 |
+
The default value can be set :
|
| 326 |
+
- to `False` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '0', or 'false' (case insensitive).
|
| 327 |
+
- to `True` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '1' or 'true' (case insensitive).
|
| 328 |
+
- to `None` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '' (empty string) or leaving it unset.
|
| 329 |
+
|
| 330 |
+
Any other value are invalid, and will make IPython exit with a non-zero return code.
|
| 331 |
+
"""
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
self.log.debug("Searching path %s for config files", self.config_file_paths)
|
| 335 |
+
base_config = 'ipython_config.py'
|
| 336 |
+
self.log.debug("Attempting to load config file: %s" %
|
| 337 |
+
base_config)
|
| 338 |
+
try:
|
| 339 |
+
if suppress_errors is not None:
|
| 340 |
+
old_value = Application.raise_config_file_errors
|
| 341 |
+
Application.raise_config_file_errors = not suppress_errors;
|
| 342 |
+
Application.load_config_file(
|
| 343 |
+
self,
|
| 344 |
+
base_config,
|
| 345 |
+
path=self.config_file_paths
|
| 346 |
+
)
|
| 347 |
+
except ConfigFileNotFound:
|
| 348 |
+
# ignore errors loading parent
|
| 349 |
+
self.log.debug("Config file %s not found", base_config)
|
| 350 |
+
pass
|
| 351 |
+
if suppress_errors is not None:
|
| 352 |
+
Application.raise_config_file_errors = old_value
|
| 353 |
+
|
| 354 |
+
for config_file_name in self.config_files:
|
| 355 |
+
if not config_file_name or config_file_name == base_config:
|
| 356 |
+
continue
|
| 357 |
+
self.log.debug("Attempting to load config file: %s" %
|
| 358 |
+
self.config_file_name)
|
| 359 |
+
try:
|
| 360 |
+
Application.load_config_file(
|
| 361 |
+
self,
|
| 362 |
+
config_file_name,
|
| 363 |
+
path=self.config_file_paths
|
| 364 |
+
)
|
| 365 |
+
except ConfigFileNotFound:
|
| 366 |
+
# Only warn if the default config file was NOT being used.
|
| 367 |
+
if config_file_name in self.config_file_specified:
|
| 368 |
+
msg = self.log.warning
|
| 369 |
+
else:
|
| 370 |
+
msg = self.log.debug
|
| 371 |
+
msg("Config file not found, skipping: %s", config_file_name)
|
| 372 |
+
except Exception:
|
| 373 |
+
# For testing purposes.
|
| 374 |
+
if not suppress_errors:
|
| 375 |
+
raise
|
| 376 |
+
self.log.warning("Error loading config file: %s" %
|
| 377 |
+
self.config_file_name, exc_info=True)
|
| 378 |
+
|
| 379 |
+
def init_profile_dir(self):
|
| 380 |
+
"""initialize the profile dir"""
|
| 381 |
+
self._in_init_profile_dir = True
|
| 382 |
+
if self.profile_dir is not None:
|
| 383 |
+
# already ran
|
| 384 |
+
return
|
| 385 |
+
if 'ProfileDir.location' not in self.config:
|
| 386 |
+
# location not specified, find by profile name
|
| 387 |
+
try:
|
| 388 |
+
p = ProfileDir.find_profile_dir_by_name(self.ipython_dir, self.profile, self.config)
|
| 389 |
+
except ProfileDirError:
|
| 390 |
+
# not found, maybe create it (always create default profile)
|
| 391 |
+
if self.auto_create or self.profile == 'default':
|
| 392 |
+
try:
|
| 393 |
+
p = ProfileDir.create_profile_dir_by_name(self.ipython_dir, self.profile, self.config)
|
| 394 |
+
except ProfileDirError:
|
| 395 |
+
self.log.fatal("Could not create profile: %r"%self.profile)
|
| 396 |
+
self.exit(1)
|
| 397 |
+
else:
|
| 398 |
+
self.log.info("Created profile dir: %r"%p.location)
|
| 399 |
+
else:
|
| 400 |
+
self.log.fatal("Profile %r not found."%self.profile)
|
| 401 |
+
self.exit(1)
|
| 402 |
+
else:
|
| 403 |
+
self.log.debug("Using existing profile dir: %r", p.location)
|
| 404 |
+
else:
|
| 405 |
+
location = self.config.ProfileDir.location
|
| 406 |
+
# location is fully specified
|
| 407 |
+
try:
|
| 408 |
+
p = ProfileDir.find_profile_dir(location, self.config)
|
| 409 |
+
except ProfileDirError:
|
| 410 |
+
# not found, maybe create it
|
| 411 |
+
if self.auto_create:
|
| 412 |
+
try:
|
| 413 |
+
p = ProfileDir.create_profile_dir(location, self.config)
|
| 414 |
+
except ProfileDirError:
|
| 415 |
+
self.log.fatal("Could not create profile directory: %r"%location)
|
| 416 |
+
self.exit(1)
|
| 417 |
+
else:
|
| 418 |
+
self.log.debug("Creating new profile dir: %r"%location)
|
| 419 |
+
else:
|
| 420 |
+
self.log.fatal("Profile directory %r not found."%location)
|
| 421 |
+
self.exit(1)
|
| 422 |
+
else:
|
| 423 |
+
self.log.debug("Using existing profile dir: %r", p.location)
|
| 424 |
+
# if profile_dir is specified explicitly, set profile name
|
| 425 |
+
dir_name = os.path.basename(p.location)
|
| 426 |
+
if dir_name.startswith('profile_'):
|
| 427 |
+
self.profile = dir_name[8:]
|
| 428 |
+
|
| 429 |
+
self.profile_dir = p
|
| 430 |
+
self.config_file_paths.append(p.location)
|
| 431 |
+
self._in_init_profile_dir = False
|
| 432 |
+
|
| 433 |
+
def init_config_files(self):
|
| 434 |
+
"""[optionally] copy default config files into profile dir."""
|
| 435 |
+
self.config_file_paths.extend(ENV_CONFIG_DIRS)
|
| 436 |
+
self.config_file_paths.extend(SYSTEM_CONFIG_DIRS)
|
| 437 |
+
# copy config files
|
| 438 |
+
path = Path(self.builtin_profile_dir)
|
| 439 |
+
if self.copy_config_files:
|
| 440 |
+
src = self.profile
|
| 441 |
+
|
| 442 |
+
cfg = self.config_file_name
|
| 443 |
+
if path and (path / cfg).exists():
|
| 444 |
+
self.log.warning(
|
| 445 |
+
"Staging %r from %s into %r [overwrite=%s]"
|
| 446 |
+
% (cfg, src, self.profile_dir.location, self.overwrite)
|
| 447 |
+
)
|
| 448 |
+
self.profile_dir.copy_config_file(cfg, path=path, overwrite=self.overwrite)
|
| 449 |
+
else:
|
| 450 |
+
self.stage_default_config_file()
|
| 451 |
+
else:
|
| 452 |
+
# Still stage *bundled* config files, but not generated ones
|
| 453 |
+
# This is necessary for `ipython profile=sympy` to load the profile
|
| 454 |
+
# on the first go
|
| 455 |
+
files = path.glob("*.py")
|
| 456 |
+
for fullpath in files:
|
| 457 |
+
cfg = fullpath.name
|
| 458 |
+
if self.profile_dir.copy_config_file(cfg, path=path, overwrite=False):
|
| 459 |
+
# file was copied
|
| 460 |
+
self.log.warning("Staging bundled %s from %s into %r"%(
|
| 461 |
+
cfg, self.profile, self.profile_dir.location)
|
| 462 |
+
)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def stage_default_config_file(self):
|
| 466 |
+
"""auto generate default config file, and stage it into the profile."""
|
| 467 |
+
s = self.generate_config_file()
|
| 468 |
+
config_file = Path(self.profile_dir.location) / self.config_file_name
|
| 469 |
+
if self.overwrite or not config_file.exists():
|
| 470 |
+
self.log.warning("Generating default config file: %r", (config_file))
|
| 471 |
+
config_file.write_text(s, encoding="utf-8")
|
| 472 |
+
|
| 473 |
+
@catch_config_error
|
| 474 |
+
def initialize(self, argv=None):
|
| 475 |
+
# don't hook up crash handler before parsing command-line
|
| 476 |
+
self.parse_command_line(argv)
|
| 477 |
+
self.init_crash_handler()
|
| 478 |
+
if self.subapp is not None:
|
| 479 |
+
# stop here if subapp is taking over
|
| 480 |
+
return
|
| 481 |
+
# save a copy of CLI config to re-load after config files
|
| 482 |
+
# so that it has highest priority
|
| 483 |
+
cl_config = deepcopy(self.config)
|
| 484 |
+
self.init_profile_dir()
|
| 485 |
+
self.init_config_files()
|
| 486 |
+
self.load_config_file()
|
| 487 |
+
# enforce cl-opts override configfile opts:
|
| 488 |
+
self.update_config(cl_config)
|
.venv/lib/python3.9/site-packages/IPython/core/async_helpers.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Async helper function that are invalid syntax on Python 3.5 and below.
|
| 3 |
+
|
| 4 |
+
This code is best effort, and may have edge cases not behaving as expected. In
|
| 5 |
+
particular it contain a number of heuristics to detect whether code is
|
| 6 |
+
effectively async and need to run in an event loop or not.
|
| 7 |
+
|
| 8 |
+
Some constructs (like top-level `return`, or `yield`) are taken care of
|
| 9 |
+
explicitly to actually raise a SyntaxError and stay as close as possible to
|
| 10 |
+
Python semantics.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
import ast
|
| 15 |
+
import asyncio
|
| 16 |
+
import inspect
|
| 17 |
+
from functools import wraps
|
| 18 |
+
|
| 19 |
+
_asyncio_event_loop = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def get_asyncio_loop():
|
| 23 |
+
"""asyncio has deprecated get_event_loop
|
| 24 |
+
|
| 25 |
+
Replicate it here, with our desired semantics:
|
| 26 |
+
|
| 27 |
+
- always returns a valid, not-closed loop
|
| 28 |
+
- not thread-local like asyncio's,
|
| 29 |
+
because we only want one loop for IPython
|
| 30 |
+
- if called from inside a coroutine (e.g. in ipykernel),
|
| 31 |
+
return the running loop
|
| 32 |
+
|
| 33 |
+
.. versionadded:: 8.0
|
| 34 |
+
"""
|
| 35 |
+
try:
|
| 36 |
+
return asyncio.get_running_loop()
|
| 37 |
+
except RuntimeError:
|
| 38 |
+
# not inside a coroutine,
|
| 39 |
+
# track our own global
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
# not thread-local like asyncio's,
|
| 43 |
+
# because we only track one event loop to run for IPython itself,
|
| 44 |
+
# always in the main thread.
|
| 45 |
+
global _asyncio_event_loop
|
| 46 |
+
if _asyncio_event_loop is None or _asyncio_event_loop.is_closed():
|
| 47 |
+
_asyncio_event_loop = asyncio.new_event_loop()
|
| 48 |
+
return _asyncio_event_loop
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class _AsyncIORunner:
|
| 52 |
+
def __call__(self, coro):
|
| 53 |
+
"""
|
| 54 |
+
Handler for asyncio autoawait
|
| 55 |
+
"""
|
| 56 |
+
return get_asyncio_loop().run_until_complete(coro)
|
| 57 |
+
|
| 58 |
+
def __str__(self):
|
| 59 |
+
return "asyncio"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
_asyncio_runner = _AsyncIORunner()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class _AsyncIOProxy:
|
| 66 |
+
"""Proxy-object for an asyncio
|
| 67 |
+
|
| 68 |
+
Any coroutine methods will be wrapped in event_loop.run_
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
def __init__(self, obj, event_loop):
|
| 72 |
+
self._obj = obj
|
| 73 |
+
self._event_loop = event_loop
|
| 74 |
+
|
| 75 |
+
def __repr__(self):
|
| 76 |
+
return f"<_AsyncIOProxy({self._obj!r})>"
|
| 77 |
+
|
| 78 |
+
def __getattr__(self, key):
|
| 79 |
+
attr = getattr(self._obj, key)
|
| 80 |
+
if inspect.iscoroutinefunction(attr):
|
| 81 |
+
# if it's a coroutine method,
|
| 82 |
+
# return a threadsafe wrapper onto the _current_ asyncio loop
|
| 83 |
+
@wraps(attr)
|
| 84 |
+
def _wrapped(*args, **kwargs):
|
| 85 |
+
concurrent_future = asyncio.run_coroutine_threadsafe(
|
| 86 |
+
attr(*args, **kwargs), self._event_loop
|
| 87 |
+
)
|
| 88 |
+
return asyncio.wrap_future(concurrent_future)
|
| 89 |
+
|
| 90 |
+
return _wrapped
|
| 91 |
+
else:
|
| 92 |
+
return attr
|
| 93 |
+
|
| 94 |
+
def __dir__(self):
|
| 95 |
+
return dir(self._obj)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def _curio_runner(coroutine):
|
| 99 |
+
"""
|
| 100 |
+
handler for curio autoawait
|
| 101 |
+
"""
|
| 102 |
+
import curio
|
| 103 |
+
|
| 104 |
+
return curio.run(coroutine)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _trio_runner(async_fn):
|
| 108 |
+
import trio
|
| 109 |
+
|
| 110 |
+
async def loc(coro):
|
| 111 |
+
"""
|
| 112 |
+
We need the dummy no-op async def to protect from
|
| 113 |
+
trio's internal. See https://github.com/python-trio/trio/issues/89
|
| 114 |
+
"""
|
| 115 |
+
return await coro
|
| 116 |
+
|
| 117 |
+
return trio.run(loc, async_fn)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _pseudo_sync_runner(coro):
|
| 121 |
+
"""
|
| 122 |
+
A runner that does not really allow async execution, and just advance the coroutine.
|
| 123 |
+
|
| 124 |
+
See discussion in https://github.com/python-trio/trio/issues/608,
|
| 125 |
+
|
| 126 |
+
Credit to Nathaniel Smith
|
| 127 |
+
"""
|
| 128 |
+
try:
|
| 129 |
+
coro.send(None)
|
| 130 |
+
except StopIteration as exc:
|
| 131 |
+
return exc.value
|
| 132 |
+
else:
|
| 133 |
+
# TODO: do not raise but return an execution result with the right info.
|
| 134 |
+
raise RuntimeError(
|
| 135 |
+
"{coro_name!r} needs a real async loop".format(coro_name=coro.__name__)
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _should_be_async(cell: str) -> bool:
|
| 140 |
+
"""Detect if a block of code need to be wrapped in an `async def`
|
| 141 |
+
|
| 142 |
+
Attempt to parse the block of code, it it compile we're fine.
|
| 143 |
+
Otherwise we wrap if and try to compile.
|
| 144 |
+
|
| 145 |
+
If it works, assume it should be async. Otherwise Return False.
|
| 146 |
+
|
| 147 |
+
Not handled yet: If the block of code has a return statement as the top
|
| 148 |
+
level, it will be seen as async. This is a know limitation.
|
| 149 |
+
"""
|
| 150 |
+
try:
|
| 151 |
+
code = compile(
|
| 152 |
+
cell, "<>", "exec", flags=getattr(ast, "PyCF_ALLOW_TOP_LEVEL_AWAIT", 0x0)
|
| 153 |
+
)
|
| 154 |
+
return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
|
| 155 |
+
except (SyntaxError, MemoryError):
|
| 156 |
+
return False
|
.venv/lib/python3.9/site-packages/IPython/core/autocall.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""
|
| 3 |
+
Autocall capabilities for IPython.core.
|
| 4 |
+
|
| 5 |
+
Authors:
|
| 6 |
+
|
| 7 |
+
* Brian Granger
|
| 8 |
+
* Fernando Perez
|
| 9 |
+
* Thomas Kluyver
|
| 10 |
+
|
| 11 |
+
Notes
|
| 12 |
+
-----
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
#-----------------------------------------------------------------------------
|
| 16 |
+
# Copyright (C) 2008-2011 The IPython Development Team
|
| 17 |
+
#
|
| 18 |
+
# Distributed under the terms of the BSD License. The full license is in
|
| 19 |
+
# the file COPYING, distributed as part of this software.
|
| 20 |
+
#-----------------------------------------------------------------------------
|
| 21 |
+
|
| 22 |
+
#-----------------------------------------------------------------------------
|
| 23 |
+
# Imports
|
| 24 |
+
#-----------------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
#-----------------------------------------------------------------------------
|
| 28 |
+
# Code
|
| 29 |
+
#-----------------------------------------------------------------------------
|
| 30 |
+
|
| 31 |
+
class IPyAutocall(object):
|
| 32 |
+
""" Instances of this class are always autocalled
|
| 33 |
+
|
| 34 |
+
This happens regardless of 'autocall' variable state. Use this to
|
| 35 |
+
develop macro-like mechanisms.
|
| 36 |
+
"""
|
| 37 |
+
_ip = None
|
| 38 |
+
rewrite = True
|
| 39 |
+
def __init__(self, ip=None):
|
| 40 |
+
self._ip = ip
|
| 41 |
+
|
| 42 |
+
def set_ip(self, ip):
|
| 43 |
+
"""Will be used to set _ip point to current ipython instance b/f call
|
| 44 |
+
|
| 45 |
+
Override this method if you don't want this to happen.
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
self._ip = ip
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class ExitAutocall(IPyAutocall):
|
| 52 |
+
"""An autocallable object which will be added to the user namespace so that
|
| 53 |
+
exit, exit(), quit or quit() are all valid ways to close the shell."""
|
| 54 |
+
rewrite = False
|
| 55 |
+
|
| 56 |
+
def __call__(self):
|
| 57 |
+
self._ip.ask_exit()
|
| 58 |
+
|
| 59 |
+
class ZMQExitAutocall(ExitAutocall):
|
| 60 |
+
"""Exit IPython. Autocallable, so it needn't be explicitly called.
|
| 61 |
+
|
| 62 |
+
Parameters
|
| 63 |
+
----------
|
| 64 |
+
keep_kernel : bool
|
| 65 |
+
If True, leave the kernel alive. Otherwise, tell the kernel to exit too
|
| 66 |
+
(default).
|
| 67 |
+
"""
|
| 68 |
+
def __call__(self, keep_kernel=False):
|
| 69 |
+
self._ip.keepkernel_on_exit = keep_kernel
|
| 70 |
+
self._ip.ask_exit()
|
.venv/lib/python3.9/site-packages/IPython/core/builtin_trap.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A context manager for managing things injected into :mod:`builtins`.
|
| 3 |
+
"""
|
| 4 |
+
# Copyright (c) IPython Development Team.
|
| 5 |
+
# Distributed under the terms of the Modified BSD License.
|
| 6 |
+
import builtins as builtin_mod
|
| 7 |
+
|
| 8 |
+
from traitlets.config.configurable import Configurable
|
| 9 |
+
|
| 10 |
+
from traitlets import Instance
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class __BuiltinUndefined(object): pass
|
| 14 |
+
BuiltinUndefined = __BuiltinUndefined()
|
| 15 |
+
|
| 16 |
+
class __HideBuiltin(object): pass
|
| 17 |
+
HideBuiltin = __HideBuiltin()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class BuiltinTrap(Configurable):
|
| 21 |
+
|
| 22 |
+
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
|
| 23 |
+
allow_none=True)
|
| 24 |
+
|
| 25 |
+
def __init__(self, shell=None):
|
| 26 |
+
super(BuiltinTrap, self).__init__(shell=shell, config=None)
|
| 27 |
+
self._orig_builtins = {}
|
| 28 |
+
# We define this to track if a single BuiltinTrap is nested.
|
| 29 |
+
# Only turn off the trap when the outermost call to __exit__ is made.
|
| 30 |
+
self._nested_level = 0
|
| 31 |
+
self.shell = shell
|
| 32 |
+
# builtins we always add - if set to HideBuiltin, they will just
|
| 33 |
+
# be removed instead of being replaced by something else
|
| 34 |
+
self.auto_builtins = {'exit': HideBuiltin,
|
| 35 |
+
'quit': HideBuiltin,
|
| 36 |
+
'get_ipython': self.shell.get_ipython,
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
def __enter__(self):
|
| 40 |
+
if self._nested_level == 0:
|
| 41 |
+
self.activate()
|
| 42 |
+
self._nested_level += 1
|
| 43 |
+
# I return self, so callers can use add_builtin in a with clause.
|
| 44 |
+
return self
|
| 45 |
+
|
| 46 |
+
def __exit__(self, type, value, traceback):
|
| 47 |
+
if self._nested_level == 1:
|
| 48 |
+
self.deactivate()
|
| 49 |
+
self._nested_level -= 1
|
| 50 |
+
# Returning False will cause exceptions to propagate
|
| 51 |
+
return False
|
| 52 |
+
|
| 53 |
+
def add_builtin(self, key, value):
|
| 54 |
+
"""Add a builtin and save the original."""
|
| 55 |
+
bdict = builtin_mod.__dict__
|
| 56 |
+
orig = bdict.get(key, BuiltinUndefined)
|
| 57 |
+
if value is HideBuiltin:
|
| 58 |
+
if orig is not BuiltinUndefined: #same as 'key in bdict'
|
| 59 |
+
self._orig_builtins[key] = orig
|
| 60 |
+
del bdict[key]
|
| 61 |
+
else:
|
| 62 |
+
self._orig_builtins[key] = orig
|
| 63 |
+
bdict[key] = value
|
| 64 |
+
|
| 65 |
+
def remove_builtin(self, key, orig):
|
| 66 |
+
"""Remove an added builtin and re-set the original."""
|
| 67 |
+
if orig is BuiltinUndefined:
|
| 68 |
+
del builtin_mod.__dict__[key]
|
| 69 |
+
else:
|
| 70 |
+
builtin_mod.__dict__[key] = orig
|
| 71 |
+
|
| 72 |
+
def activate(self):
|
| 73 |
+
"""Store ipython references in the __builtin__ namespace."""
|
| 74 |
+
|
| 75 |
+
add_builtin = self.add_builtin
|
| 76 |
+
for name, func in self.auto_builtins.items():
|
| 77 |
+
add_builtin(name, func)
|
| 78 |
+
|
| 79 |
+
def deactivate(self):
|
| 80 |
+
"""Remove any builtins which might have been added by add_builtins, or
|
| 81 |
+
restore overwritten ones to their previous values."""
|
| 82 |
+
remove_builtin = self.remove_builtin
|
| 83 |
+
for key, val in self._orig_builtins.items():
|
| 84 |
+
remove_builtin(key, val)
|
| 85 |
+
self._orig_builtins.clear()
|
| 86 |
+
self._builtins_added = False
|
.venv/lib/python3.9/site-packages/IPython/core/compilerop.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Compiler tools with improved interactive support.
|
| 2 |
+
|
| 3 |
+
Provides compilation machinery similar to codeop, but with caching support so
|
| 4 |
+
we can provide interactive tracebacks.
|
| 5 |
+
|
| 6 |
+
Authors
|
| 7 |
+
-------
|
| 8 |
+
* Robert Kern
|
| 9 |
+
* Fernando Perez
|
| 10 |
+
* Thomas Kluyver
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
# Note: though it might be more natural to name this module 'compiler', that
|
| 14 |
+
# name is in the stdlib and name collisions with the stdlib tend to produce
|
| 15 |
+
# weird problems (often with third-party tools).
|
| 16 |
+
|
| 17 |
+
#-----------------------------------------------------------------------------
|
| 18 |
+
# Copyright (C) 2010-2011 The IPython Development Team.
|
| 19 |
+
#
|
| 20 |
+
# Distributed under the terms of the BSD License.
|
| 21 |
+
#
|
| 22 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 23 |
+
#-----------------------------------------------------------------------------
|
| 24 |
+
|
| 25 |
+
#-----------------------------------------------------------------------------
|
| 26 |
+
# Imports
|
| 27 |
+
#-----------------------------------------------------------------------------
|
| 28 |
+
|
| 29 |
+
# Stdlib imports
|
| 30 |
+
import __future__
|
| 31 |
+
from ast import PyCF_ONLY_AST
|
| 32 |
+
import codeop
|
| 33 |
+
import functools
|
| 34 |
+
import hashlib
|
| 35 |
+
import linecache
|
| 36 |
+
import operator
|
| 37 |
+
import time
|
| 38 |
+
from contextlib import contextmanager
|
| 39 |
+
|
| 40 |
+
#-----------------------------------------------------------------------------
|
| 41 |
+
# Constants
|
| 42 |
+
#-----------------------------------------------------------------------------
|
| 43 |
+
|
| 44 |
+
# Roughly equal to PyCF_MASK | PyCF_MASK_OBSOLETE as defined in pythonrun.h,
|
| 45 |
+
# this is used as a bitmask to extract future-related code flags.
|
| 46 |
+
PyCF_MASK = functools.reduce(operator.or_,
|
| 47 |
+
(getattr(__future__, fname).compiler_flag
|
| 48 |
+
for fname in __future__.all_feature_names))
|
| 49 |
+
|
| 50 |
+
#-----------------------------------------------------------------------------
|
| 51 |
+
# Local utilities
|
| 52 |
+
#-----------------------------------------------------------------------------
|
| 53 |
+
|
| 54 |
+
def code_name(code, number=0):
|
| 55 |
+
""" Compute a (probably) unique name for code for caching.
|
| 56 |
+
|
| 57 |
+
This now expects code to be unicode.
|
| 58 |
+
"""
|
| 59 |
+
hash_digest = hashlib.sha1(code.encode("utf-8")).hexdigest()
|
| 60 |
+
# Include the number and 12 characters of the hash in the name. It's
|
| 61 |
+
# pretty much impossible that in a single session we'll have collisions
|
| 62 |
+
# even with truncated hashes, and the full one makes tracebacks too long
|
| 63 |
+
return '<ipython-input-{0}-{1}>'.format(number, hash_digest[:12])
|
| 64 |
+
|
| 65 |
+
#-----------------------------------------------------------------------------
|
| 66 |
+
# Classes and functions
|
| 67 |
+
#-----------------------------------------------------------------------------
|
| 68 |
+
|
| 69 |
+
class CachingCompiler(codeop.Compile):
|
| 70 |
+
"""A compiler that caches code compiled from interactive statements.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
def __init__(self):
|
| 74 |
+
codeop.Compile.__init__(self)
|
| 75 |
+
|
| 76 |
+
# Caching a dictionary { filename: execution_count } for nicely
|
| 77 |
+
# rendered tracebacks. The filename corresponds to the filename
|
| 78 |
+
# argument used for the builtins.compile function.
|
| 79 |
+
self._filename_map = {}
|
| 80 |
+
|
| 81 |
+
def ast_parse(self, source, filename='<unknown>', symbol='exec'):
|
| 82 |
+
"""Parse code to an AST with the current compiler flags active.
|
| 83 |
+
|
| 84 |
+
Arguments are exactly the same as ast.parse (in the standard library),
|
| 85 |
+
and are passed to the built-in compile function."""
|
| 86 |
+
return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)
|
| 87 |
+
|
| 88 |
+
def reset_compiler_flags(self):
|
| 89 |
+
"""Reset compiler flags to default state."""
|
| 90 |
+
# This value is copied from codeop.Compile.__init__, so if that ever
|
| 91 |
+
# changes, it will need to be updated.
|
| 92 |
+
self.flags = codeop.PyCF_DONT_IMPLY_DEDENT
|
| 93 |
+
|
| 94 |
+
@property
|
| 95 |
+
def compiler_flags(self):
|
| 96 |
+
"""Flags currently active in the compilation process.
|
| 97 |
+
"""
|
| 98 |
+
return self.flags
|
| 99 |
+
|
| 100 |
+
def get_code_name(self, raw_code, transformed_code, number):
|
| 101 |
+
"""Compute filename given the code, and the cell number.
|
| 102 |
+
|
| 103 |
+
Parameters
|
| 104 |
+
----------
|
| 105 |
+
raw_code : str
|
| 106 |
+
The raw cell code.
|
| 107 |
+
transformed_code : str
|
| 108 |
+
The executable Python source code to cache and compile.
|
| 109 |
+
number : int
|
| 110 |
+
A number which forms part of the code's name. Used for the execution
|
| 111 |
+
counter.
|
| 112 |
+
|
| 113 |
+
Returns
|
| 114 |
+
-------
|
| 115 |
+
The computed filename.
|
| 116 |
+
"""
|
| 117 |
+
return code_name(transformed_code, number)
|
| 118 |
+
|
| 119 |
+
def format_code_name(self, name):
|
| 120 |
+
"""Return a user-friendly label and name for a code block.
|
| 121 |
+
|
| 122 |
+
Parameters
|
| 123 |
+
----------
|
| 124 |
+
name : str
|
| 125 |
+
The name for the code block returned from get_code_name
|
| 126 |
+
|
| 127 |
+
Returns
|
| 128 |
+
-------
|
| 129 |
+
A (label, name) pair that can be used in tracebacks, or None if the default formatting should be used.
|
| 130 |
+
"""
|
| 131 |
+
if name in self._filename_map:
|
| 132 |
+
return "Cell", "In[%s]" % self._filename_map[name]
|
| 133 |
+
|
| 134 |
+
def cache(self, transformed_code, number=0, raw_code=None):
|
| 135 |
+
"""Make a name for a block of code, and cache the code.
|
| 136 |
+
|
| 137 |
+
Parameters
|
| 138 |
+
----------
|
| 139 |
+
transformed_code : str
|
| 140 |
+
The executable Python source code to cache and compile.
|
| 141 |
+
number : int
|
| 142 |
+
A number which forms part of the code's name. Used for the execution
|
| 143 |
+
counter.
|
| 144 |
+
raw_code : str
|
| 145 |
+
The raw code before transformation, if None, set to `transformed_code`.
|
| 146 |
+
|
| 147 |
+
Returns
|
| 148 |
+
-------
|
| 149 |
+
The name of the cached code (as a string). Pass this as the filename
|
| 150 |
+
argument to compilation, so that tracebacks are correctly hooked up.
|
| 151 |
+
"""
|
| 152 |
+
if raw_code is None:
|
| 153 |
+
raw_code = transformed_code
|
| 154 |
+
|
| 155 |
+
name = self.get_code_name(raw_code, transformed_code, number)
|
| 156 |
+
|
| 157 |
+
# Save the execution count
|
| 158 |
+
self._filename_map[name] = number
|
| 159 |
+
|
| 160 |
+
# Since Python 2.5, setting mtime to `None` means the lines will
|
| 161 |
+
# never be removed by `linecache.checkcache`. This means all the
|
| 162 |
+
# monkeypatching has *never* been necessary, since this code was
|
| 163 |
+
# only added in 2010, at which point IPython had already stopped
|
| 164 |
+
# supporting Python 2.4.
|
| 165 |
+
#
|
| 166 |
+
# Note that `linecache.clearcache` and `linecache.updatecache` may
|
| 167 |
+
# still remove our code from the cache, but those show explicit
|
| 168 |
+
# intent, and we should not try to interfere. Normally the former
|
| 169 |
+
# is never called except when out of memory, and the latter is only
|
| 170 |
+
# called for lines *not* in the cache.
|
| 171 |
+
entry = (
|
| 172 |
+
len(transformed_code),
|
| 173 |
+
None,
|
| 174 |
+
[line + "\n" for line in transformed_code.splitlines()],
|
| 175 |
+
name,
|
| 176 |
+
)
|
| 177 |
+
linecache.cache[name] = entry
|
| 178 |
+
return name
|
| 179 |
+
|
| 180 |
+
@contextmanager
|
| 181 |
+
def extra_flags(self, flags):
|
| 182 |
+
## bits that we'll set to 1
|
| 183 |
+
turn_on_bits = ~self.flags & flags
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
self.flags = self.flags | flags
|
| 187 |
+
try:
|
| 188 |
+
yield
|
| 189 |
+
finally:
|
| 190 |
+
# turn off only the bits we turned on so that something like
|
| 191 |
+
# __future__ that set flags stays.
|
| 192 |
+
self.flags &= ~turn_on_bits
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def check_linecache_ipython(*args):
|
| 196 |
+
"""Deprecated since IPython 8.6. Call linecache.checkcache() directly.
|
| 197 |
+
|
| 198 |
+
It was already not necessary to call this function directly. If no
|
| 199 |
+
CachingCompiler had been created, this function would fail badly. If
|
| 200 |
+
an instance had been created, this function would've been monkeypatched
|
| 201 |
+
into place.
|
| 202 |
+
|
| 203 |
+
As of IPython 8.6, the monkeypatching has gone away entirely. But there
|
| 204 |
+
were still internal callers of this function, so maybe external callers
|
| 205 |
+
also existed?
|
| 206 |
+
"""
|
| 207 |
+
import warnings
|
| 208 |
+
|
| 209 |
+
warnings.warn(
|
| 210 |
+
"Deprecated Since IPython 8.6, Just call linecache.checkcache() directly.",
|
| 211 |
+
DeprecationWarning,
|
| 212 |
+
stacklevel=2,
|
| 213 |
+
)
|
| 214 |
+
linecache.checkcache()
|
.venv/lib/python3.9/site-packages/IPython/core/completer.py
ADDED
|
The diff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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""Implementations for various useful completers.
|
| 3 |
+
|
| 4 |
+
These are all loaded by default by IPython.
|
| 5 |
+
"""
|
| 6 |
+
#-----------------------------------------------------------------------------
|
| 7 |
+
# Copyright (C) 2010-2011 The IPython Development Team.
|
| 8 |
+
#
|
| 9 |
+
# Distributed under the terms of the BSD License.
|
| 10 |
+
#
|
| 11 |
+
# The full license is in the file COPYING.txt, distributed with this software.
|
| 12 |
+
#-----------------------------------------------------------------------------
|
| 13 |
+
|
| 14 |
+
#-----------------------------------------------------------------------------
|
| 15 |
+
# Imports
|
| 16 |
+
#-----------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
# Stdlib imports
|
| 19 |
+
import glob
|
| 20 |
+
import inspect
|
| 21 |
+
import os
|
| 22 |
+
import re
|
| 23 |
+
import sys
|
| 24 |
+
from importlib import import_module
|
| 25 |
+
from importlib.machinery import all_suffixes
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Third-party imports
|
| 29 |
+
from time import time
|
| 30 |
+
from zipimport import zipimporter
|
| 31 |
+
|
| 32 |
+
# Our own imports
|
| 33 |
+
from .completer import expand_user, compress_user
|
| 34 |
+
from .error import TryNext
|
| 35 |
+
from ..utils._process_common import arg_split
|
| 36 |
+
|
| 37 |
+
# FIXME: this should be pulled in with the right call via the component system
|
| 38 |
+
from IPython import get_ipython
|
| 39 |
+
|
| 40 |
+
from typing import List
|
| 41 |
+
|
| 42 |
+
#-----------------------------------------------------------------------------
|
| 43 |
+
# Globals and constants
|
| 44 |
+
#-----------------------------------------------------------------------------
|
| 45 |
+
_suffixes = all_suffixes()
|
| 46 |
+
|
| 47 |
+
# Time in seconds after which the rootmodules will be stored permanently in the
|
| 48 |
+
# ipython ip.db database (kept in the user's .ipython dir).
|
| 49 |
+
TIMEOUT_STORAGE = 2
|
| 50 |
+
|
| 51 |
+
# Time in seconds after which we give up
|
| 52 |
+
TIMEOUT_GIVEUP = 20
|
| 53 |
+
|
| 54 |
+
# Regular expression for the python import statement
|
| 55 |
+
import_re = re.compile(r'(?P<name>[^\W\d]\w*?)'
|
| 56 |
+
r'(?P<package>[/\\]__init__)?'
|
| 57 |
+
r'(?P<suffix>%s)$' %
|
| 58 |
+
r'|'.join(re.escape(s) for s in _suffixes))
|
| 59 |
+
|
| 60 |
+
# RE for the ipython %run command (python + ipython scripts)
|
| 61 |
+
magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$')
|
| 62 |
+
|
| 63 |
+
#-----------------------------------------------------------------------------
|
| 64 |
+
# Local utilities
|
| 65 |
+
#-----------------------------------------------------------------------------
|
| 66 |
+
|
| 67 |
+
def module_list(path):
|
| 68 |
+
"""
|
| 69 |
+
Return the list containing the names of the modules available in the given
|
| 70 |
+
folder.
|
| 71 |
+
"""
|
| 72 |
+
# sys.path has the cwd as an empty string, but isdir/listdir need it as '.'
|
| 73 |
+
if path == '':
|
| 74 |
+
path = '.'
|
| 75 |
+
|
| 76 |
+
# A few local constants to be used in loops below
|
| 77 |
+
pjoin = os.path.join
|
| 78 |
+
|
| 79 |
+
if os.path.isdir(path):
|
| 80 |
+
# Build a list of all files in the directory and all files
|
| 81 |
+
# in its subdirectories. For performance reasons, do not
|
| 82 |
+
# recurse more than one level into subdirectories.
|
| 83 |
+
files = []
|
| 84 |
+
for root, dirs, nondirs in os.walk(path, followlinks=True):
|
| 85 |
+
subdir = root[len(path)+1:]
|
| 86 |
+
if subdir:
|
| 87 |
+
files.extend(pjoin(subdir, f) for f in nondirs)
|
| 88 |
+
dirs[:] = [] # Do not recurse into additional subdirectories.
|
| 89 |
+
else:
|
| 90 |
+
files.extend(nondirs)
|
| 91 |
+
|
| 92 |
+
else:
|
| 93 |
+
try:
|
| 94 |
+
files = list(zipimporter(path)._files.keys())
|
| 95 |
+
except:
|
| 96 |
+
files = []
|
| 97 |
+
|
| 98 |
+
# Build a list of modules which match the import_re regex.
|
| 99 |
+
modules = []
|
| 100 |
+
for f in files:
|
| 101 |
+
m = import_re.match(f)
|
| 102 |
+
if m:
|
| 103 |
+
modules.append(m.group('name'))
|
| 104 |
+
return list(set(modules))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def get_root_modules():
|
| 108 |
+
"""
|
| 109 |
+
Returns a list containing the names of all the modules available in the
|
| 110 |
+
folders of the pythonpath.
|
| 111 |
+
|
| 112 |
+
ip.db['rootmodules_cache'] maps sys.path entries to list of modules.
|
| 113 |
+
"""
|
| 114 |
+
ip = get_ipython()
|
| 115 |
+
if ip is None:
|
| 116 |
+
# No global shell instance to store cached list of modules.
|
| 117 |
+
# Don't try to scan for modules every time.
|
| 118 |
+
return list(sys.builtin_module_names)
|
| 119 |
+
|
| 120 |
+
if getattr(ip.db, "_mock", False):
|
| 121 |
+
rootmodules_cache = {}
|
| 122 |
+
else:
|
| 123 |
+
rootmodules_cache = ip.db.get("rootmodules_cache", {})
|
| 124 |
+
rootmodules = list(sys.builtin_module_names)
|
| 125 |
+
start_time = time()
|
| 126 |
+
store = False
|
| 127 |
+
for path in sys.path:
|
| 128 |
+
try:
|
| 129 |
+
modules = rootmodules_cache[path]
|
| 130 |
+
except KeyError:
|
| 131 |
+
modules = module_list(path)
|
| 132 |
+
try:
|
| 133 |
+
modules.remove('__init__')
|
| 134 |
+
except ValueError:
|
| 135 |
+
pass
|
| 136 |
+
if path not in ('', '.'): # cwd modules should not be cached
|
| 137 |
+
rootmodules_cache[path] = modules
|
| 138 |
+
if time() - start_time > TIMEOUT_STORAGE and not store:
|
| 139 |
+
store = True
|
| 140 |
+
print("\nCaching the list of root modules, please wait!")
|
| 141 |
+
print("(This will only be done once - type '%rehashx' to "
|
| 142 |
+
"reset cache!)\n")
|
| 143 |
+
sys.stdout.flush()
|
| 144 |
+
if time() - start_time > TIMEOUT_GIVEUP:
|
| 145 |
+
print("This is taking too long, we give up.\n")
|
| 146 |
+
return []
|
| 147 |
+
rootmodules.extend(modules)
|
| 148 |
+
if store:
|
| 149 |
+
ip.db['rootmodules_cache'] = rootmodules_cache
|
| 150 |
+
rootmodules = list(set(rootmodules))
|
| 151 |
+
return rootmodules
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def is_importable(module, attr, only_modules):
|
| 155 |
+
if only_modules:
|
| 156 |
+
return inspect.ismodule(getattr(module, attr))
|
| 157 |
+
else:
|
| 158 |
+
return not(attr[:2] == '__' and attr[-2:] == '__')
|
| 159 |
+
|
| 160 |
+
def is_possible_submodule(module, attr):
|
| 161 |
+
try:
|
| 162 |
+
obj = getattr(module, attr)
|
| 163 |
+
except AttributeError:
|
| 164 |
+
# Is possilby an unimported submodule
|
| 165 |
+
return True
|
| 166 |
+
except TypeError:
|
| 167 |
+
# https://github.com/ipython/ipython/issues/9678
|
| 168 |
+
return False
|
| 169 |
+
return inspect.ismodule(obj)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def try_import(mod: str, only_modules=False) -> List[str]:
|
| 173 |
+
"""
|
| 174 |
+
Try to import given module and return list of potential completions.
|
| 175 |
+
"""
|
| 176 |
+
mod = mod.rstrip('.')
|
| 177 |
+
try:
|
| 178 |
+
m = import_module(mod)
|
| 179 |
+
except:
|
| 180 |
+
return []
|
| 181 |
+
|
| 182 |
+
m_is_init = '__init__' in (getattr(m, '__file__', '') or '')
|
| 183 |
+
|
| 184 |
+
completions = []
|
| 185 |
+
if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init:
|
| 186 |
+
completions.extend( [attr for attr in dir(m) if
|
| 187 |
+
is_importable(m, attr, only_modules)])
|
| 188 |
+
|
| 189 |
+
m_all = getattr(m, "__all__", [])
|
| 190 |
+
if only_modules:
|
| 191 |
+
completions.extend(attr for attr in m_all if is_possible_submodule(m, attr))
|
| 192 |
+
else:
|
| 193 |
+
completions.extend(m_all)
|
| 194 |
+
|
| 195 |
+
if m_is_init:
|
| 196 |
+
file_ = m.__file__
|
| 197 |
+
completions.extend(module_list(os.path.dirname(file_)))
|
| 198 |
+
completions_set = {c for c in completions if isinstance(c, str)}
|
| 199 |
+
completions_set.discard('__init__')
|
| 200 |
+
return list(completions_set)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
#-----------------------------------------------------------------------------
|
| 204 |
+
# Completion-related functions.
|
| 205 |
+
#-----------------------------------------------------------------------------
|
| 206 |
+
|
| 207 |
+
def quick_completer(cmd, completions):
|
| 208 |
+
r""" Easily create a trivial completer for a command.
|
| 209 |
+
|
| 210 |
+
Takes either a list of completions, or all completions in string (that will
|
| 211 |
+
be split on whitespace).
|
| 212 |
+
|
| 213 |
+
Example::
|
| 214 |
+
|
| 215 |
+
[d:\ipython]|1> import ipy_completers
|
| 216 |
+
[d:\ipython]|2> ipy_completers.quick_completer('foo', ['bar','baz'])
|
| 217 |
+
[d:\ipython]|3> foo b<TAB>
|
| 218 |
+
bar baz
|
| 219 |
+
[d:\ipython]|3> foo ba
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
if isinstance(completions, str):
|
| 223 |
+
completions = completions.split()
|
| 224 |
+
|
| 225 |
+
def do_complete(self, event):
|
| 226 |
+
return completions
|
| 227 |
+
|
| 228 |
+
get_ipython().set_hook('complete_command',do_complete, str_key = cmd)
|
| 229 |
+
|
| 230 |
+
def module_completion(line):
|
| 231 |
+
"""
|
| 232 |
+
Returns a list containing the completion possibilities for an import line.
|
| 233 |
+
|
| 234 |
+
The line looks like this :
|
| 235 |
+
'import xml.d'
|
| 236 |
+
'from xml.dom import'
|
| 237 |
+
"""
|
| 238 |
+
|
| 239 |
+
words = line.split(' ')
|
| 240 |
+
nwords = len(words)
|
| 241 |
+
|
| 242 |
+
# from whatever <tab> -> 'import '
|
| 243 |
+
if nwords == 3 and words[0] == 'from':
|
| 244 |
+
return ['import ']
|
| 245 |
+
|
| 246 |
+
# 'from xy<tab>' or 'import xy<tab>'
|
| 247 |
+
if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) :
|
| 248 |
+
if nwords == 1:
|
| 249 |
+
return get_root_modules()
|
| 250 |
+
mod = words[1].split('.')
|
| 251 |
+
if len(mod) < 2:
|
| 252 |
+
return get_root_modules()
|
| 253 |
+
completion_list = try_import('.'.join(mod[:-1]), True)
|
| 254 |
+
return ['.'.join(mod[:-1] + [el]) for el in completion_list]
|
| 255 |
+
|
| 256 |
+
# 'from xyz import abc<tab>'
|
| 257 |
+
if nwords >= 3 and words[0] == 'from':
|
| 258 |
+
mod = words[1]
|
| 259 |
+
return try_import(mod)
|
| 260 |
+
|
| 261 |
+
#-----------------------------------------------------------------------------
|
| 262 |
+
# Completers
|
| 263 |
+
#-----------------------------------------------------------------------------
|
| 264 |
+
# These all have the func(self, event) signature to be used as custom
|
| 265 |
+
# completers
|
| 266 |
+
|
| 267 |
+
def module_completer(self,event):
|
| 268 |
+
"""Give completions after user has typed 'import ...' or 'from ...'"""
|
| 269 |
+
|
| 270 |
+
# This works in all versions of python. While 2.5 has
|
| 271 |
+
# pkgutil.walk_packages(), that particular routine is fairly dangerous,
|
| 272 |
+
# since it imports *EVERYTHING* on sys.path. That is: a) very slow b) full
|
| 273 |
+
# of possibly problematic side effects.
|
| 274 |
+
# This search the folders in the sys.path for available modules.
|
| 275 |
+
|
| 276 |
+
return module_completion(event.line)
|
| 277 |
+
|
| 278 |
+
# FIXME: there's a lot of logic common to the run, cd and builtin file
|
| 279 |
+
# completers, that is currently reimplemented in each.
|
| 280 |
+
|
| 281 |
+
def magic_run_completer(self, event):
|
| 282 |
+
"""Complete files that end in .py or .ipy or .ipynb for the %run command.
|
| 283 |
+
"""
|
| 284 |
+
comps = arg_split(event.line, strict=False)
|
| 285 |
+
# relpath should be the current token that we need to complete.
|
| 286 |
+
if (len(comps) > 1) and (not event.line.endswith(' ')):
|
| 287 |
+
relpath = comps[-1].strip("'\"")
|
| 288 |
+
else:
|
| 289 |
+
relpath = ''
|
| 290 |
+
|
| 291 |
+
#print("\nev=", event) # dbg
|
| 292 |
+
#print("rp=", relpath) # dbg
|
| 293 |
+
#print('comps=', comps) # dbg
|
| 294 |
+
|
| 295 |
+
lglob = glob.glob
|
| 296 |
+
isdir = os.path.isdir
|
| 297 |
+
relpath, tilde_expand, tilde_val = expand_user(relpath)
|
| 298 |
+
|
| 299 |
+
# Find if the user has already typed the first filename, after which we
|
| 300 |
+
# should complete on all files, since after the first one other files may
|
| 301 |
+
# be arguments to the input script.
|
| 302 |
+
|
| 303 |
+
if any(magic_run_re.match(c) for c in comps):
|
| 304 |
+
matches = [f.replace('\\','/') + ('/' if isdir(f) else '')
|
| 305 |
+
for f in lglob(relpath+'*')]
|
| 306 |
+
else:
|
| 307 |
+
dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)]
|
| 308 |
+
pys = [f.replace('\\','/')
|
| 309 |
+
for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') +
|
| 310 |
+
lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')]
|
| 311 |
+
|
| 312 |
+
matches = dirs + pys
|
| 313 |
+
|
| 314 |
+
#print('run comp:', dirs+pys) # dbg
|
| 315 |
+
return [compress_user(p, tilde_expand, tilde_val) for p in matches]
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def cd_completer(self, event):
|
| 319 |
+
"""Completer function for cd, which only returns directories."""
|
| 320 |
+
ip = get_ipython()
|
| 321 |
+
relpath = event.symbol
|
| 322 |
+
|
| 323 |
+
#print(event) # dbg
|
| 324 |
+
if event.line.endswith('-b') or ' -b ' in event.line:
|
| 325 |
+
# return only bookmark completions
|
| 326 |
+
bkms = self.db.get('bookmarks', None)
|
| 327 |
+
if bkms:
|
| 328 |
+
return bkms.keys()
|
| 329 |
+
else:
|
| 330 |
+
return []
|
| 331 |
+
|
| 332 |
+
if event.symbol == '-':
|
| 333 |
+
width_dh = str(len(str(len(ip.user_ns['_dh']) + 1)))
|
| 334 |
+
# jump in directory history by number
|
| 335 |
+
fmt = '-%0' + width_dh +'d [%s]'
|
| 336 |
+
ents = [ fmt % (i,s) for i,s in enumerate(ip.user_ns['_dh'])]
|
| 337 |
+
if len(ents) > 1:
|
| 338 |
+
return ents
|
| 339 |
+
return []
|
| 340 |
+
|
| 341 |
+
if event.symbol.startswith('--'):
|
| 342 |
+
return ["--" + os.path.basename(d) for d in ip.user_ns['_dh']]
|
| 343 |
+
|
| 344 |
+
# Expand ~ in path and normalize directory separators.
|
| 345 |
+
relpath, tilde_expand, tilde_val = expand_user(relpath)
|
| 346 |
+
relpath = relpath.replace('\\','/')
|
| 347 |
+
|
| 348 |
+
found = []
|
| 349 |
+
for d in [f.replace('\\','/') + '/' for f in glob.glob(relpath+'*')
|
| 350 |
+
if os.path.isdir(f)]:
|
| 351 |
+
if ' ' in d:
|
| 352 |
+
# we don't want to deal with any of that, complex code
|
| 353 |
+
# for this is elsewhere
|
| 354 |
+
raise TryNext
|
| 355 |
+
|
| 356 |
+
found.append(d)
|
| 357 |
+
|
| 358 |
+
if not found:
|
| 359 |
+
if os.path.isdir(relpath):
|
| 360 |
+
return [compress_user(relpath, tilde_expand, tilde_val)]
|
| 361 |
+
|
| 362 |
+
# if no completions so far, try bookmarks
|
| 363 |
+
bks = self.db.get('bookmarks',{})
|
| 364 |
+
bkmatches = [s for s in bks if s.startswith(event.symbol)]
|
| 365 |
+
if bkmatches:
|
| 366 |
+
return bkmatches
|
| 367 |
+
|
| 368 |
+
raise TryNext
|
| 369 |
+
|
| 370 |
+
return [compress_user(p, tilde_expand, tilde_val) for p in found]
|
| 371 |
+
|
| 372 |
+
def reset_completer(self, event):
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# encoding: utf-8
|
| 2 |
+
"""sys.excepthook for IPython itself, leaves a detailed report on disk.
|
| 3 |
+
|
| 4 |
+
Authors:
|
| 5 |
+
|
| 6 |
+
* Fernando Perez
|
| 7 |
+
* Brian E. Granger
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
#-----------------------------------------------------------------------------
|
| 11 |
+
# Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
|
| 12 |
+
# Copyright (C) 2008-2011 The IPython Development Team
|
| 13 |
+
#
|
| 14 |
+
# Distributed under the terms of the BSD License. The full license is in
|
| 15 |
+
# the file COPYING, distributed as part of this software.
|
| 16 |
+
#-----------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
#-----------------------------------------------------------------------------
|
| 19 |
+
# Imports
|
| 20 |
+
#-----------------------------------------------------------------------------
|
| 21 |
+
|
| 22 |
+
import sys
|
| 23 |
+
import traceback
|
| 24 |
+
from pprint import pformat
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
from IPython.core import ultratb
|
| 28 |
+
from IPython.core.release import author_email
|
| 29 |
+
from IPython.utils.sysinfo import sys_info
|
| 30 |
+
from IPython.utils.py3compat import input
|
| 31 |
+
|
| 32 |
+
from IPython.core.release import __version__ as version
|
| 33 |
+
|
| 34 |
+
from typing import Optional
|
| 35 |
+
|
| 36 |
+
#-----------------------------------------------------------------------------
|
| 37 |
+
# Code
|
| 38 |
+
#-----------------------------------------------------------------------------
|
| 39 |
+
|
| 40 |
+
# Template for the user message.
|
| 41 |
+
_default_message_template = """\
|
| 42 |
+
Oops, {app_name} crashed. We do our best to make it stable, but...
|
| 43 |
+
|
| 44 |
+
A crash report was automatically generated with the following information:
|
| 45 |
+
- A verbatim copy of the crash traceback.
|
| 46 |
+
- A copy of your input history during this session.
|
| 47 |
+
- Data on your current {app_name} configuration.
|
| 48 |
+
|
| 49 |
+
It was left in the file named:
|
| 50 |
+
\t'{crash_report_fname}'
|
| 51 |
+
If you can email this file to the developers, the information in it will help
|
| 52 |
+
them in understanding and correcting the problem.
|
| 53 |
+
|
| 54 |
+
You can mail it to: {contact_name} at {contact_email}
|
| 55 |
+
with the subject '{app_name} Crash Report'.
|
| 56 |
+
|
| 57 |
+
If you want to do it now, the following command will work (under Unix):
|
| 58 |
+
mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}
|
| 59 |
+
|
| 60 |
+
In your email, please also include information about:
|
| 61 |
+
- The operating system under which the crash happened: Linux, macOS, Windows,
|
| 62 |
+
other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2,
|
| 63 |
+
Windows 10 Pro), and whether it is 32-bit or 64-bit;
|
| 64 |
+
- How {app_name} was installed: using pip or conda, from GitHub, as part of
|
| 65 |
+
a Docker container, or other, providing more detail if possible;
|
| 66 |
+
- How to reproduce the crash: what exact sequence of instructions can one
|
| 67 |
+
input to get the same crash? Ideally, find a minimal yet complete sequence
|
| 68 |
+
of instructions that yields the crash.
|
| 69 |
+
|
| 70 |
+
To ensure accurate tracking of this issue, please file a report about it at:
|
| 71 |
+
{bug_tracker}
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
_lite_message_template = """
|
| 75 |
+
If you suspect this is an IPython {version} bug, please report it at:
|
| 76 |
+
https://github.com/ipython/ipython/issues
|
| 77 |
+
or send an email to the mailing list at {email}
|
| 78 |
+
|
| 79 |
+
You can print a more detailed traceback right now with "%tb", or use "%debug"
|
| 80 |
+
to interactively debug it.
|
| 81 |
+
|
| 82 |
+
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
|
| 83 |
+
{config}Application.verbose_crash=True
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class CrashHandler(object):
|
| 88 |
+
"""Customizable crash handlers for IPython applications.
|
| 89 |
+
|
| 90 |
+
Instances of this class provide a :meth:`__call__` method which can be
|
| 91 |
+
used as a ``sys.excepthook``. The :meth:`__call__` signature is::
|
| 92 |
+
|
| 93 |
+
def __call__(self, etype, evalue, etb)
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
message_template = _default_message_template
|
| 97 |
+
section_sep = '\n\n'+'*'*75+'\n\n'
|
| 98 |
+
|
| 99 |
+
def __init__(
|
| 100 |
+
self,
|
| 101 |
+
app,
|
| 102 |
+
contact_name: Optional[str] = None,
|
| 103 |
+
contact_email: Optional[str] = None,
|
| 104 |
+
bug_tracker: Optional[str] = None,
|
| 105 |
+
show_crash_traceback: bool = True,
|
| 106 |
+
call_pdb: bool = False,
|
| 107 |
+
):
|
| 108 |
+
"""Create a new crash handler
|
| 109 |
+
|
| 110 |
+
Parameters
|
| 111 |
+
----------
|
| 112 |
+
app : Application
|
| 113 |
+
A running :class:`Application` instance, which will be queried at
|
| 114 |
+
crash time for internal information.
|
| 115 |
+
contact_name : str
|
| 116 |
+
A string with the name of the person to contact.
|
| 117 |
+
contact_email : str
|
| 118 |
+
A string with the email address of the contact.
|
| 119 |
+
bug_tracker : str
|
| 120 |
+
A string with the URL for your project's bug tracker.
|
| 121 |
+
show_crash_traceback : bool
|
| 122 |
+
If false, don't print the crash traceback on stderr, only generate
|
| 123 |
+
the on-disk report
|
| 124 |
+
call_pdb
|
| 125 |
+
Whether to call pdb on crash
|
| 126 |
+
|
| 127 |
+
Attributes
|
| 128 |
+
----------
|
| 129 |
+
These instances contain some non-argument attributes which allow for
|
| 130 |
+
further customization of the crash handler's behavior. Please see the
|
| 131 |
+
source for further details.
|
| 132 |
+
|
| 133 |
+
"""
|
| 134 |
+
self.crash_report_fname = "Crash_report_%s.txt" % app.name
|
| 135 |
+
self.app = app
|
| 136 |
+
self.call_pdb = call_pdb
|
| 137 |
+
#self.call_pdb = True # dbg
|
| 138 |
+
self.show_crash_traceback = show_crash_traceback
|
| 139 |
+
self.info = dict(app_name = app.name,
|
| 140 |
+
contact_name = contact_name,
|
| 141 |
+
contact_email = contact_email,
|
| 142 |
+
bug_tracker = bug_tracker,
|
| 143 |
+
crash_report_fname = self.crash_report_fname)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def __call__(self, etype, evalue, etb):
|
| 147 |
+
"""Handle an exception, call for compatible with sys.excepthook"""
|
| 148 |
+
|
| 149 |
+
# do not allow the crash handler to be called twice without reinstalling it
|
| 150 |
+
# this prevents unlikely errors in the crash handling from entering an
|
| 151 |
+
# infinite loop.
|
| 152 |
+
sys.excepthook = sys.__excepthook__
|
| 153 |
+
|
| 154 |
+
# Report tracebacks shouldn't use color in general (safer for users)
|
| 155 |
+
color_scheme = 'NoColor'
|
| 156 |
+
|
| 157 |
+
# Use this ONLY for developer debugging (keep commented out for release)
|
| 158 |
+
#color_scheme = 'Linux' # dbg
|
| 159 |
+
try:
|
| 160 |
+
rptdir = self.app.ipython_dir
|
| 161 |
+
except:
|
| 162 |
+
rptdir = Path.cwd()
|
| 163 |
+
if rptdir is None or not Path.is_dir(rptdir):
|
| 164 |
+
rptdir = Path.cwd()
|
| 165 |
+
report_name = rptdir / self.crash_report_fname
|
| 166 |
+
# write the report filename into the instance dict so it can get
|
| 167 |
+
# properly expanded out in the user message template
|
| 168 |
+
self.crash_report_fname = report_name
|
| 169 |
+
self.info['crash_report_fname'] = report_name
|
| 170 |
+
TBhandler = ultratb.VerboseTB(
|
| 171 |
+
color_scheme=color_scheme,
|
| 172 |
+
long_header=1,
|
| 173 |
+
call_pdb=self.call_pdb,
|
| 174 |
+
)
|
| 175 |
+
if self.call_pdb:
|
| 176 |
+
TBhandler(etype,evalue,etb)
|
| 177 |
+
return
|
| 178 |
+
else:
|
| 179 |
+
traceback = TBhandler.text(etype,evalue,etb,context=31)
|
| 180 |
+
|
| 181 |
+
# print traceback to screen
|
| 182 |
+
if self.show_crash_traceback:
|
| 183 |
+
print(traceback, file=sys.stderr)
|
| 184 |
+
|
| 185 |
+
# and generate a complete report on disk
|
| 186 |
+
try:
|
| 187 |
+
report = open(report_name, "w", encoding="utf-8")
|
| 188 |
+
except:
|
| 189 |
+
print('Could not create crash report on disk.', file=sys.stderr)
|
| 190 |
+
return
|
| 191 |
+
|
| 192 |
+
with report:
|
| 193 |
+
# Inform user on stderr of what happened
|
| 194 |
+
print('\n'+'*'*70+'\n', file=sys.stderr)
|
| 195 |
+
print(self.message_template.format(**self.info), file=sys.stderr)
|
| 196 |
+
|
| 197 |
+
# Construct report on disk
|
| 198 |
+
report.write(self.make_report(traceback))
|
| 199 |
+
|
| 200 |
+
input("Hit <Enter> to quit (your terminal may close):")
|
| 201 |
+
|
| 202 |
+
def make_report(self,traceback):
|
| 203 |
+
"""Return a string containing a crash report."""
|
| 204 |
+
|
| 205 |
+
sec_sep = self.section_sep
|
| 206 |
+
|
| 207 |
+
report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n']
|
| 208 |
+
rpt_add = report.append
|
| 209 |
+
rpt_add(sys_info())
|
| 210 |
+
|
| 211 |
+
try:
|
| 212 |
+
config = pformat(self.app.config)
|
| 213 |
+
rpt_add(sec_sep)
|
| 214 |
+
rpt_add('Application name: %s\n\n' % self.app_name)
|
| 215 |
+
rpt_add('Current user configuration structure:\n\n')
|
| 216 |
+
rpt_add(config)
|
| 217 |
+
except:
|
| 218 |
+
pass
|
| 219 |
+
rpt_add(sec_sep+'Crash traceback:\n\n' + traceback)
|
| 220 |
+
|
| 221 |
+
return ''.join(report)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def crash_handler_lite(etype, evalue, tb):
|
| 225 |
+
"""a light excepthook, adding a small message to the usual traceback"""
|
| 226 |
+
traceback.print_exception(etype, evalue, tb)
|
| 227 |
+
|
| 228 |
+
from IPython.core.interactiveshell import InteractiveShell
|
| 229 |
+
if InteractiveShell.initialized():
|
| 230 |
+
# we are in a Shell environment, give %magic example
|
| 231 |
+
config = "%config "
|
| 232 |
+
else:
|
| 233 |
+
# we are not in a shell, show generic config
|
| 234 |
+
config = "c."
|
| 235 |
+
print(_lite_message_template.format(email=author_email, config=config, version=version), file=sys.stderr)
|
| 236 |
+
|
.venv/lib/python3.9/site-packages/IPython/core/debugger.py
ADDED
|
@@ -0,0 +1,1120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
Pdb debugger class.
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
This is an extension to PDB which adds a number of new features.
|
| 7 |
+
Note that there is also the `IPython.terminal.debugger` class which provides UI
|
| 8 |
+
improvements.
|
| 9 |
+
|
| 10 |
+
We also strongly recommend to use this via the `ipdb` package, which provides
|
| 11 |
+
extra configuration options.
|
| 12 |
+
|
| 13 |
+
Among other things, this subclass of PDB:
|
| 14 |
+
- supports many IPython magics like pdef/psource
|
| 15 |
+
- hide frames in tracebacks based on `__tracebackhide__`
|
| 16 |
+
- allows to skip frames based on `__debuggerskip__`
|
| 17 |
+
|
| 18 |
+
The skipping and hiding frames are configurable via the `skip_predicates`
|
| 19 |
+
command.
|
| 20 |
+
|
| 21 |
+
By default, frames from readonly files will be hidden, frames containing
|
| 22 |
+
``__tracebackhide__=True`` will be hidden.
|
| 23 |
+
|
| 24 |
+
Frames containing ``__debuggerskip__`` will be stepped over, frames who's parent
|
| 25 |
+
frames value of ``__debuggerskip__`` is ``True`` will be skipped.
|
| 26 |
+
|
| 27 |
+
>>> def helpers_helper():
|
| 28 |
+
... pass
|
| 29 |
+
...
|
| 30 |
+
... def helper_1():
|
| 31 |
+
... print("don't step in me")
|
| 32 |
+
... helpers_helpers() # will be stepped over unless breakpoint set.
|
| 33 |
+
...
|
| 34 |
+
...
|
| 35 |
+
... def helper_2():
|
| 36 |
+
... print("in me neither")
|
| 37 |
+
...
|
| 38 |
+
|
| 39 |
+
One can define a decorator that wraps a function between the two helpers:
|
| 40 |
+
|
| 41 |
+
>>> def pdb_skipped_decorator(function):
|
| 42 |
+
...
|
| 43 |
+
...
|
| 44 |
+
... def wrapped_fn(*args, **kwargs):
|
| 45 |
+
... __debuggerskip__ = True
|
| 46 |
+
... helper_1()
|
| 47 |
+
... __debuggerskip__ = False
|
| 48 |
+
... result = function(*args, **kwargs)
|
| 49 |
+
... __debuggerskip__ = True
|
| 50 |
+
... helper_2()
|
| 51 |
+
... # setting __debuggerskip__ to False again is not necessary
|
| 52 |
+
... return result
|
| 53 |
+
...
|
| 54 |
+
... return wrapped_fn
|
| 55 |
+
|
| 56 |
+
When decorating a function, ipdb will directly step into ``bar()`` by
|
| 57 |
+
default:
|
| 58 |
+
|
| 59 |
+
>>> @foo_decorator
|
| 60 |
+
... def bar(x, y):
|
| 61 |
+
... return x * y
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
You can toggle the behavior with
|
| 65 |
+
|
| 66 |
+
ipdb> skip_predicates debuggerskip false
|
| 67 |
+
|
| 68 |
+
or configure it in your ``.pdbrc``
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
License
|
| 73 |
+
-------
|
| 74 |
+
|
| 75 |
+
Modified from the standard pdb.Pdb class to avoid including readline, so that
|
| 76 |
+
the command line completion of other programs which include this isn't
|
| 77 |
+
damaged.
|
| 78 |
+
|
| 79 |
+
In the future, this class will be expanded with improvements over the standard
|
| 80 |
+
pdb.
|
| 81 |
+
|
| 82 |
+
The original code in this file is mainly lifted out of cmd.py in Python 2.2,
|
| 83 |
+
with minor changes. Licensing should therefore be under the standard Python
|
| 84 |
+
terms. For details on the PSF (Python Software Foundation) standard license,
|
| 85 |
+
see:
|
| 86 |
+
|
| 87 |
+
https://docs.python.org/2/license.html
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
All the changes since then are under the same license as IPython.
|
| 91 |
+
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
#*****************************************************************************
|
| 95 |
+
#
|
| 96 |
+
# This file is licensed under the PSF license.
|
| 97 |
+
#
|
| 98 |
+
# Copyright (C) 2001 Python Software Foundation, www.python.org
|
| 99 |
+
# Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu>
|
| 100 |
+
#
|
| 101 |
+
#
|
| 102 |
+
#*****************************************************************************
|
| 103 |
+
|
| 104 |
+
import inspect
|
| 105 |
+
import linecache
|
| 106 |
+
import sys
|
| 107 |
+
import re
|
| 108 |
+
import os
|
| 109 |
+
|
| 110 |
+
from IPython import get_ipython
|
| 111 |
+
from contextlib import contextmanager
|
| 112 |
+
from IPython.utils import PyColorize
|
| 113 |
+
from IPython.utils import coloransi, py3compat
|
| 114 |
+
from IPython.core.excolors import exception_colors
|
| 115 |
+
|
| 116 |
+
# skip module docstests
|
| 117 |
+
__skip_doctest__ = True
|
| 118 |
+
|
| 119 |
+
prompt = 'ipdb> '
|
| 120 |
+
|
| 121 |
+
# We have to check this directly from sys.argv, config struct not yet available
|
| 122 |
+
from pdb import Pdb as OldPdb
|
| 123 |
+
|
| 124 |
+
# Allow the set_trace code to operate outside of an ipython instance, even if
|
| 125 |
+
# it does so with some limitations. The rest of this support is implemented in
|
| 126 |
+
# the Tracer constructor.
|
| 127 |
+
|
| 128 |
+
DEBUGGERSKIP = "__debuggerskip__"
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
# this has been implemented in Pdb in Python 3.13 (https://github.com/python/cpython/pull/106676
|
| 132 |
+
# on lower python versions, we backported the feature.
|
| 133 |
+
CHAIN_EXCEPTIONS = sys.version_info < (3, 13)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def make_arrow(pad):
|
| 137 |
+
"""generate the leading arrow in front of traceback or debugger"""
|
| 138 |
+
if pad >= 2:
|
| 139 |
+
return '-'*(pad-2) + '> '
|
| 140 |
+
elif pad == 1:
|
| 141 |
+
return '>'
|
| 142 |
+
return ''
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def BdbQuit_excepthook(et, ev, tb, excepthook=None):
|
| 146 |
+
"""Exception hook which handles `BdbQuit` exceptions.
|
| 147 |
+
|
| 148 |
+
All other exceptions are processed using the `excepthook`
|
| 149 |
+
parameter.
|
| 150 |
+
"""
|
| 151 |
+
raise ValueError(
|
| 152 |
+
"`BdbQuit_excepthook` is deprecated since version 5.1",
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None):
|
| 157 |
+
raise ValueError(
|
| 158 |
+
"`BdbQuit_IPython_excepthook` is deprecated since version 5.1",
|
| 159 |
+
DeprecationWarning, stacklevel=2)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+')
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def strip_indentation(multiline_string):
|
| 166 |
+
return RGX_EXTRA_INDENT.sub('', multiline_string)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
|
| 170 |
+
"""Make new_fn have old_fn's doc string. This is particularly useful
|
| 171 |
+
for the ``do_...`` commands that hook into the help system.
|
| 172 |
+
Adapted from from a comp.lang.python posting
|
| 173 |
+
by Duncan Booth."""
|
| 174 |
+
def wrapper(*args, **kw):
|
| 175 |
+
return new_fn(*args, **kw)
|
| 176 |
+
if old_fn.__doc__:
|
| 177 |
+
wrapper.__doc__ = strip_indentation(old_fn.__doc__) + additional_text
|
| 178 |
+
return wrapper
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class Pdb(OldPdb):
|
| 182 |
+
"""Modified Pdb class, does not load readline.
|
| 183 |
+
|
| 184 |
+
for a standalone version that uses prompt_toolkit, see
|
| 185 |
+
`IPython.terminal.debugger.TerminalPdb` and
|
| 186 |
+
`IPython.terminal.debugger.set_trace()`
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
This debugger can hide and skip frames that are tagged according to some predicates.
|
| 190 |
+
See the `skip_predicates` commands.
|
| 191 |
+
|
| 192 |
+
"""
|
| 193 |
+
|
| 194 |
+
if CHAIN_EXCEPTIONS:
|
| 195 |
+
MAX_CHAINED_EXCEPTION_DEPTH = 999
|
| 196 |
+
|
| 197 |
+
default_predicates = {
|
| 198 |
+
"tbhide": True,
|
| 199 |
+
"readonly": False,
|
| 200 |
+
"ipython_internal": True,
|
| 201 |
+
"debuggerskip": True,
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwargs):
|
| 205 |
+
"""Create a new IPython debugger.
|
| 206 |
+
|
| 207 |
+
Parameters
|
| 208 |
+
----------
|
| 209 |
+
completekey : default None
|
| 210 |
+
Passed to pdb.Pdb.
|
| 211 |
+
stdin : default None
|
| 212 |
+
Passed to pdb.Pdb.
|
| 213 |
+
stdout : default None
|
| 214 |
+
Passed to pdb.Pdb.
|
| 215 |
+
context : int
|
| 216 |
+
Number of lines of source code context to show when
|
| 217 |
+
displaying stacktrace information.
|
| 218 |
+
**kwargs
|
| 219 |
+
Passed to pdb.Pdb.
|
| 220 |
+
|
| 221 |
+
Notes
|
| 222 |
+
-----
|
| 223 |
+
The possibilities are python version dependent, see the python
|
| 224 |
+
docs for more info.
|
| 225 |
+
"""
|
| 226 |
+
|
| 227 |
+
# Parent constructor:
|
| 228 |
+
try:
|
| 229 |
+
self.context = int(context)
|
| 230 |
+
if self.context <= 0:
|
| 231 |
+
raise ValueError("Context must be a positive integer")
|
| 232 |
+
except (TypeError, ValueError) as e:
|
| 233 |
+
raise ValueError("Context must be a positive integer") from e
|
| 234 |
+
|
| 235 |
+
# `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`.
|
| 236 |
+
OldPdb.__init__(self, completekey, stdin, stdout, **kwargs)
|
| 237 |
+
|
| 238 |
+
# IPython changes...
|
| 239 |
+
self.shell = get_ipython()
|
| 240 |
+
|
| 241 |
+
if self.shell is None:
|
| 242 |
+
save_main = sys.modules['__main__']
|
| 243 |
+
# No IPython instance running, we must create one
|
| 244 |
+
from IPython.terminal.interactiveshell import \
|
| 245 |
+
TerminalInteractiveShell
|
| 246 |
+
self.shell = TerminalInteractiveShell.instance()
|
| 247 |
+
# needed by any code which calls __import__("__main__") after
|
| 248 |
+
# the debugger was entered. See also #9941.
|
| 249 |
+
sys.modules["__main__"] = save_main
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
color_scheme = self.shell.colors
|
| 253 |
+
|
| 254 |
+
self.aliases = {}
|
| 255 |
+
|
| 256 |
+
# Create color table: we copy the default one from the traceback
|
| 257 |
+
# module and add a few attributes needed for debugging
|
| 258 |
+
self.color_scheme_table = exception_colors()
|
| 259 |
+
|
| 260 |
+
# shorthands
|
| 261 |
+
C = coloransi.TermColors
|
| 262 |
+
cst = self.color_scheme_table
|
| 263 |
+
|
| 264 |
+
cst['NoColor'].colors.prompt = C.NoColor
|
| 265 |
+
cst['NoColor'].colors.breakpoint_enabled = C.NoColor
|
| 266 |
+
cst['NoColor'].colors.breakpoint_disabled = C.NoColor
|
| 267 |
+
|
| 268 |
+
cst['Linux'].colors.prompt = C.Green
|
| 269 |
+
cst['Linux'].colors.breakpoint_enabled = C.LightRed
|
| 270 |
+
cst['Linux'].colors.breakpoint_disabled = C.Red
|
| 271 |
+
|
| 272 |
+
cst['LightBG'].colors.prompt = C.Blue
|
| 273 |
+
cst['LightBG'].colors.breakpoint_enabled = C.LightRed
|
| 274 |
+
cst['LightBG'].colors.breakpoint_disabled = C.Red
|
| 275 |
+
|
| 276 |
+
cst['Neutral'].colors.prompt = C.Blue
|
| 277 |
+
cst['Neutral'].colors.breakpoint_enabled = C.LightRed
|
| 278 |
+
cst['Neutral'].colors.breakpoint_disabled = C.Red
|
| 279 |
+
|
| 280 |
+
# Add a python parser so we can syntax highlight source while
|
| 281 |
+
# debugging.
|
| 282 |
+
self.parser = PyColorize.Parser(style=color_scheme)
|
| 283 |
+
self.set_colors(color_scheme)
|
| 284 |
+
|
| 285 |
+
# Set the prompt - the default prompt is '(Pdb)'
|
| 286 |
+
self.prompt = prompt
|
| 287 |
+
self.skip_hidden = True
|
| 288 |
+
self.report_skipped = True
|
| 289 |
+
|
| 290 |
+
# list of predicates we use to skip frames
|
| 291 |
+
self._predicates = self.default_predicates
|
| 292 |
+
|
| 293 |
+
if CHAIN_EXCEPTIONS:
|
| 294 |
+
self._chained_exceptions = tuple()
|
| 295 |
+
self._chained_exception_index = 0
|
| 296 |
+
|
| 297 |
+
#
|
| 298 |
+
def set_colors(self, scheme):
|
| 299 |
+
"""Shorthand access to the color table scheme selector method."""
|
| 300 |
+
self.color_scheme_table.set_active_scheme(scheme)
|
| 301 |
+
self.parser.style = scheme
|
| 302 |
+
|
| 303 |
+
def set_trace(self, frame=None):
|
| 304 |
+
if frame is None:
|
| 305 |
+
frame = sys._getframe().f_back
|
| 306 |
+
self.initial_frame = frame
|
| 307 |
+
return super().set_trace(frame)
|
| 308 |
+
|
| 309 |
+
def _hidden_predicate(self, frame):
|
| 310 |
+
"""
|
| 311 |
+
Given a frame return whether it it should be hidden or not by IPython.
|
| 312 |
+
"""
|
| 313 |
+
|
| 314 |
+
if self._predicates["readonly"]:
|
| 315 |
+
fname = frame.f_code.co_filename
|
| 316 |
+
# we need to check for file existence and interactively define
|
| 317 |
+
# function would otherwise appear as RO.
|
| 318 |
+
if os.path.isfile(fname) and not os.access(fname, os.W_OK):
|
| 319 |
+
return True
|
| 320 |
+
|
| 321 |
+
if self._predicates["tbhide"]:
|
| 322 |
+
if frame in (self.curframe, getattr(self, "initial_frame", None)):
|
| 323 |
+
return False
|
| 324 |
+
frame_locals = self._get_frame_locals(frame)
|
| 325 |
+
if "__tracebackhide__" not in frame_locals:
|
| 326 |
+
return False
|
| 327 |
+
return frame_locals["__tracebackhide__"]
|
| 328 |
+
return False
|
| 329 |
+
|
| 330 |
+
def hidden_frames(self, stack):
|
| 331 |
+
"""
|
| 332 |
+
Given an index in the stack return whether it should be skipped.
|
| 333 |
+
|
| 334 |
+
This is used in up/down and where to skip frames.
|
| 335 |
+
"""
|
| 336 |
+
# The f_locals dictionary is updated from the actual frame
|
| 337 |
+
# locals whenever the .f_locals accessor is called, so we
|
| 338 |
+
# avoid calling it here to preserve self.curframe_locals.
|
| 339 |
+
# Furthermore, there is no good reason to hide the current frame.
|
| 340 |
+
ip_hide = [self._hidden_predicate(s[0]) for s in stack]
|
| 341 |
+
ip_start = [i for i, s in enumerate(ip_hide) if s == "__ipython_bottom__"]
|
| 342 |
+
if ip_start and self._predicates["ipython_internal"]:
|
| 343 |
+
ip_hide = [h if i > ip_start[0] else True for (i, h) in enumerate(ip_hide)]
|
| 344 |
+
return ip_hide
|
| 345 |
+
|
| 346 |
+
if CHAIN_EXCEPTIONS:
|
| 347 |
+
|
| 348 |
+
def _get_tb_and_exceptions(self, tb_or_exc):
|
| 349 |
+
"""
|
| 350 |
+
Given a tracecack or an exception, return a tuple of chained exceptions
|
| 351 |
+
and current traceback to inspect.
|
| 352 |
+
This will deal with selecting the right ``__cause__`` or ``__context__``
|
| 353 |
+
as well as handling cycles, and return a flattened list of exceptions we
|
| 354 |
+
can jump to with do_exceptions.
|
| 355 |
+
"""
|
| 356 |
+
_exceptions = []
|
| 357 |
+
if isinstance(tb_or_exc, BaseException):
|
| 358 |
+
traceback, current = tb_or_exc.__traceback__, tb_or_exc
|
| 359 |
+
|
| 360 |
+
while current is not None:
|
| 361 |
+
if current in _exceptions:
|
| 362 |
+
break
|
| 363 |
+
_exceptions.append(current)
|
| 364 |
+
if current.__cause__ is not None:
|
| 365 |
+
current = current.__cause__
|
| 366 |
+
elif (
|
| 367 |
+
current.__context__ is not None
|
| 368 |
+
and not current.__suppress_context__
|
| 369 |
+
):
|
| 370 |
+
current = current.__context__
|
| 371 |
+
|
| 372 |
+
if len(_exceptions) >= self.MAX_CHAINED_EXCEPTION_DEPTH:
|
| 373 |
+
self.message(
|
| 374 |
+
f"More than {self.MAX_CHAINED_EXCEPTION_DEPTH}"
|
| 375 |
+
" chained exceptions found, not all exceptions"
|
| 376 |
+
"will be browsable with `exceptions`."
|
| 377 |
+
)
|
| 378 |
+
break
|
| 379 |
+
else:
|
| 380 |
+
traceback = tb_or_exc
|
| 381 |
+
return tuple(reversed(_exceptions)), traceback
|
| 382 |
+
|
| 383 |
+
@contextmanager
|
| 384 |
+
def _hold_exceptions(self, exceptions):
|
| 385 |
+
"""
|
| 386 |
+
Context manager to ensure proper cleaning of exceptions references
|
| 387 |
+
When given a chained exception instead of a traceback,
|
| 388 |
+
pdb may hold references to many objects which may leak memory.
|
| 389 |
+
We use this context manager to make sure everything is properly cleaned
|
| 390 |
+
"""
|
| 391 |
+
try:
|
| 392 |
+
self._chained_exceptions = exceptions
|
| 393 |
+
self._chained_exception_index = len(exceptions) - 1
|
| 394 |
+
yield
|
| 395 |
+
finally:
|
| 396 |
+
# we can't put those in forget as otherwise they would
|
| 397 |
+
# be cleared on exception change
|
| 398 |
+
self._chained_exceptions = tuple()
|
| 399 |
+
self._chained_exception_index = 0
|
| 400 |
+
|
| 401 |
+
def do_exceptions(self, arg):
|
| 402 |
+
"""exceptions [number]
|
| 403 |
+
List or change current exception in an exception chain.
|
| 404 |
+
Without arguments, list all the current exception in the exception
|
| 405 |
+
chain. Exceptions will be numbered, with the current exception indicated
|
| 406 |
+
with an arrow.
|
| 407 |
+
If given an integer as argument, switch to the exception at that index.
|
| 408 |
+
"""
|
| 409 |
+
if not self._chained_exceptions:
|
| 410 |
+
self.message(
|
| 411 |
+
"Did not find chained exceptions. To move between"
|
| 412 |
+
" exceptions, pdb/post_mortem must be given an exception"
|
| 413 |
+
" object rather than a traceback."
|
| 414 |
+
)
|
| 415 |
+
return
|
| 416 |
+
if not arg:
|
| 417 |
+
for ix, exc in enumerate(self._chained_exceptions):
|
| 418 |
+
prompt = ">" if ix == self._chained_exception_index else " "
|
| 419 |
+
rep = repr(exc)
|
| 420 |
+
if len(rep) > 80:
|
| 421 |
+
rep = rep[:77] + "..."
|
| 422 |
+
indicator = (
|
| 423 |
+
" -"
|
| 424 |
+
if self._chained_exceptions[ix].__traceback__ is None
|
| 425 |
+
else f"{ix:>3}"
|
| 426 |
+
)
|
| 427 |
+
self.message(f"{prompt} {indicator} {rep}")
|
| 428 |
+
else:
|
| 429 |
+
try:
|
| 430 |
+
number = int(arg)
|
| 431 |
+
except ValueError:
|
| 432 |
+
self.error("Argument must be an integer")
|
| 433 |
+
return
|
| 434 |
+
if 0 <= number < len(self._chained_exceptions):
|
| 435 |
+
if self._chained_exceptions[number].__traceback__ is None:
|
| 436 |
+
self.error(
|
| 437 |
+
"This exception does not have a traceback, cannot jump to it"
|
| 438 |
+
)
|
| 439 |
+
return
|
| 440 |
+
|
| 441 |
+
self._chained_exception_index = number
|
| 442 |
+
self.setup(None, self._chained_exceptions[number].__traceback__)
|
| 443 |
+
self.print_stack_entry(self.stack[self.curindex])
|
| 444 |
+
else:
|
| 445 |
+
self.error("No exception with that number")
|
| 446 |
+
|
| 447 |
+
def interaction(self, frame, tb_or_exc):
|
| 448 |
+
try:
|
| 449 |
+
if CHAIN_EXCEPTIONS:
|
| 450 |
+
# this context manager is part of interaction in 3.13
|
| 451 |
+
_chained_exceptions, tb = self._get_tb_and_exceptions(tb_or_exc)
|
| 452 |
+
if isinstance(tb_or_exc, BaseException):
|
| 453 |
+
assert tb is not None, "main exception must have a traceback"
|
| 454 |
+
with self._hold_exceptions(_chained_exceptions):
|
| 455 |
+
OldPdb.interaction(self, frame, tb)
|
| 456 |
+
else:
|
| 457 |
+
OldPdb.interaction(self, frame, traceback)
|
| 458 |
+
|
| 459 |
+
except KeyboardInterrupt:
|
| 460 |
+
self.stdout.write("\n" + self.shell.get_exception_only())
|
| 461 |
+
|
| 462 |
+
def precmd(self, line):
|
| 463 |
+
"""Perform useful escapes on the command before it is executed."""
|
| 464 |
+
|
| 465 |
+
if line.endswith("??"):
|
| 466 |
+
line = "pinfo2 " + line[:-2]
|
| 467 |
+
elif line.endswith("?"):
|
| 468 |
+
line = "pinfo " + line[:-1]
|
| 469 |
+
|
| 470 |
+
line = super().precmd(line)
|
| 471 |
+
|
| 472 |
+
return line
|
| 473 |
+
|
| 474 |
+
def new_do_frame(self, arg):
|
| 475 |
+
OldPdb.do_frame(self, arg)
|
| 476 |
+
|
| 477 |
+
def new_do_quit(self, arg):
|
| 478 |
+
|
| 479 |
+
if hasattr(self, 'old_all_completions'):
|
| 480 |
+
self.shell.Completer.all_completions = self.old_all_completions
|
| 481 |
+
|
| 482 |
+
return OldPdb.do_quit(self, arg)
|
| 483 |
+
|
| 484 |
+
do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
|
| 485 |
+
|
| 486 |
+
def new_do_restart(self, arg):
|
| 487 |
+
"""Restart command. In the context of ipython this is exactly the same
|
| 488 |
+
thing as 'quit'."""
|
| 489 |
+
self.msg("Restart doesn't make sense here. Using 'quit' instead.")
|
| 490 |
+
return self.do_quit(arg)
|
| 491 |
+
|
| 492 |
+
def print_stack_trace(self, context=None):
|
| 493 |
+
Colors = self.color_scheme_table.active_colors
|
| 494 |
+
ColorsNormal = Colors.Normal
|
| 495 |
+
if context is None:
|
| 496 |
+
context = self.context
|
| 497 |
+
try:
|
| 498 |
+
context = int(context)
|
| 499 |
+
if context <= 0:
|
| 500 |
+
raise ValueError("Context must be a positive integer")
|
| 501 |
+
except (TypeError, ValueError) as e:
|
| 502 |
+
raise ValueError("Context must be a positive integer") from e
|
| 503 |
+
try:
|
| 504 |
+
skipped = 0
|
| 505 |
+
for hidden, frame_lineno in zip(self.hidden_frames(self.stack), self.stack):
|
| 506 |
+
if hidden and self.skip_hidden:
|
| 507 |
+
skipped += 1
|
| 508 |
+
continue
|
| 509 |
+
if skipped:
|
| 510 |
+
print(
|
| 511 |
+
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
|
| 512 |
+
)
|
| 513 |
+
skipped = 0
|
| 514 |
+
self.print_stack_entry(frame_lineno, context=context)
|
| 515 |
+
if skipped:
|
| 516 |
+
print(
|
| 517 |
+
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
|
| 518 |
+
)
|
| 519 |
+
except KeyboardInterrupt:
|
| 520 |
+
pass
|
| 521 |
+
|
| 522 |
+
def print_stack_entry(self, frame_lineno, prompt_prefix='\n-> ',
|
| 523 |
+
context=None):
|
| 524 |
+
if context is None:
|
| 525 |
+
context = self.context
|
| 526 |
+
try:
|
| 527 |
+
context = int(context)
|
| 528 |
+
if context <= 0:
|
| 529 |
+
raise ValueError("Context must be a positive integer")
|
| 530 |
+
except (TypeError, ValueError) as e:
|
| 531 |
+
raise ValueError("Context must be a positive integer") from e
|
| 532 |
+
print(self.format_stack_entry(frame_lineno, '', context), file=self.stdout)
|
| 533 |
+
|
| 534 |
+
# vds: >>
|
| 535 |
+
frame, lineno = frame_lineno
|
| 536 |
+
filename = frame.f_code.co_filename
|
| 537 |
+
self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
|
| 538 |
+
# vds: <<
|
| 539 |
+
|
| 540 |
+
def _get_frame_locals(self, frame):
|
| 541 |
+
""" "
|
| 542 |
+
Accessing f_local of current frame reset the namespace, so we want to avoid
|
| 543 |
+
that or the following can happen
|
| 544 |
+
|
| 545 |
+
ipdb> foo
|
| 546 |
+
"old"
|
| 547 |
+
ipdb> foo = "new"
|
| 548 |
+
ipdb> foo
|
| 549 |
+
"new"
|
| 550 |
+
ipdb> where
|
| 551 |
+
ipdb> foo
|
| 552 |
+
"old"
|
| 553 |
+
|
| 554 |
+
So if frame is self.current_frame we instead return self.curframe_locals
|
| 555 |
+
|
| 556 |
+
"""
|
| 557 |
+
if frame is self.curframe:
|
| 558 |
+
return self.curframe_locals
|
| 559 |
+
else:
|
| 560 |
+
return frame.f_locals
|
| 561 |
+
|
| 562 |
+
def format_stack_entry(self, frame_lineno, lprefix=': ', context=None):
|
| 563 |
+
if context is None:
|
| 564 |
+
context = self.context
|
| 565 |
+
try:
|
| 566 |
+
context = int(context)
|
| 567 |
+
if context <= 0:
|
| 568 |
+
print("Context must be a positive integer", file=self.stdout)
|
| 569 |
+
except (TypeError, ValueError):
|
| 570 |
+
print("Context must be a positive integer", file=self.stdout)
|
| 571 |
+
|
| 572 |
+
import reprlib
|
| 573 |
+
|
| 574 |
+
ret = []
|
| 575 |
+
|
| 576 |
+
Colors = self.color_scheme_table.active_colors
|
| 577 |
+
ColorsNormal = Colors.Normal
|
| 578 |
+
tpl_link = "%s%%s%s" % (Colors.filenameEm, ColorsNormal)
|
| 579 |
+
tpl_call = "%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal)
|
| 580 |
+
tpl_line = "%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal)
|
| 581 |
+
tpl_line_em = "%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, ColorsNormal)
|
| 582 |
+
|
| 583 |
+
frame, lineno = frame_lineno
|
| 584 |
+
|
| 585 |
+
return_value = ''
|
| 586 |
+
loc_frame = self._get_frame_locals(frame)
|
| 587 |
+
if "__return__" in loc_frame:
|
| 588 |
+
rv = loc_frame["__return__"]
|
| 589 |
+
# return_value += '->'
|
| 590 |
+
return_value += reprlib.repr(rv) + "\n"
|
| 591 |
+
ret.append(return_value)
|
| 592 |
+
|
| 593 |
+
#s = filename + '(' + `lineno` + ')'
|
| 594 |
+
filename = self.canonic(frame.f_code.co_filename)
|
| 595 |
+
link = tpl_link % py3compat.cast_unicode(filename)
|
| 596 |
+
|
| 597 |
+
if frame.f_code.co_name:
|
| 598 |
+
func = frame.f_code.co_name
|
| 599 |
+
else:
|
| 600 |
+
func = "<lambda>"
|
| 601 |
+
|
| 602 |
+
call = ""
|
| 603 |
+
if func != "?":
|
| 604 |
+
if "__args__" in loc_frame:
|
| 605 |
+
args = reprlib.repr(loc_frame["__args__"])
|
| 606 |
+
else:
|
| 607 |
+
args = '()'
|
| 608 |
+
call = tpl_call % (func, args)
|
| 609 |
+
|
| 610 |
+
# The level info should be generated in the same format pdb uses, to
|
| 611 |
+
# avoid breaking the pdbtrack functionality of python-mode in *emacs.
|
| 612 |
+
if frame is self.curframe:
|
| 613 |
+
ret.append('> ')
|
| 614 |
+
else:
|
| 615 |
+
ret.append(" ")
|
| 616 |
+
ret.append("%s(%s)%s\n" % (link, lineno, call))
|
| 617 |
+
|
| 618 |
+
start = lineno - 1 - context//2
|
| 619 |
+
lines = linecache.getlines(filename)
|
| 620 |
+
start = min(start, len(lines) - context)
|
| 621 |
+
start = max(start, 0)
|
| 622 |
+
lines = lines[start : start + context]
|
| 623 |
+
|
| 624 |
+
for i, line in enumerate(lines):
|
| 625 |
+
show_arrow = start + 1 + i == lineno
|
| 626 |
+
linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line
|
| 627 |
+
ret.append(
|
| 628 |
+
self.__format_line(
|
| 629 |
+
linetpl, filename, start + 1 + i, line, arrow=show_arrow
|
| 630 |
+
)
|
| 631 |
+
)
|
| 632 |
+
return "".join(ret)
|
| 633 |
+
|
| 634 |
+
def __format_line(self, tpl_line, filename, lineno, line, arrow=False):
|
| 635 |
+
bp_mark = ""
|
| 636 |
+
bp_mark_color = ""
|
| 637 |
+
|
| 638 |
+
new_line, err = self.parser.format2(line, 'str')
|
| 639 |
+
if not err:
|
| 640 |
+
line = new_line
|
| 641 |
+
|
| 642 |
+
bp = None
|
| 643 |
+
if lineno in self.get_file_breaks(filename):
|
| 644 |
+
bps = self.get_breaks(filename, lineno)
|
| 645 |
+
bp = bps[-1]
|
| 646 |
+
|
| 647 |
+
if bp:
|
| 648 |
+
Colors = self.color_scheme_table.active_colors
|
| 649 |
+
bp_mark = str(bp.number)
|
| 650 |
+
bp_mark_color = Colors.breakpoint_enabled
|
| 651 |
+
if not bp.enabled:
|
| 652 |
+
bp_mark_color = Colors.breakpoint_disabled
|
| 653 |
+
|
| 654 |
+
numbers_width = 7
|
| 655 |
+
if arrow:
|
| 656 |
+
# This is the line with the error
|
| 657 |
+
pad = numbers_width - len(str(lineno)) - len(bp_mark)
|
| 658 |
+
num = '%s%s' % (make_arrow(pad), str(lineno))
|
| 659 |
+
else:
|
| 660 |
+
num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
|
| 661 |
+
|
| 662 |
+
return tpl_line % (bp_mark_color + bp_mark, num, line)
|
| 663 |
+
|
| 664 |
+
def print_list_lines(self, filename, first, last):
|
| 665 |
+
"""The printing (as opposed to the parsing part of a 'list'
|
| 666 |
+
command."""
|
| 667 |
+
try:
|
| 668 |
+
Colors = self.color_scheme_table.active_colors
|
| 669 |
+
ColorsNormal = Colors.Normal
|
| 670 |
+
tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
|
| 671 |
+
tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
|
| 672 |
+
src = []
|
| 673 |
+
if filename == "<string>" and hasattr(self, "_exec_filename"):
|
| 674 |
+
filename = self._exec_filename
|
| 675 |
+
|
| 676 |
+
for lineno in range(first, last+1):
|
| 677 |
+
line = linecache.getline(filename, lineno)
|
| 678 |
+
if not line:
|
| 679 |
+
break
|
| 680 |
+
|
| 681 |
+
if lineno == self.curframe.f_lineno:
|
| 682 |
+
line = self.__format_line(
|
| 683 |
+
tpl_line_em, filename, lineno, line, arrow=True
|
| 684 |
+
)
|
| 685 |
+
else:
|
| 686 |
+
line = self.__format_line(
|
| 687 |
+
tpl_line, filename, lineno, line, arrow=False
|
| 688 |
+
)
|
| 689 |
+
|
| 690 |
+
src.append(line)
|
| 691 |
+
self.lineno = lineno
|
| 692 |
+
|
| 693 |
+
print(''.join(src), file=self.stdout)
|
| 694 |
+
|
| 695 |
+
except KeyboardInterrupt:
|
| 696 |
+
pass
|
| 697 |
+
|
| 698 |
+
def do_skip_predicates(self, args):
|
| 699 |
+
"""
|
| 700 |
+
Turn on/off individual predicates as to whether a frame should be hidden/skip.
|
| 701 |
+
|
| 702 |
+
The global option to skip (or not) hidden frames is set with skip_hidden
|
| 703 |
+
|
| 704 |
+
To change the value of a predicate
|
| 705 |
+
|
| 706 |
+
skip_predicates key [true|false]
|
| 707 |
+
|
| 708 |
+
Call without arguments to see the current values.
|
| 709 |
+
|
| 710 |
+
To permanently change the value of an option add the corresponding
|
| 711 |
+
command to your ``~/.pdbrc`` file. If you are programmatically using the
|
| 712 |
+
Pdb instance you can also change the ``default_predicates`` class
|
| 713 |
+
attribute.
|
| 714 |
+
"""
|
| 715 |
+
if not args.strip():
|
| 716 |
+
print("current predicates:")
|
| 717 |
+
for p, v in self._predicates.items():
|
| 718 |
+
print(" ", p, ":", v)
|
| 719 |
+
return
|
| 720 |
+
type_value = args.strip().split(" ")
|
| 721 |
+
if len(type_value) != 2:
|
| 722 |
+
print(
|
| 723 |
+
f"Usage: skip_predicates <type> <value>, with <type> one of {set(self._predicates.keys())}"
|
| 724 |
+
)
|
| 725 |
+
return
|
| 726 |
+
|
| 727 |
+
type_, value = type_value
|
| 728 |
+
if type_ not in self._predicates:
|
| 729 |
+
print(f"{type_!r} not in {set(self._predicates.keys())}")
|
| 730 |
+
return
|
| 731 |
+
if value.lower() not in ("true", "yes", "1", "no", "false", "0"):
|
| 732 |
+
print(
|
| 733 |
+
f"{value!r} is invalid - use one of ('true', 'yes', '1', 'no', 'false', '0')"
|
| 734 |
+
)
|
| 735 |
+
return
|
| 736 |
+
|
| 737 |
+
self._predicates[type_] = value.lower() in ("true", "yes", "1")
|
| 738 |
+
if not any(self._predicates.values()):
|
| 739 |
+
print(
|
| 740 |
+
"Warning, all predicates set to False, skip_hidden may not have any effects."
|
| 741 |
+
)
|
| 742 |
+
|
| 743 |
+
def do_skip_hidden(self, arg):
|
| 744 |
+
"""
|
| 745 |
+
Change whether or not we should skip frames with the
|
| 746 |
+
__tracebackhide__ attribute.
|
| 747 |
+
"""
|
| 748 |
+
if not arg.strip():
|
| 749 |
+
print(
|
| 750 |
+
f"skip_hidden = {self.skip_hidden}, use 'yes','no', 'true', or 'false' to change."
|
| 751 |
+
)
|
| 752 |
+
elif arg.strip().lower() in ("true", "yes"):
|
| 753 |
+
self.skip_hidden = True
|
| 754 |
+
elif arg.strip().lower() in ("false", "no"):
|
| 755 |
+
self.skip_hidden = False
|
| 756 |
+
if not any(self._predicates.values()):
|
| 757 |
+
print(
|
| 758 |
+
"Warning, all predicates set to False, skip_hidden may not have any effects."
|
| 759 |
+
)
|
| 760 |
+
|
| 761 |
+
def do_list(self, arg):
|
| 762 |
+
"""Print lines of code from the current stack frame
|
| 763 |
+
"""
|
| 764 |
+
self.lastcmd = 'list'
|
| 765 |
+
last = None
|
| 766 |
+
if arg and arg != ".":
|
| 767 |
+
try:
|
| 768 |
+
x = eval(arg, {}, {})
|
| 769 |
+
if type(x) == type(()):
|
| 770 |
+
first, last = x
|
| 771 |
+
first = int(first)
|
| 772 |
+
last = int(last)
|
| 773 |
+
if last < first:
|
| 774 |
+
# Assume it's a count
|
| 775 |
+
last = first + last
|
| 776 |
+
else:
|
| 777 |
+
first = max(1, int(x) - 5)
|
| 778 |
+
except:
|
| 779 |
+
print('*** Error in argument:', repr(arg), file=self.stdout)
|
| 780 |
+
return
|
| 781 |
+
elif self.lineno is None or arg == ".":
|
| 782 |
+
first = max(1, self.curframe.f_lineno - 5)
|
| 783 |
+
else:
|
| 784 |
+
first = self.lineno + 1
|
| 785 |
+
if last is None:
|
| 786 |
+
last = first + 10
|
| 787 |
+
self.print_list_lines(self.curframe.f_code.co_filename, first, last)
|
| 788 |
+
|
| 789 |
+
# vds: >>
|
| 790 |
+
lineno = first
|
| 791 |
+
filename = self.curframe.f_code.co_filename
|
| 792 |
+
self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
|
| 793 |
+
# vds: <<
|
| 794 |
+
|
| 795 |
+
do_l = do_list
|
| 796 |
+
|
| 797 |
+
def getsourcelines(self, obj):
|
| 798 |
+
lines, lineno = inspect.findsource(obj)
|
| 799 |
+
if inspect.isframe(obj) and obj.f_globals is self._get_frame_locals(obj):
|
| 800 |
+
# must be a module frame: do not try to cut a block out of it
|
| 801 |
+
return lines, 1
|
| 802 |
+
elif inspect.ismodule(obj):
|
| 803 |
+
return lines, 1
|
| 804 |
+
return inspect.getblock(lines[lineno:]), lineno+1
|
| 805 |
+
|
| 806 |
+
def do_longlist(self, arg):
|
| 807 |
+
"""Print lines of code from the current stack frame.
|
| 808 |
+
|
| 809 |
+
Shows more lines than 'list' does.
|
| 810 |
+
"""
|
| 811 |
+
self.lastcmd = 'longlist'
|
| 812 |
+
try:
|
| 813 |
+
lines, lineno = self.getsourcelines(self.curframe)
|
| 814 |
+
except OSError as err:
|
| 815 |
+
self.error(err)
|
| 816 |
+
return
|
| 817 |
+
last = lineno + len(lines)
|
| 818 |
+
self.print_list_lines(self.curframe.f_code.co_filename, lineno, last)
|
| 819 |
+
do_ll = do_longlist
|
| 820 |
+
|
| 821 |
+
def do_debug(self, arg):
|
| 822 |
+
"""debug code
|
| 823 |
+
Enter a recursive debugger that steps through the code
|
| 824 |
+
argument (which is an arbitrary expression or statement to be
|
| 825 |
+
executed in the current environment).
|
| 826 |
+
"""
|
| 827 |
+
trace_function = sys.gettrace()
|
| 828 |
+
sys.settrace(None)
|
| 829 |
+
globals = self.curframe.f_globals
|
| 830 |
+
locals = self.curframe_locals
|
| 831 |
+
p = self.__class__(completekey=self.completekey,
|
| 832 |
+
stdin=self.stdin, stdout=self.stdout)
|
| 833 |
+
p.use_rawinput = self.use_rawinput
|
| 834 |
+
p.prompt = "(%s) " % self.prompt.strip()
|
| 835 |
+
self.message("ENTERING RECURSIVE DEBUGGER")
|
| 836 |
+
sys.call_tracing(p.run, (arg, globals, locals))
|
| 837 |
+
self.message("LEAVING RECURSIVE DEBUGGER")
|
| 838 |
+
sys.settrace(trace_function)
|
| 839 |
+
self.lastcmd = p.lastcmd
|
| 840 |
+
|
| 841 |
+
def do_pdef(self, arg):
|
| 842 |
+
"""Print the call signature for any callable object.
|
| 843 |
+
|
| 844 |
+
The debugger interface to %pdef"""
|
| 845 |
+
namespaces = [
|
| 846 |
+
("Locals", self.curframe_locals),
|
| 847 |
+
("Globals", self.curframe.f_globals),
|
| 848 |
+
]
|
| 849 |
+
self.shell.find_line_magic("pdef")(arg, namespaces=namespaces)
|
| 850 |
+
|
| 851 |
+
def do_pdoc(self, arg):
|
| 852 |
+
"""Print the docstring for an object.
|
| 853 |
+
|
| 854 |
+
The debugger interface to %pdoc."""
|
| 855 |
+
namespaces = [
|
| 856 |
+
("Locals", self.curframe_locals),
|
| 857 |
+
("Globals", self.curframe.f_globals),
|
| 858 |
+
]
|
| 859 |
+
self.shell.find_line_magic("pdoc")(arg, namespaces=namespaces)
|
| 860 |
+
|
| 861 |
+
def do_pfile(self, arg):
|
| 862 |
+
"""Print (or run through pager) the file where an object is defined.
|
| 863 |
+
|
| 864 |
+
The debugger interface to %pfile.
|
| 865 |
+
"""
|
| 866 |
+
namespaces = [
|
| 867 |
+
("Locals", self.curframe_locals),
|
| 868 |
+
("Globals", self.curframe.f_globals),
|
| 869 |
+
]
|
| 870 |
+
self.shell.find_line_magic("pfile")(arg, namespaces=namespaces)
|
| 871 |
+
|
| 872 |
+
def do_pinfo(self, arg):
|
| 873 |
+
"""Provide detailed information about an object.
|
| 874 |
+
|
| 875 |
+
The debugger interface to %pinfo, i.e., obj?."""
|
| 876 |
+
namespaces = [
|
| 877 |
+
("Locals", self.curframe_locals),
|
| 878 |
+
("Globals", self.curframe.f_globals),
|
| 879 |
+
]
|
| 880 |
+
self.shell.find_line_magic("pinfo")(arg, namespaces=namespaces)
|
| 881 |
+
|
| 882 |
+
def do_pinfo2(self, arg):
|
| 883 |
+
"""Provide extra detailed information about an object.
|
| 884 |
+
|
| 885 |
+
The debugger interface to %pinfo2, i.e., obj??."""
|
| 886 |
+
namespaces = [
|
| 887 |
+
("Locals", self.curframe_locals),
|
| 888 |
+
("Globals", self.curframe.f_globals),
|
| 889 |
+
]
|
| 890 |
+
self.shell.find_line_magic("pinfo2")(arg, namespaces=namespaces)
|
| 891 |
+
|
| 892 |
+
def do_psource(self, arg):
|
| 893 |
+
"""Print (or run through pager) the source code for an object."""
|
| 894 |
+
namespaces = [
|
| 895 |
+
("Locals", self.curframe_locals),
|
| 896 |
+
("Globals", self.curframe.f_globals),
|
| 897 |
+
]
|
| 898 |
+
self.shell.find_line_magic("psource")(arg, namespaces=namespaces)
|
| 899 |
+
|
| 900 |
+
def do_where(self, arg):
|
| 901 |
+
"""w(here)
|
| 902 |
+
Print a stack trace, with the most recent frame at the bottom.
|
| 903 |
+
An arrow indicates the "current frame", which determines the
|
| 904 |
+
context of most commands. 'bt' is an alias for this command.
|
| 905 |
+
|
| 906 |
+
Take a number as argument as an (optional) number of context line to
|
| 907 |
+
print"""
|
| 908 |
+
if arg:
|
| 909 |
+
try:
|
| 910 |
+
context = int(arg)
|
| 911 |
+
except ValueError as err:
|
| 912 |
+
self.error(err)
|
| 913 |
+
return
|
| 914 |
+
self.print_stack_trace(context)
|
| 915 |
+
else:
|
| 916 |
+
self.print_stack_trace()
|
| 917 |
+
|
| 918 |
+
do_w = do_where
|
| 919 |
+
|
| 920 |
+
def break_anywhere(self, frame):
|
| 921 |
+
"""
|
| 922 |
+
_stop_in_decorator_internals is overly restrictive, as we may still want
|
| 923 |
+
to trace function calls, so we need to also update break_anywhere so
|
| 924 |
+
that is we don't `stop_here`, because of debugger skip, we may still
|
| 925 |
+
stop at any point inside the function
|
| 926 |
+
|
| 927 |
+
"""
|
| 928 |
+
|
| 929 |
+
sup = super().break_anywhere(frame)
|
| 930 |
+
if sup:
|
| 931 |
+
return sup
|
| 932 |
+
if self._predicates["debuggerskip"]:
|
| 933 |
+
if DEBUGGERSKIP in frame.f_code.co_varnames:
|
| 934 |
+
return True
|
| 935 |
+
if frame.f_back and self._get_frame_locals(frame.f_back).get(DEBUGGERSKIP):
|
| 936 |
+
return True
|
| 937 |
+
return False
|
| 938 |
+
|
| 939 |
+
def _is_in_decorator_internal_and_should_skip(self, frame):
|
| 940 |
+
"""
|
| 941 |
+
Utility to tell us whether we are in a decorator internal and should stop.
|
| 942 |
+
|
| 943 |
+
"""
|
| 944 |
+
|
| 945 |
+
# if we are disabled don't skip
|
| 946 |
+
if not self._predicates["debuggerskip"]:
|
| 947 |
+
return False
|
| 948 |
+
|
| 949 |
+
# if frame is tagged, skip by default.
|
| 950 |
+
if DEBUGGERSKIP in frame.f_code.co_varnames:
|
| 951 |
+
return True
|
| 952 |
+
|
| 953 |
+
# if one of the parent frame value set to True skip as well.
|
| 954 |
+
|
| 955 |
+
cframe = frame
|
| 956 |
+
while getattr(cframe, "f_back", None):
|
| 957 |
+
cframe = cframe.f_back
|
| 958 |
+
if self._get_frame_locals(cframe).get(DEBUGGERSKIP):
|
| 959 |
+
return True
|
| 960 |
+
|
| 961 |
+
return False
|
| 962 |
+
|
| 963 |
+
def stop_here(self, frame):
|
| 964 |
+
if self._is_in_decorator_internal_and_should_skip(frame) is True:
|
| 965 |
+
return False
|
| 966 |
+
|
| 967 |
+
hidden = False
|
| 968 |
+
if self.skip_hidden:
|
| 969 |
+
hidden = self._hidden_predicate(frame)
|
| 970 |
+
if hidden:
|
| 971 |
+
if self.report_skipped:
|
| 972 |
+
Colors = self.color_scheme_table.active_colors
|
| 973 |
+
ColorsNormal = Colors.Normal
|
| 974 |
+
print(
|
| 975 |
+
f"{Colors.excName} [... skipped 1 hidden frame]{ColorsNormal}\n"
|
| 976 |
+
)
|
| 977 |
+
return super().stop_here(frame)
|
| 978 |
+
|
| 979 |
+
def do_up(self, arg):
|
| 980 |
+
"""u(p) [count]
|
| 981 |
+
Move the current frame count (default one) levels up in the
|
| 982 |
+
stack trace (to an older frame).
|
| 983 |
+
|
| 984 |
+
Will skip hidden frames.
|
| 985 |
+
"""
|
| 986 |
+
# modified version of upstream that skips
|
| 987 |
+
# frames with __tracebackhide__
|
| 988 |
+
if self.curindex == 0:
|
| 989 |
+
self.error("Oldest frame")
|
| 990 |
+
return
|
| 991 |
+
try:
|
| 992 |
+
count = int(arg or 1)
|
| 993 |
+
except ValueError:
|
| 994 |
+
self.error("Invalid frame count (%s)" % arg)
|
| 995 |
+
return
|
| 996 |
+
skipped = 0
|
| 997 |
+
if count < 0:
|
| 998 |
+
_newframe = 0
|
| 999 |
+
else:
|
| 1000 |
+
counter = 0
|
| 1001 |
+
hidden_frames = self.hidden_frames(self.stack)
|
| 1002 |
+
for i in range(self.curindex - 1, -1, -1):
|
| 1003 |
+
if hidden_frames[i] and self.skip_hidden:
|
| 1004 |
+
skipped += 1
|
| 1005 |
+
continue
|
| 1006 |
+
counter += 1
|
| 1007 |
+
if counter >= count:
|
| 1008 |
+
break
|
| 1009 |
+
else:
|
| 1010 |
+
# if no break occurred.
|
| 1011 |
+
self.error(
|
| 1012 |
+
"all frames above hidden, use `skip_hidden False` to get get into those."
|
| 1013 |
+
)
|
| 1014 |
+
return
|
| 1015 |
+
|
| 1016 |
+
Colors = self.color_scheme_table.active_colors
|
| 1017 |
+
ColorsNormal = Colors.Normal
|
| 1018 |
+
_newframe = i
|
| 1019 |
+
self._select_frame(_newframe)
|
| 1020 |
+
if skipped:
|
| 1021 |
+
print(
|
| 1022 |
+
f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n"
|
| 1023 |
+
)
|
| 1024 |
+
|
| 1025 |
+
def do_down(self, arg):
|
| 1026 |
+
"""d(own) [count]
|
| 1027 |
+
Move the current frame count (default one) levels down in the
|
| 1028 |
+
stack trace (to a newer frame).
|
| 1029 |
+
|
| 1030 |
+
Will skip hidden frames.
|
| 1031 |
+
"""
|
| 1032 |
+
if self.curindex + 1 == len(self.stack):
|
| 1033 |
+
self.error("Newest frame")
|
| 1034 |
+
return
|
| 1035 |
+
try:
|
| 1036 |
+
count = int(arg or 1)
|
| 1037 |
+
except ValueError:
|
| 1038 |
+
self.error("Invalid frame count (%s)" % arg)
|
| 1039 |
+
return
|
| 1040 |
+
if count < 0:
|
| 1041 |
+
_newframe = len(self.stack) - 1
|
| 1042 |
+
else:
|
| 1043 |
+
counter = 0
|
| 1044 |
+
skipped = 0
|
| 1045 |
+
hidden_frames = self.hidden_frames(self.stack)
|
| 1046 |
+
for i in range(self.curindex + 1, len(self.stack)):
|
| 1047 |
+
if hidden_frames[i] and self.skip_hidden:
|
| 1048 |
+
skipped += 1
|
| 1049 |
+
continue
|
| 1050 |
+
counter += 1
|
| 1051 |
+
if counter >= count:
|
| 1052 |
+
break
|
| 1053 |
+
else:
|
| 1054 |
+
self.error(
|
| 1055 |
+
"all frames below hidden, use `skip_hidden False` to get get into those."
|
| 1056 |
+
)
|
| 1057 |
+
return
|
| 1058 |
+
|
| 1059 |
+
Colors = self.color_scheme_table.active_colors
|
| 1060 |
+
ColorsNormal = Colors.Normal
|
| 1061 |
+
if skipped:
|
| 1062 |
+
print(
|
| 1063 |
+
f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n"
|
| 1064 |
+
)
|
| 1065 |
+
_newframe = i
|
| 1066 |
+
|
| 1067 |
+
self._select_frame(_newframe)
|
| 1068 |
+
|
| 1069 |
+
do_d = do_down
|
| 1070 |
+
do_u = do_up
|
| 1071 |
+
|
| 1072 |
+
def do_context(self, context):
|
| 1073 |
+
"""context number_of_lines
|
| 1074 |
+
Set the number of lines of source code to show when displaying
|
| 1075 |
+
stacktrace information.
|
| 1076 |
+
"""
|
| 1077 |
+
try:
|
| 1078 |
+
new_context = int(context)
|
| 1079 |
+
if new_context <= 0:
|
| 1080 |
+
raise ValueError()
|
| 1081 |
+
self.context = new_context
|
| 1082 |
+
except ValueError:
|
| 1083 |
+
self.error("The 'context' command requires a positive integer argument.")
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
class InterruptiblePdb(Pdb):
|
| 1087 |
+
"""Version of debugger where KeyboardInterrupt exits the debugger altogether."""
|
| 1088 |
+
|
| 1089 |
+
def cmdloop(self, intro=None):
|
| 1090 |
+
"""Wrap cmdloop() such that KeyboardInterrupt stops the debugger."""
|
| 1091 |
+
try:
|
| 1092 |
+
return OldPdb.cmdloop(self, intro=intro)
|
| 1093 |
+
except KeyboardInterrupt:
|
| 1094 |
+
self.stop_here = lambda frame: False
|
| 1095 |
+
self.do_quit("")
|
| 1096 |
+
sys.settrace(None)
|
| 1097 |
+
self.quitting = False
|
| 1098 |
+
raise
|
| 1099 |
+
|
| 1100 |
+
def _cmdloop(self):
|
| 1101 |
+
while True:
|
| 1102 |
+
try:
|
| 1103 |
+
# keyboard interrupts allow for an easy way to cancel
|
| 1104 |
+
# the current command, so allow them during interactive input
|
| 1105 |
+
self.allow_kbdint = True
|
| 1106 |
+
self.cmdloop()
|
| 1107 |
+
self.allow_kbdint = False
|
| 1108 |
+
break
|
| 1109 |
+
except KeyboardInterrupt:
|
| 1110 |
+
self.message('--KeyboardInterrupt--')
|
| 1111 |
+
raise
|
| 1112 |
+
|
| 1113 |
+
|
| 1114 |
+
def set_trace(frame=None):
|
| 1115 |
+
"""
|
| 1116 |
+
Start debugging from `frame`.
|
| 1117 |
+
|
| 1118 |
+
If frame is not specified, debugging starts from caller's frame.
|
| 1119 |
+
"""
|
| 1120 |
+
Pdb().set_trace(frame or sys._getframe().f_back)
|
.venv/lib/python3.9/site-packages/IPython/core/display.py
ADDED
|
@@ -0,0 +1,1290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Top-level display functions for displaying object in different formats."""
|
| 3 |
+
|
| 4 |
+
# Copyright (c) IPython Development Team.
|
| 5 |
+
# Distributed under the terms of the Modified BSD License.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
from binascii import b2a_base64, hexlify
|
| 9 |
+
import html
|
| 10 |
+
import json
|
| 11 |
+
import mimetypes
|
| 12 |
+
import os
|
| 13 |
+
import struct
|
| 14 |
+
import warnings
|
| 15 |
+
from copy import deepcopy
|
| 16 |
+
from os.path import splitext
|
| 17 |
+
from pathlib import Path, PurePath
|
| 18 |
+
|
| 19 |
+
from IPython.utils.py3compat import cast_unicode
|
| 20 |
+
from IPython.testing.skipdoctest import skip_doctest
|
| 21 |
+
from . import display_functions
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
__all__ = ['display_pretty', 'display_html', 'display_markdown',
|
| 25 |
+
'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json',
|
| 26 |
+
'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject',
|
| 27 |
+
'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'ProgressBar', 'JSON',
|
| 28 |
+
'GeoJSON', 'Javascript', 'Image', 'set_matplotlib_formats',
|
| 29 |
+
'set_matplotlib_close',
|
| 30 |
+
'Video']
|
| 31 |
+
|
| 32 |
+
_deprecated_names = ["display", "clear_output", "publish_display_data", "update_display", "DisplayHandle"]
|
| 33 |
+
|
| 34 |
+
__all__ = __all__ + _deprecated_names
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# ----- warn to import from IPython.display -----
|
| 38 |
+
|
| 39 |
+
from warnings import warn
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def __getattr__(name):
|
| 43 |
+
if name in _deprecated_names:
|
| 44 |
+
warn(f"Importing {name} from IPython.core.display is deprecated since IPython 7.14, please import from IPython display", DeprecationWarning, stacklevel=2)
|
| 45 |
+
return getattr(display_functions, name)
|
| 46 |
+
|
| 47 |
+
if name in globals().keys():
|
| 48 |
+
return globals()[name]
|
| 49 |
+
else:
|
| 50 |
+
raise AttributeError(f"module {__name__} has no attribute {name}")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
#-----------------------------------------------------------------------------
|
| 54 |
+
# utility functions
|
| 55 |
+
#-----------------------------------------------------------------------------
|
| 56 |
+
|
| 57 |
+
def _safe_exists(path):
|
| 58 |
+
"""Check path, but don't let exceptions raise"""
|
| 59 |
+
try:
|
| 60 |
+
return os.path.exists(path)
|
| 61 |
+
except Exception:
|
| 62 |
+
return False
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _display_mimetype(mimetype, objs, raw=False, metadata=None):
|
| 66 |
+
"""internal implementation of all display_foo methods
|
| 67 |
+
|
| 68 |
+
Parameters
|
| 69 |
+
----------
|
| 70 |
+
mimetype : str
|
| 71 |
+
The mimetype to be published (e.g. 'image/png')
|
| 72 |
+
*objs : object
|
| 73 |
+
The Python objects to display, or if raw=True raw text data to
|
| 74 |
+
display.
|
| 75 |
+
raw : bool
|
| 76 |
+
Are the data objects raw data or Python objects that need to be
|
| 77 |
+
formatted before display? [default: False]
|
| 78 |
+
metadata : dict (optional)
|
| 79 |
+
Metadata to be associated with the specific mimetype output.
|
| 80 |
+
"""
|
| 81 |
+
if metadata:
|
| 82 |
+
metadata = {mimetype: metadata}
|
| 83 |
+
if raw:
|
| 84 |
+
# turn list of pngdata into list of { 'image/png': pngdata }
|
| 85 |
+
objs = [ {mimetype: obj} for obj in objs ]
|
| 86 |
+
display_functions.display(*objs, raw=raw, metadata=metadata, include=[mimetype])
|
| 87 |
+
|
| 88 |
+
#-----------------------------------------------------------------------------
|
| 89 |
+
# Main functions
|
| 90 |
+
#-----------------------------------------------------------------------------
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def display_pretty(*objs, **kwargs):
|
| 94 |
+
"""Display the pretty (default) representation of an object.
|
| 95 |
+
|
| 96 |
+
Parameters
|
| 97 |
+
----------
|
| 98 |
+
*objs : object
|
| 99 |
+
The Python objects to display, or if raw=True raw text data to
|
| 100 |
+
display.
|
| 101 |
+
raw : bool
|
| 102 |
+
Are the data objects raw data or Python objects that need to be
|
| 103 |
+
formatted before display? [default: False]
|
| 104 |
+
metadata : dict (optional)
|
| 105 |
+
Metadata to be associated with the specific mimetype output.
|
| 106 |
+
"""
|
| 107 |
+
_display_mimetype('text/plain', objs, **kwargs)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def display_html(*objs, **kwargs):
|
| 111 |
+
"""Display the HTML representation of an object.
|
| 112 |
+
|
| 113 |
+
Note: If raw=False and the object does not have a HTML
|
| 114 |
+
representation, no HTML will be shown.
|
| 115 |
+
|
| 116 |
+
Parameters
|
| 117 |
+
----------
|
| 118 |
+
*objs : object
|
| 119 |
+
The Python objects to display, or if raw=True raw HTML data to
|
| 120 |
+
display.
|
| 121 |
+
raw : bool
|
| 122 |
+
Are the data objects raw data or Python objects that need to be
|
| 123 |
+
formatted before display? [default: False]
|
| 124 |
+
metadata : dict (optional)
|
| 125 |
+
Metadata to be associated with the specific mimetype output.
|
| 126 |
+
"""
|
| 127 |
+
_display_mimetype('text/html', objs, **kwargs)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def display_markdown(*objs, **kwargs):
|
| 131 |
+
"""Displays the Markdown representation of an object.
|
| 132 |
+
|
| 133 |
+
Parameters
|
| 134 |
+
----------
|
| 135 |
+
*objs : object
|
| 136 |
+
The Python objects to display, or if raw=True raw markdown data to
|
| 137 |
+
display.
|
| 138 |
+
raw : bool
|
| 139 |
+
Are the data objects raw data or Python objects that need to be
|
| 140 |
+
formatted before display? [default: False]
|
| 141 |
+
metadata : dict (optional)
|
| 142 |
+
Metadata to be associated with the specific mimetype output.
|
| 143 |
+
"""
|
| 144 |
+
|
| 145 |
+
_display_mimetype('text/markdown', objs, **kwargs)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def display_svg(*objs, **kwargs):
|
| 149 |
+
"""Display the SVG representation of an object.
|
| 150 |
+
|
| 151 |
+
Parameters
|
| 152 |
+
----------
|
| 153 |
+
*objs : object
|
| 154 |
+
The Python objects to display, or if raw=True raw svg data to
|
| 155 |
+
display.
|
| 156 |
+
raw : bool
|
| 157 |
+
Are the data objects raw data or Python objects that need to be
|
| 158 |
+
formatted before display? [default: False]
|
| 159 |
+
metadata : dict (optional)
|
| 160 |
+
Metadata to be associated with the specific mimetype output.
|
| 161 |
+
"""
|
| 162 |
+
_display_mimetype('image/svg+xml', objs, **kwargs)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def display_png(*objs, **kwargs):
|
| 166 |
+
"""Display the PNG representation of an object.
|
| 167 |
+
|
| 168 |
+
Parameters
|
| 169 |
+
----------
|
| 170 |
+
*objs : object
|
| 171 |
+
The Python objects to display, or if raw=True raw png data to
|
| 172 |
+
display.
|
| 173 |
+
raw : bool
|
| 174 |
+
Are the data objects raw data or Python objects that need to be
|
| 175 |
+
formatted before display? [default: False]
|
| 176 |
+
metadata : dict (optional)
|
| 177 |
+
Metadata to be associated with the specific mimetype output.
|
| 178 |
+
"""
|
| 179 |
+
_display_mimetype('image/png', objs, **kwargs)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def display_jpeg(*objs, **kwargs):
|
| 183 |
+
"""Display the JPEG representation of an object.
|
| 184 |
+
|
| 185 |
+
Parameters
|
| 186 |
+
----------
|
| 187 |
+
*objs : object
|
| 188 |
+
The Python objects to display, or if raw=True raw JPEG data to
|
| 189 |
+
display.
|
| 190 |
+
raw : bool
|
| 191 |
+
Are the data objects raw data or Python objects that need to be
|
| 192 |
+
formatted before display? [default: False]
|
| 193 |
+
metadata : dict (optional)
|
| 194 |
+
Metadata to be associated with the specific mimetype output.
|
| 195 |
+
"""
|
| 196 |
+
_display_mimetype('image/jpeg', objs, **kwargs)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def display_latex(*objs, **kwargs):
|
| 200 |
+
"""Display the LaTeX representation of an object.
|
| 201 |
+
|
| 202 |
+
Parameters
|
| 203 |
+
----------
|
| 204 |
+
*objs : object
|
| 205 |
+
The Python objects to display, or if raw=True raw latex data to
|
| 206 |
+
display.
|
| 207 |
+
raw : bool
|
| 208 |
+
Are the data objects raw data or Python objects that need to be
|
| 209 |
+
formatted before display? [default: False]
|
| 210 |
+
metadata : dict (optional)
|
| 211 |
+
Metadata to be associated with the specific mimetype output.
|
| 212 |
+
"""
|
| 213 |
+
_display_mimetype('text/latex', objs, **kwargs)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def display_json(*objs, **kwargs):
|
| 217 |
+
"""Display the JSON representation of an object.
|
| 218 |
+
|
| 219 |
+
Note that not many frontends support displaying JSON.
|
| 220 |
+
|
| 221 |
+
Parameters
|
| 222 |
+
----------
|
| 223 |
+
*objs : object
|
| 224 |
+
The Python objects to display, or if raw=True raw json data to
|
| 225 |
+
display.
|
| 226 |
+
raw : bool
|
| 227 |
+
Are the data objects raw data or Python objects that need to be
|
| 228 |
+
formatted before display? [default: False]
|
| 229 |
+
metadata : dict (optional)
|
| 230 |
+
Metadata to be associated with the specific mimetype output.
|
| 231 |
+
"""
|
| 232 |
+
_display_mimetype('application/json', objs, **kwargs)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def display_javascript(*objs, **kwargs):
|
| 236 |
+
"""Display the Javascript representation of an object.
|
| 237 |
+
|
| 238 |
+
Parameters
|
| 239 |
+
----------
|
| 240 |
+
*objs : object
|
| 241 |
+
The Python objects to display, or if raw=True raw javascript data to
|
| 242 |
+
display.
|
| 243 |
+
raw : bool
|
| 244 |
+
Are the data objects raw data or Python objects that need to be
|
| 245 |
+
formatted before display? [default: False]
|
| 246 |
+
metadata : dict (optional)
|
| 247 |
+
Metadata to be associated with the specific mimetype output.
|
| 248 |
+
"""
|
| 249 |
+
_display_mimetype('application/javascript', objs, **kwargs)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def display_pdf(*objs, **kwargs):
|
| 253 |
+
"""Display the PDF representation of an object.
|
| 254 |
+
|
| 255 |
+
Parameters
|
| 256 |
+
----------
|
| 257 |
+
*objs : object
|
| 258 |
+
The Python objects to display, or if raw=True raw javascript data to
|
| 259 |
+
display.
|
| 260 |
+
raw : bool
|
| 261 |
+
Are the data objects raw data or Python objects that need to be
|
| 262 |
+
formatted before display? [default: False]
|
| 263 |
+
metadata : dict (optional)
|
| 264 |
+
Metadata to be associated with the specific mimetype output.
|
| 265 |
+
"""
|
| 266 |
+
_display_mimetype('application/pdf', objs, **kwargs)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
#-----------------------------------------------------------------------------
|
| 270 |
+
# Smart classes
|
| 271 |
+
#-----------------------------------------------------------------------------
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class DisplayObject(object):
|
| 275 |
+
"""An object that wraps data to be displayed."""
|
| 276 |
+
|
| 277 |
+
_read_flags = 'r'
|
| 278 |
+
_show_mem_addr = False
|
| 279 |
+
metadata = None
|
| 280 |
+
|
| 281 |
+
def __init__(self, data=None, url=None, filename=None, metadata=None):
|
| 282 |
+
"""Create a display object given raw data.
|
| 283 |
+
|
| 284 |
+
When this object is returned by an expression or passed to the
|
| 285 |
+
display function, it will result in the data being displayed
|
| 286 |
+
in the frontend. The MIME type of the data should match the
|
| 287 |
+
subclasses used, so the Png subclass should be used for 'image/png'
|
| 288 |
+
data. If the data is a URL, the data will first be downloaded
|
| 289 |
+
and then displayed.
|
| 290 |
+
|
| 291 |
+
Parameters
|
| 292 |
+
----------
|
| 293 |
+
data : unicode, str or bytes
|
| 294 |
+
The raw data or a URL or file to load the data from
|
| 295 |
+
url : unicode
|
| 296 |
+
A URL to download the data from.
|
| 297 |
+
filename : unicode
|
| 298 |
+
Path to a local file to load the data from.
|
| 299 |
+
metadata : dict
|
| 300 |
+
Dict of metadata associated to be the object when displayed
|
| 301 |
+
"""
|
| 302 |
+
if isinstance(data, (Path, PurePath)):
|
| 303 |
+
data = str(data)
|
| 304 |
+
|
| 305 |
+
if data is not None and isinstance(data, str):
|
| 306 |
+
if data.startswith('http') and url is None:
|
| 307 |
+
url = data
|
| 308 |
+
filename = None
|
| 309 |
+
data = None
|
| 310 |
+
elif _safe_exists(data) and filename is None:
|
| 311 |
+
url = None
|
| 312 |
+
filename = data
|
| 313 |
+
data = None
|
| 314 |
+
|
| 315 |
+
self.url = url
|
| 316 |
+
self.filename = filename
|
| 317 |
+
# because of @data.setter methods in
|
| 318 |
+
# subclasses ensure url and filename are set
|
| 319 |
+
# before assigning to self.data
|
| 320 |
+
self.data = data
|
| 321 |
+
|
| 322 |
+
if metadata is not None:
|
| 323 |
+
self.metadata = metadata
|
| 324 |
+
elif self.metadata is None:
|
| 325 |
+
self.metadata = {}
|
| 326 |
+
|
| 327 |
+
self.reload()
|
| 328 |
+
self._check_data()
|
| 329 |
+
|
| 330 |
+
def __repr__(self):
|
| 331 |
+
if not self._show_mem_addr:
|
| 332 |
+
cls = self.__class__
|
| 333 |
+
r = "<%s.%s object>" % (cls.__module__, cls.__name__)
|
| 334 |
+
else:
|
| 335 |
+
r = super(DisplayObject, self).__repr__()
|
| 336 |
+
return r
|
| 337 |
+
|
| 338 |
+
def _check_data(self):
|
| 339 |
+
"""Override in subclasses if there's something to check."""
|
| 340 |
+
pass
|
| 341 |
+
|
| 342 |
+
def _data_and_metadata(self):
|
| 343 |
+
"""shortcut for returning metadata with shape information, if defined"""
|
| 344 |
+
if self.metadata:
|
| 345 |
+
return self.data, deepcopy(self.metadata)
|
| 346 |
+
else:
|
| 347 |
+
return self.data
|
| 348 |
+
|
| 349 |
+
def reload(self):
|
| 350 |
+
"""Reload the raw data from file or URL."""
|
| 351 |
+
if self.filename is not None:
|
| 352 |
+
encoding = None if "b" in self._read_flags else "utf-8"
|
| 353 |
+
with open(self.filename, self._read_flags, encoding=encoding) as f:
|
| 354 |
+
self.data = f.read()
|
| 355 |
+
elif self.url is not None:
|
| 356 |
+
# Deferred import
|
| 357 |
+
from urllib.request import urlopen
|
| 358 |
+
response = urlopen(self.url)
|
| 359 |
+
data = response.read()
|
| 360 |
+
# extract encoding from header, if there is one:
|
| 361 |
+
encoding = None
|
| 362 |
+
if 'content-type' in response.headers:
|
| 363 |
+
for sub in response.headers['content-type'].split(';'):
|
| 364 |
+
sub = sub.strip()
|
| 365 |
+
if sub.startswith('charset'):
|
| 366 |
+
encoding = sub.split('=')[-1].strip()
|
| 367 |
+
break
|
| 368 |
+
if 'content-encoding' in response.headers:
|
| 369 |
+
# TODO: do deflate?
|
| 370 |
+
if 'gzip' in response.headers['content-encoding']:
|
| 371 |
+
import gzip
|
| 372 |
+
from io import BytesIO
|
| 373 |
+
|
| 374 |
+
# assume utf-8 if encoding is not specified
|
| 375 |
+
with gzip.open(
|
| 376 |
+
BytesIO(data), "rt", encoding=encoding or "utf-8"
|
| 377 |
+
) as fp:
|
| 378 |
+
encoding = None
|
| 379 |
+
data = fp.read()
|
| 380 |
+
|
| 381 |
+
# decode data, if an encoding was specified
|
| 382 |
+
# We only touch self.data once since
|
| 383 |
+
# subclasses such as SVG have @data.setter methods
|
| 384 |
+
# that transform self.data into ... well svg.
|
| 385 |
+
if encoding:
|
| 386 |
+
self.data = data.decode(encoding, 'replace')
|
| 387 |
+
else:
|
| 388 |
+
self.data = data
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
class TextDisplayObject(DisplayObject):
|
| 392 |
+
"""Create a text display object given raw data.
|
| 393 |
+
|
| 394 |
+
Parameters
|
| 395 |
+
----------
|
| 396 |
+
data : str or unicode
|
| 397 |
+
The raw data or a URL or file to load the data from.
|
| 398 |
+
url : unicode
|
| 399 |
+
A URL to download the data from.
|
| 400 |
+
filename : unicode
|
| 401 |
+
Path to a local file to load the data from.
|
| 402 |
+
metadata : dict
|
| 403 |
+
Dict of metadata associated to be the object when displayed
|
| 404 |
+
"""
|
| 405 |
+
def _check_data(self):
|
| 406 |
+
if self.data is not None and not isinstance(self.data, str):
|
| 407 |
+
raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data))
|
| 408 |
+
|
| 409 |
+
class Pretty(TextDisplayObject):
|
| 410 |
+
|
| 411 |
+
def _repr_pretty_(self, pp, cycle):
|
| 412 |
+
return pp.text(self.data)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class HTML(TextDisplayObject):
|
| 416 |
+
|
| 417 |
+
def __init__(self, data=None, url=None, filename=None, metadata=None):
|
| 418 |
+
def warn():
|
| 419 |
+
if not data:
|
| 420 |
+
return False
|
| 421 |
+
|
| 422 |
+
#
|
| 423 |
+
# Avoid calling lower() on the entire data, because it could be a
|
| 424 |
+
# long string and we're only interested in its beginning and end.
|
| 425 |
+
#
|
| 426 |
+
prefix = data[:10].lower()
|
| 427 |
+
suffix = data[-10:].lower()
|
| 428 |
+
return prefix.startswith("<iframe ") and suffix.endswith("</iframe>")
|
| 429 |
+
|
| 430 |
+
if warn():
|
| 431 |
+
warnings.warn("Consider using IPython.display.IFrame instead")
|
| 432 |
+
super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata)
|
| 433 |
+
|
| 434 |
+
def _repr_html_(self):
|
| 435 |
+
return self._data_and_metadata()
|
| 436 |
+
|
| 437 |
+
def __html__(self):
|
| 438 |
+
"""
|
| 439 |
+
This method exists to inform other HTML-using modules (e.g. Markupsafe,
|
| 440 |
+
htmltag, etc) that this object is HTML and does not need things like
|
| 441 |
+
special characters (<>&) escaped.
|
| 442 |
+
"""
|
| 443 |
+
return self._repr_html_()
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
class Markdown(TextDisplayObject):
|
| 447 |
+
|
| 448 |
+
def _repr_markdown_(self):
|
| 449 |
+
return self._data_and_metadata()
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
class Math(TextDisplayObject):
|
| 453 |
+
|
| 454 |
+
def _repr_latex_(self):
|
| 455 |
+
s = r"$\displaystyle %s$" % self.data.strip('$')
|
| 456 |
+
if self.metadata:
|
| 457 |
+
return s, deepcopy(self.metadata)
|
| 458 |
+
else:
|
| 459 |
+
return s
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
class Latex(TextDisplayObject):
|
| 463 |
+
|
| 464 |
+
def _repr_latex_(self):
|
| 465 |
+
return self._data_and_metadata()
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
class SVG(DisplayObject):
|
| 469 |
+
"""Embed an SVG into the display.
|
| 470 |
+
|
| 471 |
+
Note if you just want to view a svg image via a URL use `:class:Image` with
|
| 472 |
+
a url=URL keyword argument.
|
| 473 |
+
"""
|
| 474 |
+
|
| 475 |
+
_read_flags = 'rb'
|
| 476 |
+
# wrap data in a property, which extracts the <svg> tag, discarding
|
| 477 |
+
# document headers
|
| 478 |
+
_data = None
|
| 479 |
+
|
| 480 |
+
@property
|
| 481 |
+
def data(self):
|
| 482 |
+
return self._data
|
| 483 |
+
|
| 484 |
+
@data.setter
|
| 485 |
+
def data(self, svg):
|
| 486 |
+
if svg is None:
|
| 487 |
+
self._data = None
|
| 488 |
+
return
|
| 489 |
+
# parse into dom object
|
| 490 |
+
from xml.dom import minidom
|
| 491 |
+
x = minidom.parseString(svg)
|
| 492 |
+
# get svg tag (should be 1)
|
| 493 |
+
found_svg = x.getElementsByTagName('svg')
|
| 494 |
+
if found_svg:
|
| 495 |
+
svg = found_svg[0].toxml()
|
| 496 |
+
else:
|
| 497 |
+
# fallback on the input, trust the user
|
| 498 |
+
# but this is probably an error.
|
| 499 |
+
pass
|
| 500 |
+
svg = cast_unicode(svg)
|
| 501 |
+
self._data = svg
|
| 502 |
+
|
| 503 |
+
def _repr_svg_(self):
|
| 504 |
+
return self._data_and_metadata()
|
| 505 |
+
|
| 506 |
+
class ProgressBar(DisplayObject):
|
| 507 |
+
"""Progressbar supports displaying a progressbar like element
|
| 508 |
+
"""
|
| 509 |
+
def __init__(self, total):
|
| 510 |
+
"""Creates a new progressbar
|
| 511 |
+
|
| 512 |
+
Parameters
|
| 513 |
+
----------
|
| 514 |
+
total : int
|
| 515 |
+
maximum size of the progressbar
|
| 516 |
+
"""
|
| 517 |
+
self.total = total
|
| 518 |
+
self._progress = 0
|
| 519 |
+
self.html_width = '60ex'
|
| 520 |
+
self.text_width = 60
|
| 521 |
+
self._display_id = hexlify(os.urandom(8)).decode('ascii')
|
| 522 |
+
|
| 523 |
+
def __repr__(self):
|
| 524 |
+
fraction = self.progress / self.total
|
| 525 |
+
filled = '=' * int(fraction * self.text_width)
|
| 526 |
+
rest = ' ' * (self.text_width - len(filled))
|
| 527 |
+
return '[{}{}] {}/{}'.format(
|
| 528 |
+
filled, rest,
|
| 529 |
+
self.progress, self.total,
|
| 530 |
+
)
|
| 531 |
+
|
| 532 |
+
def _repr_html_(self):
|
| 533 |
+
return "<progress style='width:{}' max='{}' value='{}'></progress>".format(
|
| 534 |
+
self.html_width, self.total, self.progress)
|
| 535 |
+
|
| 536 |
+
def display(self):
|
| 537 |
+
display_functions.display(self, display_id=self._display_id)
|
| 538 |
+
|
| 539 |
+
def update(self):
|
| 540 |
+
display_functions.display(self, display_id=self._display_id, update=True)
|
| 541 |
+
|
| 542 |
+
@property
|
| 543 |
+
def progress(self):
|
| 544 |
+
return self._progress
|
| 545 |
+
|
| 546 |
+
@progress.setter
|
| 547 |
+
def progress(self, value):
|
| 548 |
+
self._progress = value
|
| 549 |
+
self.update()
|
| 550 |
+
|
| 551 |
+
def __iter__(self):
|
| 552 |
+
self.display()
|
| 553 |
+
self._progress = -1 # First iteration is 0
|
| 554 |
+
return self
|
| 555 |
+
|
| 556 |
+
def __next__(self):
|
| 557 |
+
"""Returns current value and increments display by one."""
|
| 558 |
+
self.progress += 1
|
| 559 |
+
if self.progress < self.total:
|
| 560 |
+
return self.progress
|
| 561 |
+
else:
|
| 562 |
+
raise StopIteration()
|
| 563 |
+
|
| 564 |
+
class JSON(DisplayObject):
|
| 565 |
+
"""JSON expects a JSON-able dict or list
|
| 566 |
+
|
| 567 |
+
not an already-serialized JSON string.
|
| 568 |
+
|
| 569 |
+
Scalar types (None, number, string) are not allowed, only dict or list containers.
|
| 570 |
+
"""
|
| 571 |
+
# wrap data in a property, which warns about passing already-serialized JSON
|
| 572 |
+
_data = None
|
| 573 |
+
def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=None, root='root', **kwargs):
|
| 574 |
+
"""Create a JSON display object given raw data.
|
| 575 |
+
|
| 576 |
+
Parameters
|
| 577 |
+
----------
|
| 578 |
+
data : dict or list
|
| 579 |
+
JSON data to display. Not an already-serialized JSON string.
|
| 580 |
+
Scalar types (None, number, string) are not allowed, only dict
|
| 581 |
+
or list containers.
|
| 582 |
+
url : unicode
|
| 583 |
+
A URL to download the data from.
|
| 584 |
+
filename : unicode
|
| 585 |
+
Path to a local file to load the data from.
|
| 586 |
+
expanded : boolean
|
| 587 |
+
Metadata to control whether a JSON display component is expanded.
|
| 588 |
+
metadata : dict
|
| 589 |
+
Specify extra metadata to attach to the json display object.
|
| 590 |
+
root : str
|
| 591 |
+
The name of the root element of the JSON tree
|
| 592 |
+
"""
|
| 593 |
+
self.metadata = {
|
| 594 |
+
'expanded': expanded,
|
| 595 |
+
'root': root,
|
| 596 |
+
}
|
| 597 |
+
if metadata:
|
| 598 |
+
self.metadata.update(metadata)
|
| 599 |
+
if kwargs:
|
| 600 |
+
self.metadata.update(kwargs)
|
| 601 |
+
super(JSON, self).__init__(data=data, url=url, filename=filename)
|
| 602 |
+
|
| 603 |
+
def _check_data(self):
|
| 604 |
+
if self.data is not None and not isinstance(self.data, (dict, list)):
|
| 605 |
+
raise TypeError("%s expects JSONable dict or list, not %r" % (self.__class__.__name__, self.data))
|
| 606 |
+
|
| 607 |
+
@property
|
| 608 |
+
def data(self):
|
| 609 |
+
return self._data
|
| 610 |
+
|
| 611 |
+
@data.setter
|
| 612 |
+
def data(self, data):
|
| 613 |
+
if isinstance(data, (Path, PurePath)):
|
| 614 |
+
data = str(data)
|
| 615 |
+
|
| 616 |
+
if isinstance(data, str):
|
| 617 |
+
if self.filename is None and self.url is None:
|
| 618 |
+
warnings.warn("JSON expects JSONable dict or list, not JSON strings")
|
| 619 |
+
data = json.loads(data)
|
| 620 |
+
self._data = data
|
| 621 |
+
|
| 622 |
+
def _data_and_metadata(self):
|
| 623 |
+
return self.data, self.metadata
|
| 624 |
+
|
| 625 |
+
def _repr_json_(self):
|
| 626 |
+
return self._data_and_metadata()
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
_css_t = """var link = document.createElement("link");
|
| 630 |
+
link.rel = "stylesheet";
|
| 631 |
+
link.type = "text/css";
|
| 632 |
+
link.href = "%s";
|
| 633 |
+
document.head.appendChild(link);
|
| 634 |
+
"""
|
| 635 |
+
|
| 636 |
+
_lib_t1 = """new Promise(function(resolve, reject) {
|
| 637 |
+
var script = document.createElement("script");
|
| 638 |
+
script.onload = resolve;
|
| 639 |
+
script.onerror = reject;
|
| 640 |
+
script.src = "%s";
|
| 641 |
+
document.head.appendChild(script);
|
| 642 |
+
}).then(() => {
|
| 643 |
+
"""
|
| 644 |
+
|
| 645 |
+
_lib_t2 = """
|
| 646 |
+
});"""
|
| 647 |
+
|
| 648 |
+
class GeoJSON(JSON):
|
| 649 |
+
"""GeoJSON expects JSON-able dict
|
| 650 |
+
|
| 651 |
+
not an already-serialized JSON string.
|
| 652 |
+
|
| 653 |
+
Scalar types (None, number, string) are not allowed, only dict containers.
|
| 654 |
+
"""
|
| 655 |
+
|
| 656 |
+
def __init__(self, *args, **kwargs):
|
| 657 |
+
"""Create a GeoJSON display object given raw data.
|
| 658 |
+
|
| 659 |
+
Parameters
|
| 660 |
+
----------
|
| 661 |
+
data : dict or list
|
| 662 |
+
VegaLite data. Not an already-serialized JSON string.
|
| 663 |
+
Scalar types (None, number, string) are not allowed, only dict
|
| 664 |
+
or list containers.
|
| 665 |
+
url_template : string
|
| 666 |
+
Leaflet TileLayer URL template: http://leafletjs.com/reference.html#url-template
|
| 667 |
+
layer_options : dict
|
| 668 |
+
Leaflet TileLayer options: http://leafletjs.com/reference.html#tilelayer-options
|
| 669 |
+
url : unicode
|
| 670 |
+
A URL to download the data from.
|
| 671 |
+
filename : unicode
|
| 672 |
+
Path to a local file to load the data from.
|
| 673 |
+
metadata : dict
|
| 674 |
+
Specify extra metadata to attach to the json display object.
|
| 675 |
+
|
| 676 |
+
Examples
|
| 677 |
+
--------
|
| 678 |
+
The following will display an interactive map of Mars with a point of
|
| 679 |
+
interest on frontend that do support GeoJSON display.
|
| 680 |
+
|
| 681 |
+
>>> from IPython.display import GeoJSON
|
| 682 |
+
|
| 683 |
+
>>> GeoJSON(data={
|
| 684 |
+
... "type": "Feature",
|
| 685 |
+
... "geometry": {
|
| 686 |
+
... "type": "Point",
|
| 687 |
+
... "coordinates": [-81.327, 296.038]
|
| 688 |
+
... }
|
| 689 |
+
... },
|
| 690 |
+
... url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png",
|
| 691 |
+
... layer_options={
|
| 692 |
+
... "basemap_id": "celestia_mars-shaded-16k_global",
|
| 693 |
+
... "attribution" : "Celestia/praesepe",
|
| 694 |
+
... "minZoom" : 0,
|
| 695 |
+
... "maxZoom" : 18,
|
| 696 |
+
... })
|
| 697 |
+
<IPython.core.display.GeoJSON object>
|
| 698 |
+
|
| 699 |
+
In the terminal IPython, you will only see the text representation of
|
| 700 |
+
the GeoJSON object.
|
| 701 |
+
|
| 702 |
+
"""
|
| 703 |
+
|
| 704 |
+
super(GeoJSON, self).__init__(*args, **kwargs)
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
def _ipython_display_(self):
|
| 708 |
+
bundle = {
|
| 709 |
+
'application/geo+json': self.data,
|
| 710 |
+
'text/plain': '<IPython.display.GeoJSON object>'
|
| 711 |
+
}
|
| 712 |
+
metadata = {
|
| 713 |
+
'application/geo+json': self.metadata
|
| 714 |
+
}
|
| 715 |
+
display_functions.display(bundle, metadata=metadata, raw=True)
|
| 716 |
+
|
| 717 |
+
class Javascript(TextDisplayObject):
|
| 718 |
+
|
| 719 |
+
def __init__(self, data=None, url=None, filename=None, lib=None, css=None):
|
| 720 |
+
"""Create a Javascript display object given raw data.
|
| 721 |
+
|
| 722 |
+
When this object is returned by an expression or passed to the
|
| 723 |
+
display function, it will result in the data being displayed
|
| 724 |
+
in the frontend. If the data is a URL, the data will first be
|
| 725 |
+
downloaded and then displayed.
|
| 726 |
+
|
| 727 |
+
In the Notebook, the containing element will be available as `element`,
|
| 728 |
+
and jQuery will be available. Content appended to `element` will be
|
| 729 |
+
visible in the output area.
|
| 730 |
+
|
| 731 |
+
Parameters
|
| 732 |
+
----------
|
| 733 |
+
data : unicode, str or bytes
|
| 734 |
+
The Javascript source code or a URL to download it from.
|
| 735 |
+
url : unicode
|
| 736 |
+
A URL to download the data from.
|
| 737 |
+
filename : unicode
|
| 738 |
+
Path to a local file to load the data from.
|
| 739 |
+
lib : list or str
|
| 740 |
+
A sequence of Javascript library URLs to load asynchronously before
|
| 741 |
+
running the source code. The full URLs of the libraries should
|
| 742 |
+
be given. A single Javascript library URL can also be given as a
|
| 743 |
+
string.
|
| 744 |
+
css : list or str
|
| 745 |
+
A sequence of css files to load before running the source code.
|
| 746 |
+
The full URLs of the css files should be given. A single css URL
|
| 747 |
+
can also be given as a string.
|
| 748 |
+
"""
|
| 749 |
+
if isinstance(lib, str):
|
| 750 |
+
lib = [lib]
|
| 751 |
+
elif lib is None:
|
| 752 |
+
lib = []
|
| 753 |
+
if isinstance(css, str):
|
| 754 |
+
css = [css]
|
| 755 |
+
elif css is None:
|
| 756 |
+
css = []
|
| 757 |
+
if not isinstance(lib, (list,tuple)):
|
| 758 |
+
raise TypeError('expected sequence, got: %r' % lib)
|
| 759 |
+
if not isinstance(css, (list,tuple)):
|
| 760 |
+
raise TypeError('expected sequence, got: %r' % css)
|
| 761 |
+
self.lib = lib
|
| 762 |
+
self.css = css
|
| 763 |
+
super(Javascript, self).__init__(data=data, url=url, filename=filename)
|
| 764 |
+
|
| 765 |
+
def _repr_javascript_(self):
|
| 766 |
+
r = ''
|
| 767 |
+
for c in self.css:
|
| 768 |
+
r += _css_t % c
|
| 769 |
+
for l in self.lib:
|
| 770 |
+
r += _lib_t1 % l
|
| 771 |
+
r += self.data
|
| 772 |
+
r += _lib_t2*len(self.lib)
|
| 773 |
+
return r
|
| 774 |
+
|
| 775 |
+
# constants for identifying png/jpeg data
|
| 776 |
+
_PNG = b'\x89PNG\r\n\x1a\n'
|
| 777 |
+
_JPEG = b'\xff\xd8'
|
| 778 |
+
|
| 779 |
+
def _pngxy(data):
|
| 780 |
+
"""read the (width, height) from a PNG header"""
|
| 781 |
+
ihdr = data.index(b'IHDR')
|
| 782 |
+
# next 8 bytes are width/height
|
| 783 |
+
return struct.unpack('>ii', data[ihdr+4:ihdr+12])
|
| 784 |
+
|
| 785 |
+
def _jpegxy(data):
|
| 786 |
+
"""read the (width, height) from a JPEG header"""
|
| 787 |
+
# adapted from http://www.64lines.com/jpeg-width-height
|
| 788 |
+
|
| 789 |
+
idx = 4
|
| 790 |
+
while True:
|
| 791 |
+
block_size = struct.unpack('>H', data[idx:idx+2])[0]
|
| 792 |
+
idx = idx + block_size
|
| 793 |
+
if data[idx:idx+2] == b'\xFF\xC0':
|
| 794 |
+
# found Start of Frame
|
| 795 |
+
iSOF = idx
|
| 796 |
+
break
|
| 797 |
+
else:
|
| 798 |
+
# read another block
|
| 799 |
+
idx += 2
|
| 800 |
+
|
| 801 |
+
h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9])
|
| 802 |
+
return w, h
|
| 803 |
+
|
| 804 |
+
def _gifxy(data):
|
| 805 |
+
"""read the (width, height) from a GIF header"""
|
| 806 |
+
return struct.unpack('<HH', data[6:10])
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
class Image(DisplayObject):
|
| 810 |
+
|
| 811 |
+
_read_flags = 'rb'
|
| 812 |
+
_FMT_JPEG = u'jpeg'
|
| 813 |
+
_FMT_PNG = u'png'
|
| 814 |
+
_FMT_GIF = u'gif'
|
| 815 |
+
_ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG, _FMT_GIF]
|
| 816 |
+
_MIMETYPES = {
|
| 817 |
+
_FMT_PNG: 'image/png',
|
| 818 |
+
_FMT_JPEG: 'image/jpeg',
|
| 819 |
+
_FMT_GIF: 'image/gif',
|
| 820 |
+
}
|
| 821 |
+
|
| 822 |
+
def __init__(
|
| 823 |
+
self,
|
| 824 |
+
data=None,
|
| 825 |
+
url=None,
|
| 826 |
+
filename=None,
|
| 827 |
+
format=None,
|
| 828 |
+
embed=None,
|
| 829 |
+
width=None,
|
| 830 |
+
height=None,
|
| 831 |
+
retina=False,
|
| 832 |
+
unconfined=False,
|
| 833 |
+
metadata=None,
|
| 834 |
+
alt=None,
|
| 835 |
+
):
|
| 836 |
+
"""Create a PNG/JPEG/GIF image object given raw data.
|
| 837 |
+
|
| 838 |
+
When this object is returned by an input cell or passed to the
|
| 839 |
+
display function, it will result in the image being displayed
|
| 840 |
+
in the frontend.
|
| 841 |
+
|
| 842 |
+
Parameters
|
| 843 |
+
----------
|
| 844 |
+
data : unicode, str or bytes
|
| 845 |
+
The raw image data or a URL or filename to load the data from.
|
| 846 |
+
This always results in embedded image data.
|
| 847 |
+
|
| 848 |
+
url : unicode
|
| 849 |
+
A URL to download the data from. If you specify `url=`,
|
| 850 |
+
the image data will not be embedded unless you also specify `embed=True`.
|
| 851 |
+
|
| 852 |
+
filename : unicode
|
| 853 |
+
Path to a local file to load the data from.
|
| 854 |
+
Images from a file are always embedded.
|
| 855 |
+
|
| 856 |
+
format : unicode
|
| 857 |
+
The format of the image data (png/jpeg/jpg/gif). If a filename or URL is given
|
| 858 |
+
for format will be inferred from the filename extension.
|
| 859 |
+
|
| 860 |
+
embed : bool
|
| 861 |
+
Should the image data be embedded using a data URI (True) or be
|
| 862 |
+
loaded using an <img> tag. Set this to True if you want the image
|
| 863 |
+
to be viewable later with no internet connection in the notebook.
|
| 864 |
+
|
| 865 |
+
Default is `True`, unless the keyword argument `url` is set, then
|
| 866 |
+
default value is `False`.
|
| 867 |
+
|
| 868 |
+
Note that QtConsole is not able to display images if `embed` is set to `False`
|
| 869 |
+
|
| 870 |
+
width : int
|
| 871 |
+
Width in pixels to which to constrain the image in html
|
| 872 |
+
|
| 873 |
+
height : int
|
| 874 |
+
Height in pixels to which to constrain the image in html
|
| 875 |
+
|
| 876 |
+
retina : bool
|
| 877 |
+
Automatically set the width and height to half of the measured
|
| 878 |
+
width and height.
|
| 879 |
+
This only works for embedded images because it reads the width/height
|
| 880 |
+
from image data.
|
| 881 |
+
For non-embedded images, you can just set the desired display width
|
| 882 |
+
and height directly.
|
| 883 |
+
|
| 884 |
+
unconfined : bool
|
| 885 |
+
Set unconfined=True to disable max-width confinement of the image.
|
| 886 |
+
|
| 887 |
+
metadata : dict
|
| 888 |
+
Specify extra metadata to attach to the image.
|
| 889 |
+
|
| 890 |
+
alt : unicode
|
| 891 |
+
Alternative text for the image, for use by screen readers.
|
| 892 |
+
|
| 893 |
+
Examples
|
| 894 |
+
--------
|
| 895 |
+
embedded image data, works in qtconsole and notebook
|
| 896 |
+
when passed positionally, the first arg can be any of raw image data,
|
| 897 |
+
a URL, or a filename from which to load image data.
|
| 898 |
+
The result is always embedding image data for inline images.
|
| 899 |
+
|
| 900 |
+
>>> Image('https://www.google.fr/images/srpr/logo3w.png') # doctest: +SKIP
|
| 901 |
+
<IPython.core.display.Image object>
|
| 902 |
+
|
| 903 |
+
>>> Image('/path/to/image.jpg')
|
| 904 |
+
<IPython.core.display.Image object>
|
| 905 |
+
|
| 906 |
+
>>> Image(b'RAW_PNG_DATA...')
|
| 907 |
+
<IPython.core.display.Image object>
|
| 908 |
+
|
| 909 |
+
Specifying Image(url=...) does not embed the image data,
|
| 910 |
+
it only generates ``<img>`` tag with a link to the source.
|
| 911 |
+
This will not work in the qtconsole or offline.
|
| 912 |
+
|
| 913 |
+
>>> Image(url='https://www.google.fr/images/srpr/logo3w.png')
|
| 914 |
+
<IPython.core.display.Image object>
|
| 915 |
+
|
| 916 |
+
"""
|
| 917 |
+
if isinstance(data, (Path, PurePath)):
|
| 918 |
+
data = str(data)
|
| 919 |
+
|
| 920 |
+
if filename is not None:
|
| 921 |
+
ext = self._find_ext(filename)
|
| 922 |
+
elif url is not None:
|
| 923 |
+
ext = self._find_ext(url)
|
| 924 |
+
elif data is None:
|
| 925 |
+
raise ValueError("No image data found. Expecting filename, url, or data.")
|
| 926 |
+
elif isinstance(data, str) and (
|
| 927 |
+
data.startswith('http') or _safe_exists(data)
|
| 928 |
+
):
|
| 929 |
+
ext = self._find_ext(data)
|
| 930 |
+
else:
|
| 931 |
+
ext = None
|
| 932 |
+
|
| 933 |
+
if format is None:
|
| 934 |
+
if ext is not None:
|
| 935 |
+
if ext == u'jpg' or ext == u'jpeg':
|
| 936 |
+
format = self._FMT_JPEG
|
| 937 |
+
elif ext == u'png':
|
| 938 |
+
format = self._FMT_PNG
|
| 939 |
+
elif ext == u'gif':
|
| 940 |
+
format = self._FMT_GIF
|
| 941 |
+
else:
|
| 942 |
+
format = ext.lower()
|
| 943 |
+
elif isinstance(data, bytes):
|
| 944 |
+
# infer image type from image data header,
|
| 945 |
+
# only if format has not been specified.
|
| 946 |
+
if data[:2] == _JPEG:
|
| 947 |
+
format = self._FMT_JPEG
|
| 948 |
+
|
| 949 |
+
# failed to detect format, default png
|
| 950 |
+
if format is None:
|
| 951 |
+
format = self._FMT_PNG
|
| 952 |
+
|
| 953 |
+
if format.lower() == 'jpg':
|
| 954 |
+
# jpg->jpeg
|
| 955 |
+
format = self._FMT_JPEG
|
| 956 |
+
|
| 957 |
+
self.format = format.lower()
|
| 958 |
+
self.embed = embed if embed is not None else (url is None)
|
| 959 |
+
|
| 960 |
+
if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
|
| 961 |
+
raise ValueError("Cannot embed the '%s' image format" % (self.format))
|
| 962 |
+
if self.embed:
|
| 963 |
+
self._mimetype = self._MIMETYPES.get(self.format)
|
| 964 |
+
|
| 965 |
+
self.width = width
|
| 966 |
+
self.height = height
|
| 967 |
+
self.retina = retina
|
| 968 |
+
self.unconfined = unconfined
|
| 969 |
+
self.alt = alt
|
| 970 |
+
super(Image, self).__init__(data=data, url=url, filename=filename,
|
| 971 |
+
metadata=metadata)
|
| 972 |
+
|
| 973 |
+
if self.width is None and self.metadata.get('width', {}):
|
| 974 |
+
self.width = metadata['width']
|
| 975 |
+
|
| 976 |
+
if self.height is None and self.metadata.get('height', {}):
|
| 977 |
+
self.height = metadata['height']
|
| 978 |
+
|
| 979 |
+
if self.alt is None and self.metadata.get("alt", {}):
|
| 980 |
+
self.alt = metadata["alt"]
|
| 981 |
+
|
| 982 |
+
if retina:
|
| 983 |
+
self._retina_shape()
|
| 984 |
+
|
| 985 |
+
|
| 986 |
+
def _retina_shape(self):
|
| 987 |
+
"""load pixel-doubled width and height from image data"""
|
| 988 |
+
if not self.embed:
|
| 989 |
+
return
|
| 990 |
+
if self.format == self._FMT_PNG:
|
| 991 |
+
w, h = _pngxy(self.data)
|
| 992 |
+
elif self.format == self._FMT_JPEG:
|
| 993 |
+
w, h = _jpegxy(self.data)
|
| 994 |
+
elif self.format == self._FMT_GIF:
|
| 995 |
+
w, h = _gifxy(self.data)
|
| 996 |
+
else:
|
| 997 |
+
# retina only supports png
|
| 998 |
+
return
|
| 999 |
+
self.width = w // 2
|
| 1000 |
+
self.height = h // 2
|
| 1001 |
+
|
| 1002 |
+
def reload(self):
|
| 1003 |
+
"""Reload the raw data from file or URL."""
|
| 1004 |
+
if self.embed:
|
| 1005 |
+
super(Image,self).reload()
|
| 1006 |
+
if self.retina:
|
| 1007 |
+
self._retina_shape()
|
| 1008 |
+
|
| 1009 |
+
def _repr_html_(self):
|
| 1010 |
+
if not self.embed:
|
| 1011 |
+
width = height = klass = alt = ""
|
| 1012 |
+
if self.width:
|
| 1013 |
+
width = ' width="%d"' % self.width
|
| 1014 |
+
if self.height:
|
| 1015 |
+
height = ' height="%d"' % self.height
|
| 1016 |
+
if self.unconfined:
|
| 1017 |
+
klass = ' class="unconfined"'
|
| 1018 |
+
if self.alt:
|
| 1019 |
+
alt = ' alt="%s"' % html.escape(self.alt)
|
| 1020 |
+
return '<img src="{url}"{width}{height}{klass}{alt}/>'.format(
|
| 1021 |
+
url=self.url,
|
| 1022 |
+
width=width,
|
| 1023 |
+
height=height,
|
| 1024 |
+
klass=klass,
|
| 1025 |
+
alt=alt,
|
| 1026 |
+
)
|
| 1027 |
+
|
| 1028 |
+
def _repr_mimebundle_(self, include=None, exclude=None):
|
| 1029 |
+
"""Return the image as a mimebundle
|
| 1030 |
+
|
| 1031 |
+
Any new mimetype support should be implemented here.
|
| 1032 |
+
"""
|
| 1033 |
+
if self.embed:
|
| 1034 |
+
mimetype = self._mimetype
|
| 1035 |
+
data, metadata = self._data_and_metadata(always_both=True)
|
| 1036 |
+
if metadata:
|
| 1037 |
+
metadata = {mimetype: metadata}
|
| 1038 |
+
return {mimetype: data}, metadata
|
| 1039 |
+
else:
|
| 1040 |
+
return {'text/html': self._repr_html_()}
|
| 1041 |
+
|
| 1042 |
+
def _data_and_metadata(self, always_both=False):
|
| 1043 |
+
"""shortcut for returning metadata with shape information, if defined"""
|
| 1044 |
+
try:
|
| 1045 |
+
b64_data = b2a_base64(self.data, newline=False).decode("ascii")
|
| 1046 |
+
except TypeError as e:
|
| 1047 |
+
raise FileNotFoundError(
|
| 1048 |
+
"No such file or directory: '%s'" % (self.data)) from e
|
| 1049 |
+
md = {}
|
| 1050 |
+
if self.metadata:
|
| 1051 |
+
md.update(self.metadata)
|
| 1052 |
+
if self.width:
|
| 1053 |
+
md['width'] = self.width
|
| 1054 |
+
if self.height:
|
| 1055 |
+
md['height'] = self.height
|
| 1056 |
+
if self.unconfined:
|
| 1057 |
+
md['unconfined'] = self.unconfined
|
| 1058 |
+
if self.alt:
|
| 1059 |
+
md["alt"] = self.alt
|
| 1060 |
+
if md or always_both:
|
| 1061 |
+
return b64_data, md
|
| 1062 |
+
else:
|
| 1063 |
+
return b64_data
|
| 1064 |
+
|
| 1065 |
+
def _repr_png_(self):
|
| 1066 |
+
if self.embed and self.format == self._FMT_PNG:
|
| 1067 |
+
return self._data_and_metadata()
|
| 1068 |
+
|
| 1069 |
+
def _repr_jpeg_(self):
|
| 1070 |
+
if self.embed and self.format == self._FMT_JPEG:
|
| 1071 |
+
return self._data_and_metadata()
|
| 1072 |
+
|
| 1073 |
+
def _find_ext(self, s):
|
| 1074 |
+
base, ext = splitext(s)
|
| 1075 |
+
|
| 1076 |
+
if not ext:
|
| 1077 |
+
return base
|
| 1078 |
+
|
| 1079 |
+
# `splitext` includes leading period, so we skip it
|
| 1080 |
+
return ext[1:].lower()
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
class Video(DisplayObject):
|
| 1084 |
+
|
| 1085 |
+
def __init__(self, data=None, url=None, filename=None, embed=False,
|
| 1086 |
+
mimetype=None, width=None, height=None, html_attributes="controls"):
|
| 1087 |
+
"""Create a video object given raw data or an URL.
|
| 1088 |
+
|
| 1089 |
+
When this object is returned by an input cell or passed to the
|
| 1090 |
+
display function, it will result in the video being displayed
|
| 1091 |
+
in the frontend.
|
| 1092 |
+
|
| 1093 |
+
Parameters
|
| 1094 |
+
----------
|
| 1095 |
+
data : unicode, str or bytes
|
| 1096 |
+
The raw video data or a URL or filename to load the data from.
|
| 1097 |
+
Raw data will require passing ``embed=True``.
|
| 1098 |
+
|
| 1099 |
+
url : unicode
|
| 1100 |
+
A URL for the video. If you specify ``url=``,
|
| 1101 |
+
the image data will not be embedded.
|
| 1102 |
+
|
| 1103 |
+
filename : unicode
|
| 1104 |
+
Path to a local file containing the video.
|
| 1105 |
+
Will be interpreted as a local URL unless ``embed=True``.
|
| 1106 |
+
|
| 1107 |
+
embed : bool
|
| 1108 |
+
Should the video be embedded using a data URI (True) or be
|
| 1109 |
+
loaded using a <video> tag (False).
|
| 1110 |
+
|
| 1111 |
+
Since videos are large, embedding them should be avoided, if possible.
|
| 1112 |
+
You must confirm embedding as your intention by passing ``embed=True``.
|
| 1113 |
+
|
| 1114 |
+
Local files can be displayed with URLs without embedding the content, via::
|
| 1115 |
+
|
| 1116 |
+
Video('./video.mp4')
|
| 1117 |
+
|
| 1118 |
+
mimetype : unicode
|
| 1119 |
+
Specify the mimetype for embedded videos.
|
| 1120 |
+
Default will be guessed from file extension, if available.
|
| 1121 |
+
|
| 1122 |
+
width : int
|
| 1123 |
+
Width in pixels to which to constrain the video in HTML.
|
| 1124 |
+
If not supplied, defaults to the width of the video.
|
| 1125 |
+
|
| 1126 |
+
height : int
|
| 1127 |
+
Height in pixels to which to constrain the video in html.
|
| 1128 |
+
If not supplied, defaults to the height of the video.
|
| 1129 |
+
|
| 1130 |
+
html_attributes : str
|
| 1131 |
+
Attributes for the HTML ``<video>`` block.
|
| 1132 |
+
Default: ``"controls"`` to get video controls.
|
| 1133 |
+
Other examples: ``"controls muted"`` for muted video with controls,
|
| 1134 |
+
``"loop autoplay"`` for looping autoplaying video without controls.
|
| 1135 |
+
|
| 1136 |
+
Examples
|
| 1137 |
+
--------
|
| 1138 |
+
::
|
| 1139 |
+
|
| 1140 |
+
Video('https://archive.org/download/Sita_Sings_the_Blues/Sita_Sings_the_Blues_small.mp4')
|
| 1141 |
+
Video('path/to/video.mp4')
|
| 1142 |
+
Video('path/to/video.mp4', embed=True)
|
| 1143 |
+
Video('path/to/video.mp4', embed=True, html_attributes="controls muted autoplay")
|
| 1144 |
+
Video(b'raw-videodata', embed=True)
|
| 1145 |
+
"""
|
| 1146 |
+
if isinstance(data, (Path, PurePath)):
|
| 1147 |
+
data = str(data)
|
| 1148 |
+
|
| 1149 |
+
if url is None and isinstance(data, str) and data.startswith(('http:', 'https:')):
|
| 1150 |
+
url = data
|
| 1151 |
+
data = None
|
| 1152 |
+
elif data is not None and os.path.exists(data):
|
| 1153 |
+
filename = data
|
| 1154 |
+
data = None
|
| 1155 |
+
|
| 1156 |
+
if data and not embed:
|
| 1157 |
+
msg = ''.join([
|
| 1158 |
+
"To embed videos, you must pass embed=True ",
|
| 1159 |
+
"(this may make your notebook files huge)\n",
|
| 1160 |
+
"Consider passing Video(url='...')",
|
| 1161 |
+
])
|
| 1162 |
+
raise ValueError(msg)
|
| 1163 |
+
|
| 1164 |
+
self.mimetype = mimetype
|
| 1165 |
+
self.embed = embed
|
| 1166 |
+
self.width = width
|
| 1167 |
+
self.height = height
|
| 1168 |
+
self.html_attributes = html_attributes
|
| 1169 |
+
super(Video, self).__init__(data=data, url=url, filename=filename)
|
| 1170 |
+
|
| 1171 |
+
def _repr_html_(self):
|
| 1172 |
+
width = height = ''
|
| 1173 |
+
if self.width:
|
| 1174 |
+
width = ' width="%d"' % self.width
|
| 1175 |
+
if self.height:
|
| 1176 |
+
height = ' height="%d"' % self.height
|
| 1177 |
+
|
| 1178 |
+
# External URLs and potentially local files are not embedded into the
|
| 1179 |
+
# notebook output.
|
| 1180 |
+
if not self.embed:
|
| 1181 |
+
url = self.url if self.url is not None else self.filename
|
| 1182 |
+
output = """<video src="{0}" {1} {2} {3}>
|
| 1183 |
+
Your browser does not support the <code>video</code> element.
|
| 1184 |
+
</video>""".format(url, self.html_attributes, width, height)
|
| 1185 |
+
return output
|
| 1186 |
+
|
| 1187 |
+
# Embedded videos are base64-encoded.
|
| 1188 |
+
mimetype = self.mimetype
|
| 1189 |
+
if self.filename is not None:
|
| 1190 |
+
if not mimetype:
|
| 1191 |
+
mimetype, _ = mimetypes.guess_type(self.filename)
|
| 1192 |
+
|
| 1193 |
+
with open(self.filename, 'rb') as f:
|
| 1194 |
+
video = f.read()
|
| 1195 |
+
else:
|
| 1196 |
+
video = self.data
|
| 1197 |
+
if isinstance(video, str):
|
| 1198 |
+
# unicode input is already b64-encoded
|
| 1199 |
+
b64_video = video
|
| 1200 |
+
else:
|
| 1201 |
+
b64_video = b2a_base64(video, newline=False).decode("ascii").rstrip()
|
| 1202 |
+
|
| 1203 |
+
output = """<video {0} {1} {2}>
|
| 1204 |
+
<source src="data:{3};base64,{4}" type="{3}">
|
| 1205 |
+
Your browser does not support the video tag.
|
| 1206 |
+
</video>""".format(self.html_attributes, width, height, mimetype, b64_video)
|
| 1207 |
+
return output
|
| 1208 |
+
|
| 1209 |
+
def reload(self):
|
| 1210 |
+
# TODO
|
| 1211 |
+
pass
|
| 1212 |
+
|
| 1213 |
+
|
| 1214 |
+
@skip_doctest
|
| 1215 |
+
def set_matplotlib_formats(*formats, **kwargs):
|
| 1216 |
+
"""
|
| 1217 |
+
.. deprecated:: 7.23
|
| 1218 |
+
|
| 1219 |
+
use `matplotlib_inline.backend_inline.set_matplotlib_formats()`
|
| 1220 |
+
|
| 1221 |
+
Select figure formats for the inline backend. Optionally pass quality for JPEG.
|
| 1222 |
+
|
| 1223 |
+
For example, this enables PNG and JPEG output with a JPEG quality of 90%::
|
| 1224 |
+
|
| 1225 |
+
In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)
|
| 1226 |
+
|
| 1227 |
+
To set this in your config files use the following::
|
| 1228 |
+
|
| 1229 |
+
c.InlineBackend.figure_formats = {'png', 'jpeg'}
|
| 1230 |
+
c.InlineBackend.print_figure_kwargs.update({'quality' : 90})
|
| 1231 |
+
|
| 1232 |
+
Parameters
|
| 1233 |
+
----------
|
| 1234 |
+
*formats : strs
|
| 1235 |
+
One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
|
| 1236 |
+
**kwargs
|
| 1237 |
+
Keyword args will be relayed to ``figure.canvas.print_figure``.
|
| 1238 |
+
"""
|
| 1239 |
+
warnings.warn(
|
| 1240 |
+
"`set_matplotlib_formats` is deprecated since IPython 7.23, directly "
|
| 1241 |
+
"use `matplotlib_inline.backend_inline.set_matplotlib_formats()`",
|
| 1242 |
+
DeprecationWarning,
|
| 1243 |
+
stacklevel=2,
|
| 1244 |
+
)
|
| 1245 |
+
|
| 1246 |
+
from matplotlib_inline.backend_inline import (
|
| 1247 |
+
set_matplotlib_formats as set_matplotlib_formats_orig,
|
| 1248 |
+
)
|
| 1249 |
+
|
| 1250 |
+
set_matplotlib_formats_orig(*formats, **kwargs)
|
| 1251 |
+
|
| 1252 |
+
@skip_doctest
|
| 1253 |
+
def set_matplotlib_close(close=True):
|
| 1254 |
+
"""
|
| 1255 |
+
.. deprecated:: 7.23
|
| 1256 |
+
|
| 1257 |
+
use `matplotlib_inline.backend_inline.set_matplotlib_close()`
|
| 1258 |
+
|
| 1259 |
+
Set whether the inline backend closes all figures automatically or not.
|
| 1260 |
+
|
| 1261 |
+
By default, the inline backend used in the IPython Notebook will close all
|
| 1262 |
+
matplotlib figures automatically after each cell is run. This means that
|
| 1263 |
+
plots in different cells won't interfere. Sometimes, you may want to make
|
| 1264 |
+
a plot in one cell and then refine it in later cells. This can be accomplished
|
| 1265 |
+
by::
|
| 1266 |
+
|
| 1267 |
+
In [1]: set_matplotlib_close(False)
|
| 1268 |
+
|
| 1269 |
+
To set this in your config files use the following::
|
| 1270 |
+
|
| 1271 |
+
c.InlineBackend.close_figures = False
|
| 1272 |
+
|
| 1273 |
+
Parameters
|
| 1274 |
+
----------
|
| 1275 |
+
close : bool
|
| 1276 |
+
Should all matplotlib figures be automatically closed after each cell is
|
| 1277 |
+
run?
|
| 1278 |
+
"""
|
| 1279 |
+
warnings.warn(
|
| 1280 |
+
"`set_matplotlib_close` is deprecated since IPython 7.23, directly "
|
| 1281 |
+
"use `matplotlib_inline.backend_inline.set_matplotlib_close()`",
|
| 1282 |
+
DeprecationWarning,
|
| 1283 |
+
stacklevel=2,
|
| 1284 |
+
)
|
| 1285 |
+
|
| 1286 |
+
from matplotlib_inline.backend_inline import (
|
| 1287 |
+
set_matplotlib_close as set_matplotlib_close_orig,
|
| 1288 |
+
)
|
| 1289 |
+
|
| 1290 |
+
set_matplotlib_close_orig(close)
|
.venv/lib/python3.9/site-packages/IPython/core/display_functions.py
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Top-level display functions for displaying object in different formats."""
|
| 3 |
+
|
| 4 |
+
# Copyright (c) IPython Development Team.
|
| 5 |
+
# Distributed under the terms of the Modified BSD License.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
from binascii import b2a_hex
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import warnings
|
| 12 |
+
|
| 13 |
+
__all__ = ['display', 'clear_output', 'publish_display_data', 'update_display', 'DisplayHandle']
|
| 14 |
+
|
| 15 |
+
#-----------------------------------------------------------------------------
|
| 16 |
+
# utility functions
|
| 17 |
+
#-----------------------------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _merge(d1, d2):
|
| 21 |
+
"""Like update, but merges sub-dicts instead of clobbering at the top level.
|
| 22 |
+
|
| 23 |
+
Updates d1 in-place
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
if not isinstance(d2, dict) or not isinstance(d1, dict):
|
| 27 |
+
return d2
|
| 28 |
+
for key, value in d2.items():
|
| 29 |
+
d1[key] = _merge(d1.get(key), value)
|
| 30 |
+
return d1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
#-----------------------------------------------------------------------------
|
| 34 |
+
# Main functions
|
| 35 |
+
#-----------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
class _Sentinel:
|
| 38 |
+
def __repr__(self):
|
| 39 |
+
return "<deprecated>"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
_sentinel = _Sentinel()
|
| 43 |
+
|
| 44 |
+
# use * to indicate transient is keyword-only
|
| 45 |
+
def publish_display_data(
|
| 46 |
+
data, metadata=None, source=_sentinel, *, transient=None, **kwargs
|
| 47 |
+
):
|
| 48 |
+
"""Publish data and metadata to all frontends.
|
| 49 |
+
|
| 50 |
+
See the ``display_data`` message in the messaging documentation for
|
| 51 |
+
more details about this message type.
|
| 52 |
+
|
| 53 |
+
Keys of data and metadata can be any mime-type.
|
| 54 |
+
|
| 55 |
+
Parameters
|
| 56 |
+
----------
|
| 57 |
+
data : dict
|
| 58 |
+
A dictionary having keys that are valid MIME types (like
|
| 59 |
+
'text/plain' or 'image/svg+xml') and values that are the data for
|
| 60 |
+
that MIME type. The data itself must be a JSON'able data
|
| 61 |
+
structure. Minimally all data should have the 'text/plain' data,
|
| 62 |
+
which can be displayed by all frontends. If more than the plain
|
| 63 |
+
text is given, it is up to the frontend to decide which
|
| 64 |
+
representation to use.
|
| 65 |
+
metadata : dict
|
| 66 |
+
A dictionary for metadata related to the data. This can contain
|
| 67 |
+
arbitrary key, value pairs that frontends can use to interpret
|
| 68 |
+
the data. mime-type keys matching those in data can be used
|
| 69 |
+
to specify metadata about particular representations.
|
| 70 |
+
source : str, deprecated
|
| 71 |
+
Unused.
|
| 72 |
+
transient : dict, keyword-only
|
| 73 |
+
A dictionary of transient data, such as display_id.
|
| 74 |
+
"""
|
| 75 |
+
from IPython.core.interactiveshell import InteractiveShell
|
| 76 |
+
|
| 77 |
+
if source is not _sentinel:
|
| 78 |
+
warnings.warn(
|
| 79 |
+
"The `source` parameter emit a deprecation warning since"
|
| 80 |
+
" IPython 8.0, it had no effects for a long time and will "
|
| 81 |
+
" be removed in future versions.",
|
| 82 |
+
DeprecationWarning,
|
| 83 |
+
stacklevel=2,
|
| 84 |
+
)
|
| 85 |
+
display_pub = InteractiveShell.instance().display_pub
|
| 86 |
+
|
| 87 |
+
# only pass transient if supplied,
|
| 88 |
+
# to avoid errors with older ipykernel.
|
| 89 |
+
# TODO: We could check for ipykernel version and provide a detailed upgrade message.
|
| 90 |
+
if transient:
|
| 91 |
+
kwargs['transient'] = transient
|
| 92 |
+
|
| 93 |
+
display_pub.publish(
|
| 94 |
+
data=data,
|
| 95 |
+
metadata=metadata,
|
| 96 |
+
**kwargs
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _new_id():
|
| 101 |
+
"""Generate a new random text id with urandom"""
|
| 102 |
+
return b2a_hex(os.urandom(16)).decode('ascii')
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def display(
|
| 106 |
+
*objs,
|
| 107 |
+
include=None,
|
| 108 |
+
exclude=None,
|
| 109 |
+
metadata=None,
|
| 110 |
+
transient=None,
|
| 111 |
+
display_id=None,
|
| 112 |
+
raw=False,
|
| 113 |
+
clear=False,
|
| 114 |
+
**kwargs
|
| 115 |
+
):
|
| 116 |
+
"""Display a Python object in all frontends.
|
| 117 |
+
|
| 118 |
+
By default all representations will be computed and sent to the frontends.
|
| 119 |
+
Frontends can decide which representation is used and how.
|
| 120 |
+
|
| 121 |
+
In terminal IPython this will be similar to using :func:`print`, for use in richer
|
| 122 |
+
frontends see Jupyter notebook examples with rich display logic.
|
| 123 |
+
|
| 124 |
+
Parameters
|
| 125 |
+
----------
|
| 126 |
+
*objs : object
|
| 127 |
+
The Python objects to display.
|
| 128 |
+
raw : bool, optional
|
| 129 |
+
Are the objects to be displayed already mimetype-keyed dicts of raw display data,
|
| 130 |
+
or Python objects that need to be formatted before display? [default: False]
|
| 131 |
+
include : list, tuple or set, optional
|
| 132 |
+
A list of format type strings (MIME types) to include in the
|
| 133 |
+
format data dict. If this is set *only* the format types included
|
| 134 |
+
in this list will be computed.
|
| 135 |
+
exclude : list, tuple or set, optional
|
| 136 |
+
A list of format type strings (MIME types) to exclude in the format
|
| 137 |
+
data dict. If this is set all format types will be computed,
|
| 138 |
+
except for those included in this argument.
|
| 139 |
+
metadata : dict, optional
|
| 140 |
+
A dictionary of metadata to associate with the output.
|
| 141 |
+
mime-type keys in this dictionary will be associated with the individual
|
| 142 |
+
representation formats, if they exist.
|
| 143 |
+
transient : dict, optional
|
| 144 |
+
A dictionary of transient data to associate with the output.
|
| 145 |
+
Data in this dict should not be persisted to files (e.g. notebooks).
|
| 146 |
+
display_id : str, bool optional
|
| 147 |
+
Set an id for the display.
|
| 148 |
+
This id can be used for updating this display area later via update_display.
|
| 149 |
+
If given as `True`, generate a new `display_id`
|
| 150 |
+
clear : bool, optional
|
| 151 |
+
Should the output area be cleared before displaying anything? If True,
|
| 152 |
+
this will wait for additional output before clearing. [default: False]
|
| 153 |
+
**kwargs : additional keyword-args, optional
|
| 154 |
+
Additional keyword-arguments are passed through to the display publisher.
|
| 155 |
+
|
| 156 |
+
Returns
|
| 157 |
+
-------
|
| 158 |
+
handle: DisplayHandle
|
| 159 |
+
Returns a handle on updatable displays for use with :func:`update_display`,
|
| 160 |
+
if `display_id` is given. Returns :any:`None` if no `display_id` is given
|
| 161 |
+
(default).
|
| 162 |
+
|
| 163 |
+
Examples
|
| 164 |
+
--------
|
| 165 |
+
>>> class Json(object):
|
| 166 |
+
... def __init__(self, json):
|
| 167 |
+
... self.json = json
|
| 168 |
+
... def _repr_pretty_(self, pp, cycle):
|
| 169 |
+
... import json
|
| 170 |
+
... pp.text(json.dumps(self.json, indent=2))
|
| 171 |
+
... def __repr__(self):
|
| 172 |
+
... return str(self.json)
|
| 173 |
+
...
|
| 174 |
+
|
| 175 |
+
>>> d = Json({1:2, 3: {4:5}})
|
| 176 |
+
|
| 177 |
+
>>> print(d)
|
| 178 |
+
{1: 2, 3: {4: 5}}
|
| 179 |
+
|
| 180 |
+
>>> display(d)
|
| 181 |
+
{
|
| 182 |
+
"1": 2,
|
| 183 |
+
"3": {
|
| 184 |
+
"4": 5
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
>>> def int_formatter(integer, pp, cycle):
|
| 189 |
+
... pp.text('I'*integer)
|
| 190 |
+
|
| 191 |
+
>>> plain = get_ipython().display_formatter.formatters['text/plain']
|
| 192 |
+
>>> plain.for_type(int, int_formatter)
|
| 193 |
+
<function _repr_pprint at 0x...>
|
| 194 |
+
>>> display(7-5)
|
| 195 |
+
II
|
| 196 |
+
|
| 197 |
+
>>> del plain.type_printers[int]
|
| 198 |
+
>>> display(7-5)
|
| 199 |
+
2
|
| 200 |
+
|
| 201 |
+
See Also
|
| 202 |
+
--------
|
| 203 |
+
:func:`update_display`
|
| 204 |
+
|
| 205 |
+
Notes
|
| 206 |
+
-----
|
| 207 |
+
In Python, objects can declare their textual representation using the
|
| 208 |
+
`__repr__` method. IPython expands on this idea and allows objects to declare
|
| 209 |
+
other, rich representations including:
|
| 210 |
+
|
| 211 |
+
- HTML
|
| 212 |
+
- JSON
|
| 213 |
+
- PNG
|
| 214 |
+
- JPEG
|
| 215 |
+
- SVG
|
| 216 |
+
- LaTeX
|
| 217 |
+
|
| 218 |
+
A single object can declare some or all of these representations; all are
|
| 219 |
+
handled by IPython's display system.
|
| 220 |
+
|
| 221 |
+
The main idea of the first approach is that you have to implement special
|
| 222 |
+
display methods when you define your class, one for each representation you
|
| 223 |
+
want to use. Here is a list of the names of the special methods and the
|
| 224 |
+
values they must return:
|
| 225 |
+
|
| 226 |
+
- `_repr_html_`: return raw HTML as a string, or a tuple (see below).
|
| 227 |
+
- `_repr_json_`: return a JSONable dict, or a tuple (see below).
|
| 228 |
+
- `_repr_jpeg_`: return raw JPEG data, or a tuple (see below).
|
| 229 |
+
- `_repr_png_`: return raw PNG data, or a tuple (see below).
|
| 230 |
+
- `_repr_svg_`: return raw SVG data as a string, or a tuple (see below).
|
| 231 |
+
- `_repr_latex_`: return LaTeX commands in a string surrounded by "$",
|
| 232 |
+
or a tuple (see below).
|
| 233 |
+
- `_repr_mimebundle_`: return a full mimebundle containing the mapping
|
| 234 |
+
from all mimetypes to data.
|
| 235 |
+
Use this for any mime-type not listed above.
|
| 236 |
+
|
| 237 |
+
The above functions may also return the object's metadata alonside the
|
| 238 |
+
data. If the metadata is available, the functions will return a tuple
|
| 239 |
+
containing the data and metadata, in that order. If there is no metadata
|
| 240 |
+
available, then the functions will return the data only.
|
| 241 |
+
|
| 242 |
+
When you are directly writing your own classes, you can adapt them for
|
| 243 |
+
display in IPython by following the above approach. But in practice, you
|
| 244 |
+
often need to work with existing classes that you can't easily modify.
|
| 245 |
+
|
| 246 |
+
You can refer to the documentation on integrating with the display system in
|
| 247 |
+
order to register custom formatters for already existing types
|
| 248 |
+
(:ref:`integrating_rich_display`).
|
| 249 |
+
|
| 250 |
+
.. versionadded:: 5.4 display available without import
|
| 251 |
+
.. versionadded:: 6.1 display available without import
|
| 252 |
+
|
| 253 |
+
Since IPython 5.4 and 6.1 :func:`display` is automatically made available to
|
| 254 |
+
the user without import. If you are using display in a document that might
|
| 255 |
+
be used in a pure python context or with older version of IPython, use the
|
| 256 |
+
following import at the top of your file::
|
| 257 |
+
|
| 258 |
+
from IPython.display import display
|
| 259 |
+
|
| 260 |
+
"""
|
| 261 |
+
from IPython.core.interactiveshell import InteractiveShell
|
| 262 |
+
|
| 263 |
+
if not InteractiveShell.initialized():
|
| 264 |
+
# Directly print objects.
|
| 265 |
+
print(*objs)
|
| 266 |
+
return
|
| 267 |
+
|
| 268 |
+
if transient is None:
|
| 269 |
+
transient = {}
|
| 270 |
+
if metadata is None:
|
| 271 |
+
metadata={}
|
| 272 |
+
if display_id:
|
| 273 |
+
if display_id is True:
|
| 274 |
+
display_id = _new_id()
|
| 275 |
+
transient['display_id'] = display_id
|
| 276 |
+
if kwargs.get('update') and 'display_id' not in transient:
|
| 277 |
+
raise TypeError('display_id required for update_display')
|
| 278 |
+
if transient:
|
| 279 |
+
kwargs['transient'] = transient
|
| 280 |
+
|
| 281 |
+
if not objs and display_id:
|
| 282 |
+
# if given no objects, but still a request for a display_id,
|
| 283 |
+
# we assume the user wants to insert an empty output that
|
| 284 |
+
# can be updated later
|
| 285 |
+
objs = [{}]
|
| 286 |
+
raw = True
|
| 287 |
+
|
| 288 |
+
if not raw:
|
| 289 |
+
format = InteractiveShell.instance().display_formatter.format
|
| 290 |
+
|
| 291 |
+
if clear:
|
| 292 |
+
clear_output(wait=True)
|
| 293 |
+
|
| 294 |
+
for obj in objs:
|
| 295 |
+
if raw:
|
| 296 |
+
publish_display_data(data=obj, metadata=metadata, **kwargs)
|
| 297 |
+
else:
|
| 298 |
+
format_dict, md_dict = format(obj, include=include, exclude=exclude)
|
| 299 |
+
if not format_dict:
|
| 300 |
+
# nothing to display (e.g. _ipython_display_ took over)
|
| 301 |
+
continue
|
| 302 |
+
if metadata:
|
| 303 |
+
# kwarg-specified metadata gets precedence
|
| 304 |
+
_merge(md_dict, metadata)
|
| 305 |
+
publish_display_data(data=format_dict, metadata=md_dict, **kwargs)
|
| 306 |
+
if display_id:
|
| 307 |
+
return DisplayHandle(display_id)
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
# use * for keyword-only display_id arg
|
| 311 |
+
def update_display(obj, *, display_id, **kwargs):
|
| 312 |
+
"""Update an existing display by id
|
| 313 |
+
|
| 314 |
+
Parameters
|
| 315 |
+
----------
|
| 316 |
+
obj
|
| 317 |
+
The object with which to update the display
|
| 318 |
+
display_id : keyword-only
|
| 319 |
+
The id of the display to update
|
| 320 |
+
|
| 321 |
+
See Also
|
| 322 |
+
--------
|
| 323 |
+
:func:`display`
|
| 324 |
+
"""
|
| 325 |
+
kwargs['update'] = True
|
| 326 |
+
display(obj, display_id=display_id, **kwargs)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class DisplayHandle(object):
|
| 330 |
+
"""A handle on an updatable display
|
| 331 |
+
|
| 332 |
+
Call `.update(obj)` to display a new object.
|
| 333 |
+
|
| 334 |
+
Call `.display(obj`) to add a new instance of this display,
|
| 335 |
+
and update existing instances.
|
| 336 |
+
|
| 337 |
+
See Also
|
| 338 |
+
--------
|
| 339 |
+
|
| 340 |
+
:func:`display`, :func:`update_display`
|
| 341 |
+
|
| 342 |
+
"""
|
| 343 |
+
|
| 344 |
+
def __init__(self, display_id=None):
|
| 345 |
+
if display_id is None:
|
| 346 |
+
display_id = _new_id()
|
| 347 |
+
self.display_id = display_id
|
| 348 |
+
|
| 349 |
+
def __repr__(self):
|
| 350 |
+
return "<%s display_id=%s>" % (self.__class__.__name__, self.display_id)
|
| 351 |
+
|
| 352 |
+
def display(self, obj, **kwargs):
|
| 353 |
+
"""Make a new display with my id, updating existing instances.
|
| 354 |
+
|
| 355 |
+
Parameters
|
| 356 |
+
----------
|
| 357 |
+
obj
|
| 358 |
+
object to display
|
| 359 |
+
**kwargs
|
| 360 |
+
additional keyword arguments passed to display
|
| 361 |
+
"""
|
| 362 |
+
display(obj, display_id=self.display_id, **kwargs)
|
| 363 |
+
|
| 364 |
+
def update(self, obj, **kwargs):
|
| 365 |
+
"""Update existing displays with my id
|
| 366 |
+
|
| 367 |
+
Parameters
|
| 368 |
+
----------
|
| 369 |
+
obj
|
| 370 |
+
object to display
|
| 371 |
+
**kwargs
|
| 372 |
+
additional keyword arguments passed to update_display
|
| 373 |
+
"""
|
| 374 |
+
update_display(obj, display_id=self.display_id, **kwargs)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def clear_output(wait=False):
|
| 378 |
+
"""Clear the output of the current cell receiving output.
|
| 379 |
+
|
| 380 |
+
Parameters
|
| 381 |
+
----------
|
| 382 |
+
wait : bool [default: false]
|
| 383 |
+
Wait to clear the output until new output is available to replace it."""
|
| 384 |
+
from IPython.core.interactiveshell import InteractiveShell
|
| 385 |
+
if InteractiveShell.initialized():
|
| 386 |
+
InteractiveShell.instance().display_pub.clear_output(wait)
|
| 387 |
+
else:
|
| 388 |
+
print('\033[2K\r', end='')
|
| 389 |
+
sys.stdout.flush()
|
| 390 |
+
print('\033[2K\r', end='')
|
| 391 |
+
sys.stderr.flush()
|