samplekit 0.1.1__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: samplekit
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Lightweight Python framework for documenting scientific samples with bidirectional Markdown I/O
5
5
  Author-email: zelyph <github@zelyph.fr>
6
6
  License: MIT
@@ -119,8 +119,8 @@ from samplekit import Sample, Property, Table, Column, report
119
119
 
120
120
 
121
121
  class Experiment(Sample):
122
- def __init__(self, name=None, filepath=None):
123
- super().__init__(name, filepath)
122
+ def __init__(self, path=None, name=None):
123
+ super().__init__(path, name)
124
124
 
125
125
  self.temperature = Property(
126
126
  value=25.0, uncertainty=0.5,
@@ -341,17 +341,18 @@ Column(
341
341
  ### `Sample`
342
342
 
343
343
  ```python
344
- Sample(name=None, filepath=None)
344
+ Sample(path=None, name=None)
345
345
  ```
346
346
 
347
347
  Subclass it and declare Properties and Tables in `__init__`. Assignment auto-registers them and wires names, symbols, and dependencies.
348
348
 
349
349
  | Member | Description |
350
350
  |---|---|
351
+ | `.path` | `Path` — file path (set at construction or after save). |
351
352
  | `.props` | `dict[str, Property]` — all registered properties. |
352
353
  | `.tables` | `dict[str, Table]` — all registered tables. |
353
- | `.save(filepath, style="math")` | Write YAML frontmatter + template body to `.md`. |
354
- | `.load(filepath)` | classmethod — load from `.md` file. |
354
+ | `.save(path, style="math")` | Write YAML frontmatter + template body to `.md`. |
355
+ | `.load(path)` | classmethod — load from `.md` file. |
355
356
  | `.template(style="math")` | Override for custom Markdown body. |
356
357
  | `.to_dict()` | Export all data as a plain dict. |
357
358
  | `.to_dataframe()` | Export scalar properties as a single-row DataFrame. |
@@ -94,8 +94,8 @@ from samplekit import Sample, Property, Table, Column, report
94
94
 
95
95
 
96
96
  class Experiment(Sample):
97
- def __init__(self, name=None, filepath=None):
98
- super().__init__(name, filepath)
97
+ def __init__(self, path=None, name=None):
98
+ super().__init__(path, name)
99
99
 
100
100
  self.temperature = Property(
101
101
  value=25.0, uncertainty=0.5,
@@ -316,17 +316,18 @@ Column(
316
316
  ### `Sample`
317
317
 
318
318
  ```python
319
- Sample(name=None, filepath=None)
319
+ Sample(path=None, name=None)
320
320
  ```
321
321
 
322
322
  Subclass it and declare Properties and Tables in `__init__`. Assignment auto-registers them and wires names, symbols, and dependencies.
323
323
 
324
324
  | Member | Description |
325
325
  |---|---|
326
+ | `.path` | `Path` — file path (set at construction or after save). |
326
327
  | `.props` | `dict[str, Property]` — all registered properties. |
327
328
  | `.tables` | `dict[str, Table]` — all registered tables. |
328
- | `.save(filepath, style="math")` | Write YAML frontmatter + template body to `.md`. |
329
- | `.load(filepath)` | classmethod — load from `.md` file. |
329
+ | `.save(path, style="math")` | Write YAML frontmatter + template body to `.md`. |
330
+ | `.load(path)` | classmethod — load from `.md` file. |
330
331
  | `.template(style="math")` | Override for custom Markdown body. |
331
332
  | `.to_dict()` | Export all data as a plain dict. |
332
333
  | `.to_dataframe()` | Export scalar properties as a single-row DataFrame. |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "samplekit"
3
- version = "0.1.1"
3
+ version = "0.2.0"
4
4
  description = "Lightweight Python framework for documenting scientific samples with bidirectional Markdown I/O"
5
5
  authors = [{ name = "zelyph", email = "github@zelyph.fr" }]
6
6
  readme = "README.md"
@@ -7,7 +7,7 @@ from .sample_list import SampleList
7
7
  from . import report
8
8
  from . import converters
9
9
 
10
- __version__ = "0.1.1"
10
+ __version__ = "0.2.0"
11
11
 
12
12
  __all__ = [
13
13
  "Property",
@@ -67,40 +67,52 @@ class Sample:
67
67
  """
68
68
  Named container of Properties and Tables.
69
69
 
70
- Subclass and define properties in __init__. Properties and Tables
71
- are auto-registered when assigned as instance attributes.
70
+ Parameters
71
+ ----------
72
+ path : str or Path, optional
73
+ Path to a Markdown file. If the file exists, properties and
74
+ tables are loaded automatically. The name defaults to the
75
+ file stem when not provided.
76
+ name : str, optional
77
+ Display name. If omitted, inferred from *path* or set to
78
+ ``"Unnamed"``.
72
79
 
73
80
  Examples
74
81
  --------
82
+ Load from file:
83
+
84
+ >>> sample = Sample("data/my_sample.md")
85
+ >>> sample.name
86
+ 'my_sample'
87
+
88
+ Define a subclass with fixed properties:
89
+
75
90
  >>> class MySample(Sample):
76
- ... def __init__(self, name=None, filepath=None):
77
- ... super().__init__(name, filepath)
91
+ ... def __init__(self, path=None, name=None):
92
+ ... super().__init__(path, name)
78
93
  ... self.temperature = Property(value=25.0, unit="°C", symbol_math="T")
79
- ... self.pressure = Property(value=101.3, unit="kPa", symbol_math="P")
80
94
  ...
81
- ... def template(self, style="math"):
82
- ... from .report import properties_table
83
- ... return properties_table(self, ["temperature", "pressure"], style=style)
84
- >>>
85
- >>> sample = MySample("EXP_001")
86
- >>> sample.save("sample.md")
95
+ >>> s = MySample(name="EXP_001")
96
+ >>> s.save("sample.md")
87
97
  >>> loaded = MySample.load("sample.md")
88
98
  """
89
99
 
90
- def __init__(self, name: str | None = None, filepath: str | Path | None = None):
100
+ def __init__(self, path: str | Path | None = None, name: str | None = None):
91
101
  # Use object.__setattr__ to bypass our custom __setattr__
92
102
  object.__setattr__(self, '_props', {})
93
103
  object.__setattr__(self, '_tables', {})
94
104
  object.__setattr__(self, '_order', [])
95
- fp = Path(filepath) if filepath else None
96
- object.__setattr__(self, '_filepath', fp)
105
+ fp = Path(path) if path else None
106
+ object.__setattr__(self, 'path', fp)
97
107
  n = name if name is not None else (fp.stem if fp else "Unnamed")
98
108
  object.__setattr__(self, 'name', n)
99
109
  object.__setattr__(self, '_hydrating', False)
110
+ if type(self) is Sample:
111
+ self._auto_hydrate()
100
112
 
101
113
  def _auto_hydrate(self):
102
- """Load data from filepath if the file exists."""
103
- fp = object.__getattribute__(self, '_filepath')
114
+ """Load data from path if the file exists."""
115
+ fp = object.__getattribute__(self, 'path')
104
116
  if fp is not None and fp.exists():
105
117
  object.__setattr__(self, '_hydrating', True)
106
118
  try:
@@ -123,7 +135,7 @@ class Sample:
123
135
 
124
136
  def __setattr__(self, name: str, value):
125
137
  object.__setattr__(self, name, value)
126
- if name.startswith('_') or name == 'name':
138
+ if name.startswith('_') or name in ('name', 'path'):
127
139
  return
128
140
  if isinstance(value, Property):
129
141
  props = object.__getattribute__(self, '_props')
@@ -237,19 +249,19 @@ class Sample:
237
249
  object.__setattr__(self, 'name', name)
238
250
  self._hydrate_from_yaml(yaml_data)
239
251
 
240
- def save(self, filepath: str | Path | None = None, style: str = "math") -> Path:
252
+ def save(self, path: str | Path | None = None, style: str = "math") -> Path:
241
253
  """Save to markdown file with YAML frontmatter.
242
254
 
243
255
  Parameters
244
256
  ----------
245
- filepath : path, optional
246
- Defaults to the filepath used at construction.
257
+ path : path, optional
258
+ Defaults to the path used at construction.
247
259
  style : "math" or "text"
248
260
  Controls math rendering in the body.
249
261
  """
250
- fp = Path(filepath) if filepath else self._filepath
262
+ fp = Path(path) if path else self.path
251
263
  if fp is None:
252
- raise ValueError("No filepath specified")
264
+ raise ValueError("No path specified")
253
265
 
254
266
  yaml_data = self._build_yaml_data()
255
267
  yaml_str = yaml.dump(
@@ -268,20 +280,20 @@ class Sample:
268
280
 
269
281
  fp.parent.mkdir(parents=True, exist_ok=True)
270
282
  fp.write_text(content, encoding="utf-8")
271
- self._filepath = fp
283
+ self.path = fp
272
284
  return fp
273
285
 
274
286
  @classmethod
275
- def load(cls, filepath: str | Path) -> Sample:
287
+ def load(cls, path: str | Path) -> Sample:
276
288
  """Load from a markdown file with YAML frontmatter.
277
289
 
278
290
  Creates an instance of *cls* (calling its __init__ to define
279
291
  properties), then hydrates from the YAML data via _auto_hydrate.
280
292
  """
281
- fp = Path(filepath)
293
+ fp = Path(path)
282
294
  # _auto_hydrate (called by __init_subclass__ wrapper) will read
283
295
  # the file and hydrate since fp exists on disk.
284
- return cls(filepath=fp)
296
+ return cls(path=fp)
285
297
 
286
298
  # ── Converters (delegated to samplekit.converters) ──
287
299
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: samplekit
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Lightweight Python framework for documenting scientific samples with bidirectional Markdown I/O
5
5
  Author-email: zelyph <github@zelyph.fr>
6
6
  License: MIT
@@ -119,8 +119,8 @@ from samplekit import Sample, Property, Table, Column, report
119
119
 
120
120
 
121
121
  class Experiment(Sample):
122
- def __init__(self, name=None, filepath=None):
123
- super().__init__(name, filepath)
122
+ def __init__(self, path=None, name=None):
123
+ super().__init__(path, name)
124
124
 
125
125
  self.temperature = Property(
126
126
  value=25.0, uncertainty=0.5,
@@ -341,17 +341,18 @@ Column(
341
341
  ### `Sample`
342
342
 
343
343
  ```python
344
- Sample(name=None, filepath=None)
344
+ Sample(path=None, name=None)
345
345
  ```
346
346
 
347
347
  Subclass it and declare Properties and Tables in `__init__`. Assignment auto-registers them and wires names, symbols, and dependencies.
348
348
 
349
349
  | Member | Description |
350
350
  |---|---|
351
+ | `.path` | `Path` — file path (set at construction or after save). |
351
352
  | `.props` | `dict[str, Property]` — all registered properties. |
352
353
  | `.tables` | `dict[str, Table]` — all registered tables. |
353
- | `.save(filepath, style="math")` | Write YAML frontmatter + template body to `.md`. |
354
- | `.load(filepath)` | classmethod — load from `.md` file. |
354
+ | `.save(path, style="math")` | Write YAML frontmatter + template body to `.md`. |
355
+ | `.load(path)` | classmethod — load from `.md` file. |
355
356
  | `.template(style="math")` | Override for custom Markdown body. |
356
357
  | `.to_dict()` | Export all data as a plain dict. |
357
358
  | `.to_dataframe()` | Export scalar properties as a single-row DataFrame. |
File without changes
File without changes
File without changes
File without changes