( root: AbsPath, subdir: RelPath )
| 702 | * Read and parse a .python-version file if it exists in the given subdirectory. |
| 703 | */ |
| 704 | async function maybeLoadPythonRequest( |
| 705 | root: AbsPath, |
| 706 | subdir: RelPath |
| 707 | ): Promise<PythonVersionConfig | null> { |
| 708 | const dotPythonVersionRelPath: RelPath = path.join(subdir, '.python-version'); |
| 709 | const dotPythonVersionPath: AbsPath = path.join( |
| 710 | root, |
| 711 | dotPythonVersionRelPath |
| 712 | ); |
| 713 | const data: string | null = await readFileTextIfExists(dotPythonVersionPath); |
| 714 | |
| 715 | if (data == null) { |
| 716 | return null; |
| 717 | } |
| 718 | |
| 719 | const pyreq = parsePythonVersionFile(data); |
| 720 | if (pyreq == null) { |
| 721 | throw new PythonAnalysisError({ |
| 722 | message: `could not parse .python-version file: no valid Python version requests found`, |
| 723 | code: 'PYTHON_VERSION_FILE_PARSE_ERROR', |
| 724 | path: dotPythonVersionRelPath, |
| 725 | }); |
| 726 | } |
| 727 | |
| 728 | return { |
| 729 | kind: PythonConfigKind.PythonVersion, |
| 730 | path: dotPythonVersionRelPath, |
| 731 | data: pyreq, |
| 732 | specifier: data.trim(), |
| 733 | }; |
| 734 | } |
no test coverage detected