lazyscribe-yaml 0.1.0__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.
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: lazyscribe-yaml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: YAML-based artifact handler for Lazyscribe
|
|
5
|
+
Author: Akshay Gupta
|
|
6
|
+
Author-email: Akshay Gupta <akgcodes@gmail.com>
|
|
7
|
+
License: MIT license
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: attrs>=21.2,<=25.3
|
|
17
|
+
Requires-Dist: lazyscribe==2.0.0a0
|
|
18
|
+
Requires-Dist: pyyaml>=5.4,<=6.0.3
|
|
19
|
+
Requires-Dist: commitizen ; extra == 'build'
|
|
20
|
+
Requires-Dist: uv ; extra == 'build'
|
|
21
|
+
Requires-Dist: lazyscribe-yaml[build] ; extra == 'dev'
|
|
22
|
+
Requires-Dist: lazyscribe-yaml[qa] ; extra == 'dev'
|
|
23
|
+
Requires-Dist: lazyscribe-yaml[tests] ; extra == 'dev'
|
|
24
|
+
Requires-Dist: edgetest ; extra == 'qa'
|
|
25
|
+
Requires-Dist: mypy ; extra == 'qa'
|
|
26
|
+
Requires-Dist: pre-commit ; extra == 'qa'
|
|
27
|
+
Requires-Dist: pyproject-fmt ; extra == 'qa'
|
|
28
|
+
Requires-Dist: ruff ; extra == 'qa'
|
|
29
|
+
Requires-Dist: types-python-slugify ; extra == 'qa'
|
|
30
|
+
Requires-Dist: types-pyyaml ; extra == 'qa'
|
|
31
|
+
Requires-Dist: uv ; extra == 'qa'
|
|
32
|
+
Requires-Dist: pytest ; extra == 'tests'
|
|
33
|
+
Requires-Dist: pytest-cov ; extra == 'tests'
|
|
34
|
+
Requires-Dist: time-machine ; extra == 'tests'
|
|
35
|
+
Requires-Python: >=3.10.0
|
|
36
|
+
Project-URL: Documentation, https://github.com/lazyscribe/lazyscribe-yaml
|
|
37
|
+
Project-URL: Repository, https://github.com/lazyscribe/lazyscribe-yaml
|
|
38
|
+
Provides-Extra: build
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Provides-Extra: qa
|
|
41
|
+
Provides-Extra: tests
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
[](LICENSE) [](https://pypi.org/project/lazyscribe-yaml/) [](https://pypi.org/project/lazyscrib-yaml/) [](https://codecov.io/gh/lazyscribe/lazyscribe-yaml)
|
|
45
|
+
|
|
46
|
+
# YAML-based artifact handling for lazyscribe
|
|
47
|
+
|
|
48
|
+
`lazyscribe-yaml` is a lightweight package that adds the following artifact handlers for `lazyscribe`:
|
|
49
|
+
|
|
50
|
+
* `yaml`
|
|
51
|
+
|
|
52
|
+
# Installation
|
|
53
|
+
|
|
54
|
+
Python 3.10 or above is required. Use `pip` to install:
|
|
55
|
+
|
|
56
|
+
```console
|
|
57
|
+
$ python -m pip install lazyscribe-yaml
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
# Usage
|
|
61
|
+
|
|
62
|
+
To use this library, simply log an artifact to a `lazyscribe` experiment or repository with `handler="yaml"`.
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from lazyscribe import Project
|
|
66
|
+
|
|
67
|
+
project = Project("project.json", mode="w")
|
|
68
|
+
with project.log("My experiment") as exp:
|
|
69
|
+
exp.log_artifact(name="feature-names", value=["a", "b", "c"], handler="yaml")
|
|
70
|
+
|
|
71
|
+
project.save()
|
|
72
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[](LICENSE) [](https://pypi.org/project/lazyscribe-yaml/) [](https://pypi.org/project/lazyscrib-yaml/) [](https://codecov.io/gh/lazyscribe/lazyscribe-yaml)
|
|
2
|
+
|
|
3
|
+
# YAML-based artifact handling for lazyscribe
|
|
4
|
+
|
|
5
|
+
`lazyscribe-yaml` is a lightweight package that adds the following artifact handlers for `lazyscribe`:
|
|
6
|
+
|
|
7
|
+
* `yaml`
|
|
8
|
+
|
|
9
|
+
# Installation
|
|
10
|
+
|
|
11
|
+
Python 3.10 or above is required. Use `pip` to install:
|
|
12
|
+
|
|
13
|
+
```console
|
|
14
|
+
$ python -m pip install lazyscribe-yaml
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
# Usage
|
|
18
|
+
|
|
19
|
+
To use this library, simply log an artifact to a `lazyscribe` experiment or repository with `handler="yaml"`.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from lazyscribe import Project
|
|
23
|
+
|
|
24
|
+
project = Project("project.json", mode="w")
|
|
25
|
+
with project.log("My experiment") as exp:
|
|
26
|
+
exp.log_artifact(name="feature-names", value=["a", "b", "c"], handler="yaml")
|
|
27
|
+
|
|
28
|
+
project.save()
|
|
29
|
+
```
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""PyYAML-based handler for YAML-serializable artifacts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from io import IOBase
|
|
8
|
+
from typing import Any, ClassVar
|
|
9
|
+
|
|
10
|
+
import yaml
|
|
11
|
+
from lazyscribe._utils import utcnow
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from yaml import CSafeLoader as SafeLoader
|
|
15
|
+
except ImportError: # pragma: no cover
|
|
16
|
+
from yaml import SafeLoader # type: ignore[assignment]
|
|
17
|
+
|
|
18
|
+
from attrs import define
|
|
19
|
+
from lazyscribe.artifacts.base import Artifact
|
|
20
|
+
from slugify import slugify
|
|
21
|
+
|
|
22
|
+
__all__: list[str] = ["YAMLArtifact"]
|
|
23
|
+
|
|
24
|
+
LOG = logging.getLogger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@define(auto_attribs=True)
|
|
28
|
+
class YAMLArtifact(Artifact):
|
|
29
|
+
"""Handler for YAML-serializable objects.
|
|
30
|
+
|
|
31
|
+
.. important::
|
|
32
|
+
|
|
33
|
+
This class is not meant to be initialized directly. Please use the ``construct``
|
|
34
|
+
method.
|
|
35
|
+
|
|
36
|
+
.. note::
|
|
37
|
+
|
|
38
|
+
For the attributes documentation, see also "Attributes" of :py:class:`lazyscribe.artifacts.base.Artifact`.
|
|
39
|
+
|
|
40
|
+
Attributes
|
|
41
|
+
----------
|
|
42
|
+
alias : str = "yaml"
|
|
43
|
+
suffix : str = "yaml"
|
|
44
|
+
binary : bool = False
|
|
45
|
+
output_only : bool = False
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
alias: ClassVar[str] = "yaml"
|
|
49
|
+
suffix: ClassVar[str] = "yaml"
|
|
50
|
+
binary: ClassVar[bool] = False
|
|
51
|
+
output_only: ClassVar[bool] = False
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def construct(
|
|
55
|
+
cls,
|
|
56
|
+
name: str,
|
|
57
|
+
value: Any = None,
|
|
58
|
+
fname: str | None = None,
|
|
59
|
+
created_at: datetime | None = None,
|
|
60
|
+
writer_kwargs: dict[str, Any] | None = None,
|
|
61
|
+
version: int = 0,
|
|
62
|
+
dirty: bool = True,
|
|
63
|
+
**kwargs: Any,
|
|
64
|
+
) -> YAMLArtifact:
|
|
65
|
+
"""Construct the handler class.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
name : str
|
|
70
|
+
The name of the artifact.
|
|
71
|
+
value : Any, optional (default None)
|
|
72
|
+
The value for the artifact. The default value of ``None`` is used when
|
|
73
|
+
an experiment is loaded from the project JSON.
|
|
74
|
+
fname : str, optional (default None)
|
|
75
|
+
The filename for the artifact. If set to ``None`` or not provided, it will be derived from
|
|
76
|
+
the name of the artifact and the suffix for the class.
|
|
77
|
+
created_at : datetime.datetime, optional (default ``lazyscribe._utils.utcnow()``)
|
|
78
|
+
When the artifact was created.
|
|
79
|
+
writer_kwargs : dict[str, Any], optional (default {})
|
|
80
|
+
Keyword arguments for writing an artifact to the filesystem. Provided when an artifact
|
|
81
|
+
is logged to an experiment.
|
|
82
|
+
version : int, optional (default 0)
|
|
83
|
+
Integer version to be used for versioning artifacts.
|
|
84
|
+
|
|
85
|
+
Returns
|
|
86
|
+
-------
|
|
87
|
+
YAMLArtifact
|
|
88
|
+
The artifact.
|
|
89
|
+
"""
|
|
90
|
+
created_at = created_at or utcnow()
|
|
91
|
+
return cls( # type: ignore[call-arg]
|
|
92
|
+
name=name,
|
|
93
|
+
value=value,
|
|
94
|
+
fname=fname
|
|
95
|
+
or f"{slugify(name)}-{slugify(created_at.strftime('%Y%m%d%H%M%S'))}.{cls.suffix}",
|
|
96
|
+
created_at=created_at,
|
|
97
|
+
writer_kwargs=writer_kwargs or {},
|
|
98
|
+
version=version,
|
|
99
|
+
dirty=dirty,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def read(cls, buf: IOBase, **kwargs: Any) -> Any:
|
|
104
|
+
"""Read in the artifact.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
buf : file-like object
|
|
109
|
+
The buffer from a ``fsspec`` filesystem.
|
|
110
|
+
**kwargs
|
|
111
|
+
Keyword arguments for the read method.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
Any
|
|
116
|
+
The artifact object.
|
|
117
|
+
"""
|
|
118
|
+
if "Loader" not in kwargs:
|
|
119
|
+
LOG.debug("No loader provided, defaulting to SafeLoader")
|
|
120
|
+
kwargs["Loader"] = SafeLoader # default to safe loader
|
|
121
|
+
|
|
122
|
+
return yaml.load(buf, **kwargs)
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def write(cls, obj: Any, buf: IOBase, **kwargs: Any) -> None:
|
|
126
|
+
"""Write the content to a YAML file.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
obj : Any
|
|
131
|
+
The YAML-serializable object.
|
|
132
|
+
buf : file-like object
|
|
133
|
+
The buffer from a ``fsspec`` filesystem.
|
|
134
|
+
**kwargs
|
|
135
|
+
Keyword arguments for :py:meth:`yaml.dump`.
|
|
136
|
+
"""
|
|
137
|
+
yaml.dump(obj, buf, **kwargs)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "uv_build"
|
|
3
|
+
|
|
4
|
+
requires = [ "uv-build>=0.8,<0.9" ]
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "lazyscribe-yaml"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
description = "YAML-based artifact handler for Lazyscribe"
|
|
11
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
12
|
+
license = { text = "MIT license" }
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Akshay Gupta", email = "akgcodes@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.10.0"
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Natural Language :: English",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [ "attrs>=21.2,<=25.3", "lazyscribe==2.0.0a0", "pyyaml>=5.4,<=6.0.3" ]
|
|
28
|
+
|
|
29
|
+
optional-dependencies.build = [ "commitizen", "uv" ]
|
|
30
|
+
optional-dependencies.dev = [ "lazyscribe-yaml[build]", "lazyscribe-yaml[qa]", "lazyscribe-yaml[tests]" ]
|
|
31
|
+
optional-dependencies.qa = [
|
|
32
|
+
"edgetest",
|
|
33
|
+
"mypy",
|
|
34
|
+
"pre-commit",
|
|
35
|
+
"pyproject-fmt",
|
|
36
|
+
"ruff",
|
|
37
|
+
"types-python-slugify",
|
|
38
|
+
"types-pyyaml",
|
|
39
|
+
"uv",
|
|
40
|
+
]
|
|
41
|
+
optional-dependencies.tests = [ "pytest", "pytest-cov", "time-machine" ]
|
|
42
|
+
urls."Documentation" = "https://github.com/lazyscribe/lazyscribe-yaml"
|
|
43
|
+
urls."Repository" = "https://github.com/lazyscribe/lazyscribe-yaml"
|
|
44
|
+
entry-points."lazyscribe.artifact_type".yaml = "lazyscribe_yaml:YAMLArtifact"
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
target-version = "py310"
|
|
48
|
+
|
|
49
|
+
lint.select = [
|
|
50
|
+
"B", # flake8-bugbear
|
|
51
|
+
"C", # flake8-comprehensions
|
|
52
|
+
"D", # pydocstyle
|
|
53
|
+
"E", # pycodestyle errors
|
|
54
|
+
"F", # pyflakes
|
|
55
|
+
"I", # isort
|
|
56
|
+
"LOG", # flake8-logging
|
|
57
|
+
"RUF", # Ruff errors
|
|
58
|
+
"SIM", # flake8-simplify
|
|
59
|
+
"T20", # flake8-print
|
|
60
|
+
"TID252", # flake8-tidy-imports ban relative imports
|
|
61
|
+
"UP", # pyupgrade
|
|
62
|
+
"W", # pycodestyle warnings
|
|
63
|
+
]
|
|
64
|
+
lint.ignore = [
|
|
65
|
+
"C901", # Function/method is too complex. (Add back in later.)
|
|
66
|
+
"E501", # Line too long. Using formatter instead.
|
|
67
|
+
]
|
|
68
|
+
lint.per-file-ignores."**/{tests,docs}/*" = [ "ARG", "D", "E402", "F841" ]
|
|
69
|
+
lint.per-file-ignores."__init__.py" = [ "E402" ]
|
|
70
|
+
lint.per-file-ignores."tutorials/*" = [ "D", "T201" ]
|
|
71
|
+
lint.flake8-tidy-imports.ban-relative-imports = "all"
|
|
72
|
+
lint.pydocstyle.convention = "numpy"
|
|
73
|
+
lint.preview = true
|
|
74
|
+
|
|
75
|
+
[tool.mypy]
|
|
76
|
+
python_version = "3.10"
|
|
77
|
+
warn_return_any = true
|
|
78
|
+
warn_unused_configs = true
|
|
79
|
+
ignore_missing_imports = true
|
|
80
|
+
allow_redefinition = true
|
|
81
|
+
check_untyped_defs = true
|
|
82
|
+
|
|
83
|
+
[tool.uv.build-backend]
|
|
84
|
+
module-name = "lazyscribe_yaml"
|
|
85
|
+
module-root = ""
|
|
86
|
+
|
|
87
|
+
[tool.commitizen]
|
|
88
|
+
version_provider = "uv"
|
|
89
|
+
tag_format = "v$version"
|
|
90
|
+
update_changelog_on_bump = true
|
|
91
|
+
version_files = [
|
|
92
|
+
"lazyscribe_yaml/_meta.py:__version__",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[edgetest.envs.core]
|
|
96
|
+
extras = [ "tests" ]
|
|
97
|
+
upgrade = [ "attrs", "lazyscribe", "pyyaml", "python-slugify" ]
|
|
98
|
+
command = "pytest tests"
|