• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 20357994067

18 Dec 2025 10:01PM UTC coverage: 86.913% (-0.02%) from 86.929%
20357994067

push

github

web-flow
Fix CloudWatch model annotation (#13545)

1 of 1 new or added line in 1 file covered. (100.0%)

1391 existing lines in 33 files now uncovered.

70000 of 80540 relevant lines covered (86.91%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.08
/localstack-core/localstack/utils/venv.py
1
import io
2✔
2
import os
2✔
3
import sys
2✔
4
from functools import cached_property
2✔
5
from pathlib import Path
2✔
6
from typing import Union
2✔
7

8

9
class VirtualEnvironment:
2✔
10
    """
11
    Encapsulates methods to operate and navigate on a python virtual environment.
12
    """
13

14
    def __init__(self, venv_dir: Union[str, os.PathLike]):
2✔
15
        self._venv_dir = venv_dir
2✔
16

17
    def create(self) -> None:
2✔
18
        """
19
        Uses the virtualenv cli to create the virtual environment.
20
        :return:
21
        """
22
        self.venv_dir.mkdir(parents=True, exist_ok=True)
2✔
23
        from venv import main
2✔
24

25
        main([str(self.venv_dir)])
2✔
26

27
    @property
2✔
28
    def exists(self) -> bool:
2✔
29
        """
30
        Checks whether the virtual environment exists by checking whether the site-package directory of the venv exists.
31
        :return: the if the venv exists
32
        :raises NotADirectoryError: if the venv path exists but is not a directory
33
        """
34
        try:
2✔
35
            return True if self.site_dir else False
2✔
36
        except FileNotFoundError:
2✔
37
            return False
2✔
38

39
    @cached_property
2✔
40
    def venv_dir(self) -> Path:
2✔
41
        """
42
        Returns the path of the virtual environment directory
43
        :return: the path to the venv
44
        """
45
        return Path(self._venv_dir).absolute()
2✔
46

47
    @cached_property
2✔
48
    def site_dir(self) -> Path:
2✔
49
        """
50
        Resolves and returns the site-packages directory of the virtual environment. Once resolved successfully the
51
        result is cached.
52

53
        :return: the path to the site-packages dir.
54
        :raise FileNotFoundError: if the venv does not exist or the site-packages could not be found, or there are
55
         multiple lib/python* directories.
56
        :raise NotADirectoryError: if the venv is not a directory
57
        """
58
        venv = self.venv_dir
2✔
59

60
        if not venv.exists():
2✔
61
            raise FileNotFoundError(f"expected venv directory to exist at {venv}")
2✔
62

63
        if not venv.is_dir():
2✔
64
            raise NotADirectoryError(f"expected {venv} to be a directory")
×
65

66
        matches = list(venv.glob("lib/python*/site-packages"))
2✔
67

68
        if not matches:
2✔
69
            raise FileNotFoundError(f"could not find site-packages directory in {venv}")
×
70

71
        if len(matches) > 1:
2✔
72
            raise FileNotFoundError(f"multiple python versions found in {venv}: {matches}")
×
73

74
        return matches[0]
2✔
75

76
    def inject_to_sys_path(self) -> None:
2✔
77
        path = str(self.site_dir)
2✔
78
        if path and path not in sys.path:
2✔
79
            sys.path.append(path)
2✔
80

81
    def add_pth(self, name, path: Union[str, os.PathLike, "VirtualEnvironment"]) -> None:
2✔
82
        """
83
        Add a <name>.pth file into the virtual environment and append the given path to it. Does nothing if the path
84
        is already in the file.
85

86
        :param name: the name of the path file (without the .pth extensions)
87
        :param path: the path to be appended
88
        """
UNCOV
89
        pth_file = self.site_dir / f"{name}.pth"
×
90

UNCOV
91
        if isinstance(path, VirtualEnvironment):
×
UNCOV
92
            path = path.site_dir
×
93

UNCOV
94
        line = io.text_encoding(str(path)) + "\n"
×
95

UNCOV
96
        if pth_file.exists() and line in pth_file.read_text():
×
97
            return
×
98

UNCOV
99
        with open(pth_file, "a") as fd:
×
UNCOV
100
            fd.write(line)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc