fm-weck 1.4.8__py3-none-any.whl → 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ # This file is part of fm-weck: executing fm-tools in containerized environments.
2
+ # https://gitlab.com/sosy-lab/software/fm-weck
3
+ #
4
+ # SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
5
+ #
6
+ # SPDX-License-Identifier: Apache-2.0
7
+
8
+ import logging
9
+ from threading import Lock
10
+
11
+ from .request_handling import RunHandler
12
+
13
+ RUNS_IN_PROGRESS = {}
14
+ EXCEPTIONS = {}
15
+ LOCK = Lock()
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ def add_run(run_handler: RunHandler) -> str:
20
+ with LOCK:
21
+ RUNS_IN_PROGRESS[run_handler.run_id] = run_handler
22
+
23
+ return run_handler.run_id
24
+
25
+
26
+ def remove_run(run_id: str) -> None:
27
+ with LOCK:
28
+ RUNS_IN_PROGRESS.pop(run_id, None)
29
+
30
+
31
+ def get_run(run_id: str) -> RunHandler:
32
+ with LOCK:
33
+ return RUNS_IN_PROGRESS.get(run_id)
34
+
35
+
36
+ def active_runs() -> frozenset:
37
+ with LOCK:
38
+ return frozenset(RUNS_IN_PROGRESS.keys())
@@ -0,0 +1,27 @@
1
+ # This file is part of fm-weck: executing fm-tools in containerized environments.
2
+ # https://gitlab.com/sosy-lab/software/fm-weck
3
+ #
4
+ # SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
5
+ #
6
+ # SPDX-License-Identifier: Apache-2.0
7
+
8
+ import logging
9
+ import tempfile
10
+ from pathlib import Path
11
+
12
+ TMP_DIR = Path(tempfile.gettempdir()) / "fm_weck"
13
+ TMP_DIR.mkdir(parents=True, exist_ok=True)
14
+ logger = logging.getLogger(__name__)
15
+ logger.setLevel(logging.INFO)
16
+
17
+
18
+ def read_file(file_path: Path) -> bytes:
19
+ """
20
+ Returns the content of a file as bytes.
21
+
22
+ :param file_path: The path to the file.
23
+ :return: The content of the file as bytes.
24
+ """
25
+
26
+ with open(file_path, "rb") as file:
27
+ return file.read()
fm_weck/image_mgr.py CHANGED
@@ -26,6 +26,8 @@ if TYPE_CHECKING:
26
26
 
27
27
  CONTAINERFILE = Path(__file__).parent / "resources" / "Containerfile"
28
28
 
29
+ logger = logging.getLogger(__name__)
30
+
29
31
 
30
32
  class ImageMgr(object):
31
33
  """
@@ -49,7 +51,7 @@ class ImageMgr(object):
49
51
  if not image.base_images:
50
52
  raise NoImageError("No base image specified")
51
53
 
52
- logging.info(
54
+ logger.info(
53
55
  "Building image from from base image %s with packages %s", image.base_images[0], image.required_packages
54
56
  )
55
57
  image_cmd = engine.image_from(CONTAINERFILE)
@@ -8,6 +8,5 @@
8
8
 
9
9
  ARG BASE_IMAGE
10
10
  FROM ${BASE_IMAGE}
11
- RUN apt-get update
12
11
  ARG REQUIRED_PACKAGES
13
- RUN apt-get install -y ${REQUIRED_PACKAGES} && rm -rf /var/lib/apt/lists/*
12
+ RUN apt-get update && apt-get install -y ${REQUIRED_PACKAGES} && rm -rf /var/lib/apt/lists/*
@@ -6,6 +6,7 @@
6
6
  # SPDX-License-Identifier: Apache-2.0
7
7
 
8
8
  import importlib.resources as pkg_resources
9
+ from functools import cache
9
10
  from pathlib import Path
10
11
 
11
12
  from . import fm_tools, properties
@@ -19,16 +20,33 @@ RUNEXEC_SCRIPT = "runexec"
19
20
 
20
21
 
21
22
  def iter_fm_data():
22
- for fm_data in pkg_resources.contents(fm_tools):
23
- with pkg_resources.path(fm_tools, fm_data) as fake_context_path:
24
- fm_data_path = Path(fake_context_path)
25
- if fm_data_path.is_file() and (fm_data_path.name.endswith(".yml") or fm_data_path.name.endswith(".yaml")):
26
- yield fm_data_path
23
+ for entry in pkg_resources.files(fm_tools).iterdir():
24
+ if entry.name.endswith((".yml", ".yaml")):
25
+ with pkg_resources.as_file(entry) as path:
26
+ fm_data_path = Path(path)
27
+ if fm_data_path.is_file():
28
+ yield fm_data_path
27
29
 
28
30
 
29
31
  def iter_properties():
30
- for prop in pkg_resources.contents(properties):
31
- with pkg_resources.path(properties, prop) as fake_context_path:
32
- prop_path = Path(fake_context_path)
32
+ for entry in pkg_resources.files(properties).iterdir():
33
+ with pkg_resources.as_file(entry) as path:
34
+ prop_path = Path(path)
33
35
  if prop_path.is_file():
34
36
  yield prop_path
37
+
38
+
39
+ @cache
40
+ def fm_tools_choice_map():
41
+ ignore = {
42
+ "schema.yml",
43
+ }
44
+
45
+ actors = {actor_def.stem: actor_def for actor_def in iter_fm_data() if (actor_def.name not in ignore)}
46
+
47
+ return actors
48
+
49
+
50
+ @cache
51
+ def property_choice_map():
52
+ return {spec_path.stem: spec_path for spec_path in iter_properties() if spec_path.suffix != ".license"}