(filepath: Path)
| 11 | |
| 12 | @contextmanager |
| 13 | def subst_path_windows(filepath: Path): |
| 14 | for c in ascii_lowercase[7:]: # Create a subst drive from H-Z. |
| 15 | c += ":" |
| 16 | if not os.path.exists(c): |
| 17 | drive = c |
| 18 | break |
| 19 | else: |
| 20 | raise AssertionError("Unable to find suitable drive letter for subst.") |
| 21 | |
| 22 | directory = filepath.parent |
| 23 | basename = filepath.name |
| 24 | |
| 25 | args = ["subst", drive, str(directory)] |
| 26 | subprocess.check_call(args) |
| 27 | assert os.path.exists(drive) |
| 28 | try: |
| 29 | filename = Path(drive, os.sep, basename) |
| 30 | yield filename |
| 31 | finally: |
| 32 | args = ["subst", "/D", drive] |
| 33 | subprocess.check_call(args) |
| 34 | |
| 35 | |
| 36 | @contextmanager |
nothing calls this directly
no outgoing calls
no test coverage detected