File: py_info.py

package info (click to toggle)
python-virtualenv 20.33.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,124 kB
  • sloc: python: 10,907; sh: 160; ansic: 61; csh: 47; makefile: 8
file content (21 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from __future__ import annotations

from pathlib import Path

from virtualenv.discovery.py_info import PythonInfo


def fixture_file(fixture_name):
    file_mask = f"*{fixture_name}.json"
    files = Path(__file__).parent.parent.rglob(file_mask)
    try:
        return next(files)
    except StopIteration as exc:
        # Fixture file was not found in the testing root and its subdirs.
        error = FileNotFoundError
        raise error(file_mask) from exc


def read_fixture(fixture_name):
    fixture_json = fixture_file(fixture_name).read_text(encoding="utf-8")
    return PythonInfo._from_json(fixture_json)  # noqa: SLF001