| 228 | |
| 229 | |
| 230 | def validate_basetemp(path: str) -> str: |
| 231 | # GH 7119 |
| 232 | msg = "basetemp must not be empty, the current working directory or any parent directory of it" |
| 233 | |
| 234 | # empty path |
| 235 | if not path: |
| 236 | raise argparse.ArgumentTypeError(msg) |
| 237 | |
| 238 | def is_ancestor(base: Path, query: Path) -> bool: |
| 239 | """Return whether query is an ancestor of base.""" |
| 240 | if base == query: |
| 241 | return True |
| 242 | return query in base.parents |
| 243 | |
| 244 | # check if path is an ancestor of cwd |
| 245 | if is_ancestor(Path.cwd(), Path(path).absolute()): |
| 246 | raise argparse.ArgumentTypeError(msg) |
| 247 | |
| 248 | # check symlinks for ancestors |
| 249 | if is_ancestor(Path.cwd().resolve(), Path(path).resolve()): |
| 250 | raise argparse.ArgumentTypeError(msg) |
| 251 | |
| 252 | return path |
| 253 | |
| 254 | |
| 255 | def wrap_session( |