|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 |
| -import logging |
4 |
| -import os |
5 |
| -import sys |
6 |
| - |
7 |
| - |
8 |
| -if sys.platform == "win32": |
9 |
| - config_for_pytensor_cache_script = "cxx=,device=cpu" |
10 |
| - pytensor_flags = os.environ["PYTENSOR_FLAGS"] if "PYTENSOR_FLAGS" in os.environ else "" |
11 |
| - if pytensor_flags: |
12 |
| - pytensor_flags += "," |
13 |
| - pytensor_flags += config_for_pytensor_cache_script |
14 |
| - os.environ["PYTENSOR_FLAGS"] = pytensor_flags |
15 |
| - |
16 |
| -import pytensor |
17 |
| -import pytensor.compile.compiledir |
18 |
| -from pytensor import config |
19 |
| -from pytensor.link.c.basic import get_module_cache |
20 |
| - |
21 |
| - |
22 |
| -_logger = logging.getLogger("pytensor.bin.pytensor-cache") |
23 |
| - |
24 |
| - |
25 |
| -def print_help(exit_status): |
26 |
| - if exit_status: |
27 |
| - print(f"command \"{' '.join(sys.argv)}\" not recognized") |
28 |
| - print('Type "pytensor-cache" to print the cache location') |
29 |
| - print('Type "pytensor-cache help" to print this help') |
30 |
| - print('Type "pytensor-cache clear" to erase the cache') |
31 |
| - print('Type "pytensor-cache list" to print the cache content') |
32 |
| - print('Type "pytensor-cache unlock" to unlock the cache directory') |
33 |
| - print( |
34 |
| - 'Type "pytensor-cache cleanup" to delete keys in the old ' "format/code version" |
35 |
| - ) |
36 |
| - print('Type "pytensor-cache purge" to force deletion of the cache directory') |
37 |
| - print( |
38 |
| - 'Type "pytensor-cache basecompiledir" ' |
39 |
| - "to print the parent of the cache directory" |
40 |
| - ) |
41 |
| - print( |
42 |
| - 'Type "pytensor-cache basecompiledir list" ' |
43 |
| - "to print the content of the base compile dir" |
44 |
| - ) |
45 |
| - print( |
46 |
| - 'Type "pytensor-cache basecompiledir purge" ' |
47 |
| - "to remove everything in the base compile dir, " |
48 |
| - "that is, erase ALL cache directories" |
49 |
| - ) |
50 |
| - sys.exit(exit_status) |
51 |
| - |
52 |
| - |
53 |
| -def main(): |
54 |
| - if len(sys.argv) == 1: |
55 |
| - print(config.compiledir) |
56 |
| - elif len(sys.argv) == 2: |
57 |
| - if sys.argv[1] == "help": |
58 |
| - print_help(exit_status=0) |
59 |
| - if sys.argv[1] == "clear": |
60 |
| - # We skip the refresh on module cache creation because the refresh will |
61 |
| - # be done when calling clear afterwards. |
62 |
| - cache = get_module_cache(init_args=dict(do_refresh=False)) |
63 |
| - cache.clear( |
64 |
| - unversioned_min_age=-1, clear_base_files=True, delete_if_problem=True |
65 |
| - ) |
66 |
| - |
67 |
| - # Print a warning if some cached modules were not removed, so that the |
68 |
| - # user knows he should manually delete them, or call |
69 |
| - # pytensor-cache purge, # to properly clear the cache. |
70 |
| - items = [ |
71 |
| - item |
72 |
| - for item in sorted(os.listdir(cache.dirname)) |
73 |
| - if item.startswith("tmp") |
74 |
| - ] |
75 |
| - if items: |
76 |
| - _logger.warning( |
77 |
| - "There remain elements in the cache dir that you may " |
78 |
| - "need to erase manually. The cache dir is:\n %s\n" |
79 |
| - 'You can also call "pytensor-cache purge" to ' |
80 |
| - "remove everything from that directory." % config.compiledir |
81 |
| - ) |
82 |
| - _logger.debug(f"Remaining elements ({len(items)}): {', '.join(items)}") |
83 |
| - elif sys.argv[1] == "list": |
84 |
| - pytensor.compile.compiledir.print_compiledir_content() |
85 |
| - elif sys.argv[1] == "cleanup": |
86 |
| - pytensor.compile.compiledir.cleanup() |
87 |
| - cache = get_module_cache(init_args=dict(do_refresh=False)) |
88 |
| - cache.clear_old() |
89 |
| - elif sys.argv[1] == "unlock": |
90 |
| - pytensor.compile.compilelock.force_unlock(config.compiledir) |
91 |
| - print("Lock successfully removed!") |
92 |
| - elif sys.argv[1] == "purge": |
93 |
| - pytensor.compile.compiledir.compiledir_purge() |
94 |
| - elif sys.argv[1] == "basecompiledir": |
95 |
| - # Simply print the base_compiledir |
96 |
| - print(pytensor.config.base_compiledir) |
97 |
| - else: |
98 |
| - print_help(exit_status=1) |
99 |
| - elif len(sys.argv) == 3 and sys.argv[1] == "basecompiledir": |
100 |
| - if sys.argv[2] == "list": |
101 |
| - pytensor.compile.compiledir.basecompiledir_ls() |
102 |
| - elif sys.argv[2] == "purge": |
103 |
| - pytensor.compile.compiledir.basecompiledir_purge() |
104 |
| - else: |
105 |
| - print_help(exit_status=1) |
106 |
| - else: |
107 |
| - print_help(exit_status=1) |
| 3 | +import warnings |
108 | 4 |
|
| 5 | +from pytensor.bin.pytensor_cache import * |
| 6 | +from pytensor.bin.pytensor_cache import _logger |
109 | 7 |
|
110 | 8 | if __name__ == "__main__":
|
| 9 | + warnings.warn( |
| 10 | + message= "Running 'pytensor_cache.py' is deprecated. Use the pytensor-cache " |
| 11 | + "script instead.", |
| 12 | + category=DeprecationWarning, |
| 13 | + ) |
111 | 14 | main()
|
0 commit comments