Return the cache directory to write .pyc files for the given .py file path.
(file_path: Path)
| 1121 | |
| 1122 | |
| 1123 | def get_cache_dir(file_path: Path) -> Path: |
| 1124 | """Return the cache directory to write .pyc files for the given .py file path.""" |
| 1125 | if sys.version_info >= (3, 8) and sys.pycache_prefix: |
| 1126 | # given: |
| 1127 | # prefix = '/tmp/pycs' |
| 1128 | # path = '/home/user/proj/test_app.py' |
| 1129 | # we want: |
| 1130 | # '/tmp/pycs/home/user/proj' |
| 1131 | return Path(sys.pycache_prefix) / Path(*file_path.parts[1:-1]) |
| 1132 | else: |
| 1133 | # classic pycache directory |
| 1134 | return file_path.parent / "__pycache__" |
no outgoing calls