package-utils 0.9.0__tar.gz → 0.9.2__tar.gz
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.
- {package_utils-0.9.0/src/package_utils.egg-info → package_utils-0.9.2}/PKG-INFO +5 -5
- {package_utils-0.9.0 → package_utils-0.9.2}/pyproject.toml +5 -5
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/context.py +6 -6
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/dataclasses/mixins.py +5 -9
- {package_utils-0.9.0 → package_utils-0.9.2/src/package_utils.egg-info}/PKG-INFO +5 -5
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils.egg-info/SOURCES.txt +0 -2
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils.egg-info/requires.txt +4 -4
- {package_utils-0.9.0 → package_utils-0.9.2}/tests/test_secrets.py +1 -3
- package_utils-0.9.0/src/package_utils/jobs/__init__.py +0 -1
- package_utils-0.9.0/src/package_utils/jobs/jobs.py +0 -41
- {package_utils-0.9.0 → package_utils-0.9.2}/LICENSE +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/README.md +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/setup.cfg +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/annotations.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/cli/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/cli/convertor.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/cli/declarations.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/cli/entry_point.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/cli/parser.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/entry_point.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/lazy_secrets.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/models/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/context/models/models.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/dataclasses/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/py.typed +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/secrets_.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/storage/__init__.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/storage/cached_file_content.py +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils.egg-info/dependency_links.txt +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils.egg-info/top_level.txt +0 -0
- {package_utils-0.9.0 → package_utils-0.9.2}/tests/test_annotations.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: package-utils
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
4
4
|
Summary: Common utilities for Python packages
|
|
5
5
|
Author-email: Quinten Roets <qdr2104@columbia.edu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -12,17 +12,17 @@ Requires-Dist: typer<1,>=0.27.1
|
|
|
12
12
|
Provides-Extra: context
|
|
13
13
|
Requires-Dist: dacite<2,>=1.8.1; extra == "context"
|
|
14
14
|
Requires-Dist: PyYaml<7,>=6.0.1; extra == "context"
|
|
15
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
15
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "context"
|
|
16
16
|
Provides-Extra: dataclasses
|
|
17
17
|
Requires-Dist: dacite<2,>=1.8.1; extra == "dataclasses"
|
|
18
18
|
Provides-Extra: storage
|
|
19
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
19
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "storage"
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
Requires-Dist: dacite<2,>=1.8.1; extra == "dev"
|
|
22
22
|
Requires-Dist: PyYaml<7,>=6.0.1; extra == "dev"
|
|
23
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
23
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "dev"
|
|
24
24
|
Requires-Dist: hypothesis<7,>=6.91.0; extra == "dev"
|
|
25
|
-
Requires-Dist: package-dev-tools<1,>=0.8.
|
|
25
|
+
Requires-Dist: package-dev-tools<1,>=0.8.7; extra == "dev"
|
|
26
26
|
Requires-Dist: package-dev-utils<1,>=0.1.6; extra == "dev"
|
|
27
27
|
Requires-Dist: typing-extensions<5,>=4.6.0; extra == "dev"
|
|
28
28
|
Dynamic: license-file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "package-utils"
|
|
3
|
-
version = "0.9.
|
|
3
|
+
version = "0.9.2"
|
|
4
4
|
description = "Common utilities for Python packages"
|
|
5
5
|
authors = [{name = "Quinten Roets", email = "qdr2104@columbia.edu"}]
|
|
6
6
|
license = "MIT"
|
|
@@ -14,22 +14,22 @@ dependencies = [
|
|
|
14
14
|
context = [
|
|
15
15
|
"dacite >=1.8.1, <2",
|
|
16
16
|
"PyYaml >=6.0.1, <7",
|
|
17
|
-
"superpathlib >=2.
|
|
17
|
+
"superpathlib >=2.1.0, <3",
|
|
18
18
|
]
|
|
19
19
|
dataclasses = [
|
|
20
20
|
"dacite >=1.8.1, <2",
|
|
21
21
|
]
|
|
22
22
|
storage = [
|
|
23
|
-
"superpathlib >=
|
|
23
|
+
"superpathlib >=2.1.0, <3",
|
|
24
24
|
]
|
|
25
25
|
dev = [
|
|
26
26
|
# context
|
|
27
27
|
"dacite >=1.8.1, <2",
|
|
28
28
|
"PyYaml >=6.0.1, <7",
|
|
29
|
-
"superpathlib >=2.
|
|
29
|
+
"superpathlib >=2.1.0, <3",
|
|
30
30
|
|
|
31
31
|
"hypothesis >=6.91.0, <7",
|
|
32
|
-
"package-dev-tools >=0.8.
|
|
32
|
+
"package-dev-tools >=0.8.7, <1",
|
|
33
33
|
"package-dev-utils >=0.1.6, <1",
|
|
34
34
|
"typing-extensions >=4.6.0, <5",
|
|
35
35
|
]
|
|
@@ -41,7 +41,8 @@ class Context(Generic[Options_, Config_, Secrets_]):
|
|
|
41
41
|
else:
|
|
42
42
|
optional_path = getattr(self.options, "config_path", None)
|
|
43
43
|
path = typing.cast("Path | None", optional_path)
|
|
44
|
-
|
|
44
|
+
content = None if path is None else path.cached_yaml
|
|
45
|
+
config = load_from_dict(model, content) if content else model()
|
|
45
46
|
return typing.cast("Config_", config)
|
|
46
47
|
|
|
47
48
|
@cached_property
|
|
@@ -57,10 +58,9 @@ class Context(Generic[Options_, Config_, Secrets_]):
|
|
|
57
58
|
)
|
|
58
59
|
|
|
59
60
|
|
|
60
|
-
def
|
|
61
|
+
def load_from_dict(model: type[T], content: dict[str, Any]) -> T:
|
|
61
62
|
import dacite # noqa: PLC0415
|
|
62
|
-
from superpathlib import Path # noqa: PLC0415
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return dacite.from_dict(model,
|
|
64
|
+
from package_utils.dataclasses.mixins import default_config # noqa: PLC0415
|
|
65
|
+
|
|
66
|
+
return dacite.from_dict(model, content, config=default_config)
|
|
@@ -2,25 +2,21 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import typing
|
|
4
4
|
from dataclasses import asdict
|
|
5
|
-
from
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Self
|
|
6
7
|
|
|
7
8
|
import dacite
|
|
9
|
+
from dacite import Config
|
|
8
10
|
|
|
9
11
|
if typing.TYPE_CHECKING:
|
|
10
12
|
from _typeshed import DataclassInstance # pragma: nocover
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
default_config = Config(strict=True, cast=[Path])
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class SerializationMixin:
|
|
16
18
|
@classmethod
|
|
17
|
-
def from_dict(
|
|
18
|
-
cls,
|
|
19
|
-
items: dict[str, Any],
|
|
20
|
-
config: dacite.Config | None = None,
|
|
21
|
-
) -> Self:
|
|
22
|
-
if config is None:
|
|
23
|
-
config = dacite.Config(strict=True)
|
|
19
|
+
def from_dict(cls, items: dict[str, Any], config: Config = default_config) -> Self:
|
|
24
20
|
return dacite.from_dict(cls, items, config=config)
|
|
25
21
|
|
|
26
22
|
def dict(self: DataclassInstance) -> dict[str, Any]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: package-utils
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
4
4
|
Summary: Common utilities for Python packages
|
|
5
5
|
Author-email: Quinten Roets <qdr2104@columbia.edu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -12,17 +12,17 @@ Requires-Dist: typer<1,>=0.27.1
|
|
|
12
12
|
Provides-Extra: context
|
|
13
13
|
Requires-Dist: dacite<2,>=1.8.1; extra == "context"
|
|
14
14
|
Requires-Dist: PyYaml<7,>=6.0.1; extra == "context"
|
|
15
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
15
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "context"
|
|
16
16
|
Provides-Extra: dataclasses
|
|
17
17
|
Requires-Dist: dacite<2,>=1.8.1; extra == "dataclasses"
|
|
18
18
|
Provides-Extra: storage
|
|
19
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
19
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "storage"
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
Requires-Dist: dacite<2,>=1.8.1; extra == "dev"
|
|
22
22
|
Requires-Dist: PyYaml<7,>=6.0.1; extra == "dev"
|
|
23
|
-
Requires-Dist: superpathlib<3,>=2.
|
|
23
|
+
Requires-Dist: superpathlib<3,>=2.1.0; extra == "dev"
|
|
24
24
|
Requires-Dist: hypothesis<7,>=6.91.0; extra == "dev"
|
|
25
|
-
Requires-Dist: package-dev-tools<1,>=0.8.
|
|
25
|
+
Requires-Dist: package-dev-tools<1,>=0.8.7; extra == "dev"
|
|
26
26
|
Requires-Dist: package-dev-utils<1,>=0.1.6; extra == "dev"
|
|
27
27
|
Requires-Dist: typing-extensions<5,>=4.6.0; extra == "dev"
|
|
28
28
|
Dynamic: license-file
|
|
@@ -23,8 +23,6 @@ src/package_utils/context/models/__init__.py
|
|
|
23
23
|
src/package_utils/context/models/models.py
|
|
24
24
|
src/package_utils/dataclasses/__init__.py
|
|
25
25
|
src/package_utils/dataclasses/mixins.py
|
|
26
|
-
src/package_utils/jobs/__init__.py
|
|
27
|
-
src/package_utils/jobs/jobs.py
|
|
28
26
|
src/package_utils/storage/__init__.py
|
|
29
27
|
src/package_utils/storage/cached_file_content.py
|
|
30
28
|
tests/test_annotations.py
|
|
@@ -3,7 +3,7 @@ typer<1,>=0.27.1
|
|
|
3
3
|
[context]
|
|
4
4
|
dacite<2,>=1.8.1
|
|
5
5
|
PyYaml<7,>=6.0.1
|
|
6
|
-
superpathlib<3,>=2.
|
|
6
|
+
superpathlib<3,>=2.1.0
|
|
7
7
|
|
|
8
8
|
[dataclasses]
|
|
9
9
|
dacite<2,>=1.8.1
|
|
@@ -11,11 +11,11 @@ dacite<2,>=1.8.1
|
|
|
11
11
|
[dev]
|
|
12
12
|
dacite<2,>=1.8.1
|
|
13
13
|
PyYaml<7,>=6.0.1
|
|
14
|
-
superpathlib<3,>=2.
|
|
14
|
+
superpathlib<3,>=2.1.0
|
|
15
15
|
hypothesis<7,>=6.91.0
|
|
16
|
-
package-dev-tools<1,>=0.8.
|
|
16
|
+
package-dev-tools<1,>=0.8.7
|
|
17
17
|
package-dev-utils<1,>=0.1.6
|
|
18
18
|
typing-extensions<5,>=4.6.0
|
|
19
19
|
|
|
20
20
|
[storage]
|
|
21
|
-
superpathlib<3,>=2.
|
|
21
|
+
superpathlib<3,>=2.1.0
|
|
@@ -5,9 +5,7 @@ import pytest
|
|
|
5
5
|
from tests.utils import forbid_imports
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
10
|
-
) -> None:
|
|
8
|
+
def test_loading_without_subprocess(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
11
9
|
name = "package_utils.secrets_"
|
|
12
10
|
forbid_imports(monkeypatch, "shlex", "subprocess", from_module=name)
|
|
13
11
|
monkeypatch.setenv("MY_SECRET", "value")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .jobs import run_jobs
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
from collections.abc import Callable, Iterable, Iterator
|
|
2
|
-
from concurrent.futures import Future, ProcessPoolExecutor, ThreadPoolExecutor
|
|
3
|
-
from queue import Queue
|
|
4
|
-
from threading import Semaphore, Thread
|
|
5
|
-
from typing import TypeVar
|
|
6
|
-
|
|
7
|
-
T = TypeVar("T")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def run_jobs(
|
|
11
|
-
jobs: Iterable[Callable[..., T]],
|
|
12
|
-
number_of_workers: int = 0,
|
|
13
|
-
*,
|
|
14
|
-
use_multiprocessing: bool = False,
|
|
15
|
-
) -> Iterator[T]:
|
|
16
|
-
if number_of_workers <= 0:
|
|
17
|
-
return (job() for job in jobs)
|
|
18
|
-
executor_class = ProcessPoolExecutor if use_multiprocessing else ThreadPoolExecutor
|
|
19
|
-
executor = executor_class(max_workers=number_of_workers)
|
|
20
|
-
futures: Queue[Future[T] | None] = Queue()
|
|
21
|
-
submission_semaphore = Semaphore(number_of_workers * 2)
|
|
22
|
-
# large enough to keep all workers busy
|
|
23
|
-
|
|
24
|
-
def launch_jobs() -> None:
|
|
25
|
-
with executor:
|
|
26
|
-
for job in jobs:
|
|
27
|
-
submission_semaphore.acquire()
|
|
28
|
-
future = executor.submit(job)
|
|
29
|
-
future.add_done_callback(futures.put)
|
|
30
|
-
future.add_done_callback(lambda _: submission_semaphore.release())
|
|
31
|
-
futures.put(None)
|
|
32
|
-
|
|
33
|
-
Thread(target=launch_jobs).start()
|
|
34
|
-
return extract_results(futures)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def extract_results(futures: Queue[Future[T] | None]) -> Iterator[T]:
|
|
38
|
-
future = futures.get()
|
|
39
|
-
while future is not None:
|
|
40
|
-
yield future.result()
|
|
41
|
-
future = futures.get()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{package_utils-0.9.0 → package_utils-0.9.2}/src/package_utils/storage/cached_file_content.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|