|
1 | 1 | """ utility script to warm up/validate the jedi cache
|
2 | 2 | """
|
| 3 | +import os |
3 | 4 | import pathlib
|
4 | 5 | import shutil
|
5 | 6 | import sys
|
|
8 | 9 | import IPython
|
9 | 10 | import jedi
|
10 | 11 | import jupyterlab
|
| 12 | +import notebook |
| 13 | +import parso |
| 14 | +import pyls |
11 | 15 |
|
12 | 16 | SOURCE_TEMPLATE = """
|
13 | 17 | import {module}
|
14 | 18 | {module}."""
|
15 | 19 |
|
16 | 20 | MODULES_TO_CACHE = [
|
17 |
| - "sys", |
18 | 21 | "itertools",
|
19 |
| - "IPython", |
20 | 22 | "statistics",
|
21 |
| - "os", |
22 |
| - "time", |
23 | 23 | *sys.modules,
|
24 | 24 | ]
|
25 | 25 |
|
26 | 26 |
|
27 | 27 | def warm_up_one(module):
|
| 28 | + print(module, end="\t") |
28 | 29 | start = time.time()
|
29 | 30 | script = jedi.Script(SOURCE_TEMPLATE.format(module=module))
|
30 | 31 | completions = len(script.complete(3, len("{}.".format(module))))
|
31 | 32 | end = time.time()
|
32 |
| - print(module, completions, end - start) |
| 33 | + print("\t", completions, end - start) |
33 | 34 |
|
34 | 35 |
|
35 |
| -if __name__ == "__main__": |
36 |
| - jedi_cache = pathlib.Path(jedi.settings.cache_directory) |
| 36 | +def print_versions(): |
| 37 | + print(".".join(map(str, sys.version_info[:3])), "\t", "python") |
| 38 | + print(IPython.__version__, "\t", "ipython") |
| 39 | + print(jedi.__version__, "\t", "jedi") |
| 40 | + print(jupyterlab.__version__, "\t", "jupyterlab") |
| 41 | + print(notebook.__version__, "\t", "notebook") |
| 42 | + print(parso.__version__, "\t", "parso") |
| 43 | + print(pyls.__version__, "\t", "pyls") |
| 44 | + |
| 45 | + |
| 46 | +def print_env(): |
| 47 | + [ |
| 48 | + print(key, "\t", value) |
| 49 | + for key, value in sorted(os.environ.items()) |
| 50 | + if "CONDA" in key |
| 51 | + ] |
| 52 | + |
| 53 | + |
| 54 | +def setup_jedi(): |
| 55 | + print("default jedi environment", jedi.api.environment.get_default_environment()) |
| 56 | + jedi_cache = pathlib.Path( |
| 57 | + jedi.settings.cache_directory, environment=jedi.InterpreterEnvironment() |
| 58 | + ) |
37 | 59 | if jedi_cache.exists():
|
38 | 60 | shutil.rmtree(jedi_cache)
|
39 |
| - print(IPython.__version__) |
40 |
| - print(jupyterlab.__version__) |
| 61 | + print("removed jedi cache!") |
| 62 | + else: |
| 63 | + print("no jedi cache was found!") |
| 64 | + |
| 65 | + |
| 66 | +def warm_up(modules): |
| 67 | + print_env() |
| 68 | + print("-" * 80) |
| 69 | + print_versions() |
| 70 | + print("-" * 80) |
| 71 | + setup_jedi() |
| 72 | + print("-" * 80) |
41 | 73 | start = time.time()
|
42 |
| - modules = sorted(set(sys.argv[1:] or MODULES_TO_CACHE)) |
43 | 74 | [warm_up_one(module) for module in modules]
|
44 | 75 | end = time.time()
|
45 |
| - print("------------------") |
| 76 | + print("-" * 80) |
46 | 77 | print(len(modules), "modules in", jedi.settings.cache_directory, end - start)
|
| 78 | + |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + warm_up(sorted(set(sys.argv[1:] or MODULES_TO_CACHE))) |
0 commit comments