|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import ast |
| 4 | +import importlib.metadata |
4 | 5 | import os |
5 | 6 | import re |
6 | 7 | import shutil |
|
10 | 11 | from functools import lru_cache |
11 | 12 | from pathlib import Path |
12 | 13 | from tempfile import TemporaryDirectory |
| 14 | +from typing import TYPE_CHECKING |
13 | 15 |
|
14 | 16 | import tomlkit |
15 | 17 |
|
|
19 | 21 | ImportErrorPattern = re.compile(r"ModuleNotFoundError.*$", re.MULTILINE) |
20 | 22 |
|
21 | 23 |
|
| 24 | +if TYPE_CHECKING: |
| 25 | + from collections.abc import Generator |
| 26 | + |
| 27 | + |
22 | 28 | @contextmanager |
23 | | -def custom_addopts() -> None: |
| 29 | +def custom_addopts() -> Generator[None, None, None]: |
24 | 30 | pyproject_file = find_pyproject_toml() |
25 | 31 | original_content = None |
26 | 32 | non_blacklist_plugin_args = "" |
@@ -58,7 +64,7 @@ def custom_addopts() -> None: |
58 | 64 |
|
59 | 65 |
|
60 | 66 | @contextmanager |
61 | | -def add_addopts_to_pyproject() -> None: |
| 67 | +def add_addopts_to_pyproject() -> Generator[None, None, None]: |
62 | 68 | pyproject_file = find_pyproject_toml() |
63 | 69 | original_content = None |
64 | 70 | try: |
@@ -220,3 +226,32 @@ def exit_with_message(message: str, *, error_on_exit: bool = False) -> None: |
220 | 226 | paneled_text(message, panel_args={"style": "red"}) |
221 | 227 |
|
222 | 228 | sys.exit(1 if error_on_exit else 0) |
| 229 | + |
| 230 | + |
| 231 | +blacklist_installed_pkgs = { |
| 232 | + "codeflash", |
| 233 | + "pytest", |
| 234 | + "coverage", |
| 235 | + "__", # this is for private packages or ones that contain "__" in order to mangle names i.e 3204bda914b7f2c6f497__mypyc |
| 236 | + "setuptools", |
| 237 | + "pip", |
| 238 | + "wheel", |
| 239 | + "importlib_metadata", |
| 240 | + "importlib_resources", |
| 241 | + "isort", |
| 242 | + "black", |
| 243 | + "tomlkit", |
| 244 | + "stubs", |
| 245 | +} |
| 246 | + |
| 247 | + |
| 248 | +def get_installed_packages() -> set[str]: |
| 249 | + pkgs = importlib.metadata.packages_distributions().keys() |
| 250 | + return { |
| 251 | + pkg |
| 252 | + for pkg in pkgs |
| 253 | + if not any(blacklisted in pkg for blacklisted in blacklist_installed_pkgs) and not pkg.startswith("_") |
| 254 | + } |
| 255 | + |
| 256 | + |
| 257 | +print(get_installed_packages()) |
0 commit comments