pipelime-python 1.9.1__py3-none-any.whl → 2.1.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.
Files changed (52) hide show
  1. pipelime/__init__.py +1 -1
  2. pipelime/choixe/ast/nodes.py +3 -3
  3. pipelime/choixe/visitors/decoder.py +1 -1
  4. pipelime/cli/main.py +42 -3
  5. pipelime/cli/pretty_print.py +10 -10
  6. pipelime/cli/tui/tui.css +1 -1
  7. pipelime/cli/tui/tui.py +22 -18
  8. pipelime/cli/tui/utils.py +2 -2
  9. pipelime/cli/utils.py +7 -7
  10. pipelime/commands/__init__.py +13 -15
  11. pipelime/commands/general.py +26 -142
  12. pipelime/commands/interfaces.py +159 -106
  13. pipelime/commands/piper.py +10 -2
  14. pipelime/commands/resume.py +1 -1
  15. pipelime/commands/shell.py +1 -1
  16. pipelime/commands/split_ops.py +36 -36
  17. pipelime/commands/tempman.py +11 -7
  18. pipelime/commands/toy_dataset.py +1 -1
  19. pipelime/items/base.py +25 -138
  20. pipelime/piper/checkpoint.py +2 -2
  21. pipelime/piper/model.py +9 -8
  22. pipelime/piper/progress/model.py +1 -1
  23. pipelime/sequences/grabber.py +61 -7
  24. pipelime/sequences/pipes/base.py +3 -2
  25. pipelime/sequences/pipes/mapping.py +2 -1
  26. pipelime/sequences/pipes/operations.py +5 -4
  27. pipelime/sequences/pipes/validation.py +3 -3
  28. pipelime/sequences/pipes/writers.py +2 -2
  29. pipelime/sequences/samples_sequence.py +22 -6
  30. pipelime/sequences/sources/from_callable.py +1 -1
  31. pipelime/sequences/sources/raw.py +1 -1
  32. pipelime/sequences/sources/readers.py +53 -2
  33. pipelime/sequences/sources/toy_dataset.py +7 -6
  34. pipelime/sequences/utils.py +7 -7
  35. pipelime/stages/__init__.py +13 -10
  36. pipelime/stages/augmentations.py +2 -2
  37. pipelime/stages/base.py +1 -1
  38. pipelime/stages/entities.py +9 -8
  39. pipelime/stages/item_info.py +2 -2
  40. pipelime/stages/item_replacement.py +3 -3
  41. pipelime/stages/item_sources.py +3 -24
  42. pipelime/stages/key_transformations.py +1 -1
  43. pipelime/utils/pydantic_types.py +10 -7
  44. {pipelime_python-1.9.1.dist-info → pipelime_python-2.1.0.dist-info}/METADATA +10 -10
  45. {pipelime_python-1.9.1.dist-info → pipelime_python-2.1.0.dist-info}/RECORD +48 -52
  46. {pipelime_python-1.9.1.dist-info → pipelime_python-2.1.0.dist-info}/WHEEL +1 -1
  47. pipelime/remotes/__init__.py +0 -5
  48. pipelime/remotes/base.py +0 -415
  49. pipelime/remotes/s3_remote.py +0 -184
  50. pipelime/remotes/shared_folder_remote.py +0 -144
  51. {pipelime_python-1.9.1.dist-info → pipelime_python-2.1.0.dist-info}/entry_points.txt +0 -0
  52. {pipelime_python-1.9.1.dist-info → pipelime_python-2.1.0.dist-info}/licenses/LICENSE +0 -0
pipelime/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  __author__ = "Eyecan.ai"
4
4
  __email__ = "info@eyecan.ai"
5
- __version__ = "1.9.1"
5
+ __version__ = "2.1.0"
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
+ from dataclasses import field
4
5
  from typing import Any, Dict, Optional, Sequence, Tuple, Union
5
6
 
6
- # from dataclasses import dataclass
7
- from pydantic.dataclasses import dataclass
7
+ from pydantic.v1.dataclasses import dataclass
8
8
 
9
9
 
10
10
  class NodeVisitor: # pragma: no cover
@@ -336,7 +336,7 @@ class RandNode(Node):
336
336
 
337
337
  args: Sequence[HashNode] = tuple()
338
338
  n: Optional[Node] = None
339
- pdf: Optional[Node] = None
339
+ pdf: Optional[Node] = field(default=None, compare=False)
340
340
 
341
341
  def __init__(self, *args: HashNode, **data) -> None:
342
342
  super().__init__()
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
  from typing import Any
4
4
 
5
5
  import numpy as np
6
- from pydantic import BaseModel
6
+ from pydantic.v1 import BaseModel
7
7
 
8
8
  from pipelime.choixe.ast.nodes import LiteralNode, Node
9
9
  from pipelime.choixe.visitors.unparser import Unparser
pipelime/cli/main.py CHANGED
@@ -6,7 +6,7 @@ import typing as t
6
6
  from pathlib import Path
7
7
 
8
8
  import typer
9
- from pydantic import BaseModel
9
+ from pydantic.v1 import BaseModel
10
10
 
11
11
  from pipelime.choixe import XConfig
12
12
  from pipelime.choixe.visitors.processor_ui import ProcessorUi
@@ -35,6 +35,7 @@ class PlCliOptions(BaseModel):
35
35
  output_ctx: t.Optional[Path]
36
36
  command_outputs: t.Optional[Path]
37
37
  verbose: int
38
+ data_cache: t.Optional[str]
38
39
  dry_run: bool
39
40
  no_ui: bool
40
41
  command: str
@@ -80,6 +81,33 @@ def _set_logger_level(verbose: int):
80
81
  os.environ["LOGURU_LEVEL"] = level
81
82
 
82
83
 
84
+ def _set_item_data_cache(data_cache: t.Optional[str]):
85
+ from loguru import logger
86
+
87
+ from pipelime.items import enable_item_data_cache
88
+ from pipelime.utils.pydantic_types import ItemType
89
+
90
+ item_list = (data_cache or "").replace(" ", "").split(",")
91
+ item_list = [i for i in item_list if i]
92
+
93
+ if not item_list:
94
+ return
95
+
96
+ if "*" in item_list:
97
+ logger.debug("Enabling data cache for all items.")
98
+ enable_item_data_cache()
99
+ else:
100
+ item_cls_list = []
101
+ for name in item_list:
102
+ try:
103
+ item_cls_list.append(ItemType.create(name).value)
104
+ except Exception:
105
+ logger.error(f"Item `{name}` not found.")
106
+ logger.debug(f"Enabling data cache for items: {item_cls_list}")
107
+ if item_cls_list:
108
+ enable_item_data_cache(*item_cls_list)
109
+
110
+
83
111
  def _complete_yaml(incomplete: str): # pragma: no cover
84
112
  for v in Path(".").glob(f"{incomplete}*.yaml"):
85
113
  yield str(v)
@@ -422,6 +450,13 @@ def pl_main(
422
450
  resolve_path=True,
423
451
  help="The checkpoint folder. If it already exists, it must be empty.",
424
452
  ),
453
+ data_cache: t.Optional[str] = typer.Option(
454
+ None,
455
+ help=(
456
+ "Comma-separated list of pipelime items for which to enable data cache. "
457
+ "Use the special `*` value to enable data cache for any item."
458
+ ),
459
+ ),
425
460
  verbose: int = typer.Option(
426
461
  0,
427
462
  "--verbose",
@@ -574,6 +609,7 @@ def pl_main(
574
609
  output_ctx=output_ctx,
575
610
  command_outputs=command_outputs,
576
611
  verbose=verbose,
612
+ data_cache=data_cache,
577
613
  dry_run=dry_run,
578
614
  no_ui=no_ui,
579
615
  command=command,
@@ -618,6 +654,7 @@ def run_with_checkpoint(
618
654
  from pipelime.choixe import XConfig
619
655
  from pipelime.cli.pretty_print import print_error, print_info, print_warning
620
656
 
657
+ _set_item_data_cache(cli_opts.data_cache)
621
658
  PipelimeSymbolsHelper.set_extra_modules(cli_opts.extra_modules)
622
659
 
623
660
  if cli_opts.pipelime_tmp:
@@ -805,7 +842,9 @@ def run_with_checkpoint(
805
842
 
806
843
  cfg_size = len(effective_configs)
807
844
  pls = "s" if cfg_size != 1 else ""
808
- print_info(f"🎉 Configuration successfully processed ({cfg_size} variant{pls}).")
845
+ print_info(
846
+ f"🎉 Configuration successfully processed ({cfg_size} variant{pls})."
847
+ )
809
848
 
810
849
  if cli_opts.verbose > 2:
811
850
  print_info("\nFinal effective configurations:")
@@ -879,7 +918,7 @@ def run_command(
879
918
 
880
919
  import time
881
920
 
882
- from pydantic.error_wrappers import ValidationError
921
+ from pydantic.v1.error_wrappers import ValidationError
883
922
 
884
923
  from pipelime.choixe.utils.io import PipelimeTmp, dump
885
924
  from pipelime.cli.pretty_print import print_command_outputs, print_info
@@ -1,14 +1,13 @@
1
1
  import inspect
2
2
  import typing as t
3
3
 
4
- from pydantic import BaseModel
5
- from rich import box
6
- from rich.markup import escape
7
- from rich import get_console
4
+ from pydantic.v1 import BaseModel
5
+ from rich import box, get_console
8
6
  from rich import print as rprint
9
- from rich.pretty import Pretty
10
- from rich.table import Table, Column
7
+ from rich.markup import escape
11
8
  from rich.panel import Panel
9
+ from rich.pretty import Pretty
10
+ from rich.table import Column, Table
12
11
 
13
12
  if t.TYPE_CHECKING:
14
13
  from pipelime.cli.utils import ActionInfo
@@ -421,12 +420,13 @@ def _is_model(type_):
421
420
 
422
421
  def _human_readable_type(field_outer_type):
423
422
  from enum import Enum
424
- from pydantic.typing import (
425
- typing_base, # noqa: F401 # type: ignore
423
+
424
+ from pydantic.v1.typing import (
426
425
  WithArgsTypes,
427
- is_union,
428
- get_origin,
429
426
  get_args,
427
+ get_origin,
428
+ is_union,
429
+ typing_base, # noqa: F401 # type: ignore
430
430
  )
431
431
 
432
432
  v = field_outer_type
pipelime/cli/tui/tui.css CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
 
21
21
  .description {
22
- height: 0;
22
+ height: auto;
23
23
  opacity: 0.5;
24
24
  }
25
25
 
pipelime/cli/tui/tui.py CHANGED
@@ -30,18 +30,16 @@ class Constants:
30
30
  SUB_FIELD_MARGIN = (0, 0, 0, 4)
31
31
  TUI_KEY_CONFIRM = Keys.ControlN
32
32
  TUI_KEY_SAVE = Keys.ControlS
33
- TUI_KEY_ABORT = Keys.ControlC
33
+ TUI_KEY_ABORT = Keys.ControlT
34
34
  TUI_KEY_TOGGLE_DESCRIPTIONS = Keys.ControlJ
35
35
  SAVE_KEY_CONFIRM = Keys.ControlS
36
36
  SAVE_KEY_CANCEL = Keys.Escape
37
- SAVE_KEY_ABORT = Keys.ControlC
38
37
 
39
38
 
40
39
  class SaveScreen(ModalScreen):
41
40
  BINDINGS = [
42
41
  (Constants.SAVE_KEY_CONFIRM, "confirm", "Confirm"),
43
42
  (Constants.SAVE_KEY_CANCEL, "cancel", "Cancel"),
44
- (Constants.SAVE_KEY_ABORT, "ctrl_c", "Abort"),
45
43
  ]
46
44
  HELP = "CTRL+S to confirm, ESC to cancel"
47
45
 
@@ -55,11 +53,14 @@ class SaveScreen(ModalScreen):
55
53
  self.config = config
56
54
 
57
55
  def compose(self) -> ComposeResult:
56
+ """Compose the save screen."""
57
+ error_label = Label("", classes="error-label")
58
+ error_label.display = False
58
59
  yield Container(
59
60
  Label("Save path", classes="field-label"),
60
61
  Input(""),
61
- Label(SaveScreen.HELP),
62
- Label("", classes="error-label"),
62
+ Label(str(SaveScreen.HELP)),
63
+ error_label,
63
64
  id="dialog",
64
65
  )
65
66
 
@@ -85,17 +86,16 @@ class SaveScreen(ModalScreen):
85
86
  except Exception as e:
86
87
  error_label = self.query_one(".error-label")
87
88
  error_label = cast(Label, error_label)
88
- error_label.styles.height = "auto"
89
- error_label.update(str(e))
89
+ error_label.display = True
90
+ error = str(e)
91
+ # escape the square brackets to avoid rich syntax
92
+ error = error.replace("[", r"\[") # noqa: W605
93
+ error_label.update(error)
90
94
 
91
95
  def action_cancel(self) -> None:
92
96
  """Cancel the save."""
93
97
  self.app.pop_screen()
94
98
 
95
- def action_ctrl_c(self) -> None:
96
- """Propagate the KeyboardInterrupt exception."""
97
- raise KeyboardInterrupt
98
-
99
99
 
100
100
  class TuiApp(App[Mapping]):
101
101
  """A Textual app to handle Pipelime configurations."""
@@ -104,7 +104,7 @@ class TuiApp(App[Mapping]):
104
104
  BINDINGS = [
105
105
  (Constants.TUI_KEY_CONFIRM, "confirm", "Confirm"),
106
106
  (Constants.TUI_KEY_SAVE, "save", "Save to file"),
107
- (Constants.TUI_KEY_ABORT, "ctrl_c", "Abort"),
107
+ (Constants.TUI_KEY_ABORT, "abort", "Abort"),
108
108
  (
109
109
  Constants.TUI_KEY_TOGGLE_DESCRIPTIONS,
110
110
  "toggle_descriptions",
@@ -165,7 +165,9 @@ class TuiApp(App[Mapping]):
165
165
  labels.append(Label(title, classes="title-label"))
166
166
  if description:
167
167
  description = TuiApp.preprocess_string(description)
168
- labels.append(Label(description, classes="title-label description"))
168
+ label = Label(description, classes="title-label description")
169
+ label.display = True if self.show_descriptions else False
170
+ labels.append(label)
169
171
  return labels
170
172
 
171
173
  def create_simple_field(self, field: TuiField) -> List[Widget]:
@@ -186,7 +188,9 @@ class TuiApp(App[Mapping]):
186
188
  description = field.description
187
189
  descr = f"({field.type_}) {description}" if description else f"({field.type_})"
188
190
  description = TuiApp.preprocess_string(descr)
189
- widgets.append(Label(description, classes="description"))
191
+ label = Label(description, classes="description")
192
+ label.display = True if self.show_descriptions else False
193
+ widgets.append(label)
190
194
 
191
195
  inp = Input(value=field.value, placeholder=field.hint)
192
196
  widgets.append(inp)
@@ -275,8 +279,8 @@ class TuiApp(App[Mapping]):
275
279
  save_screen = SaveScreen(self.collect_cmd_args())
276
280
  self.push_screen(save_screen)
277
281
 
278
- def action_ctrl_c(self) -> None:
279
- """Propagate the KeyboardInterrupt exception."""
282
+ def action_abort(self) -> None:
283
+ """Raise KeyboardInterrupt exception."""
280
284
  raise KeyboardInterrupt
281
285
 
282
286
  def action_toggle_descriptions(self) -> None:
@@ -284,7 +288,7 @@ class TuiApp(App[Mapping]):
284
288
  self.show_descriptions = not self.show_descriptions
285
289
  query = self.query(".description")
286
290
  for widget in query:
287
- widget.styles.height = "auto" if self.show_descriptions else 0
291
+ widget.display = True if self.show_descriptions else False
288
292
 
289
293
  query = self.query(Input)
290
294
  for widget in query:
@@ -315,7 +319,7 @@ class TuiApp(App[Mapping]):
315
319
  replace_whitespace=False,
316
320
  tabsize=4,
317
321
  )
318
- sub = sub.replace("[", "\[") # noqa: W605
322
+ sub = sub.replace("[", r"\[") # noqa: W605
319
323
  preprocessed += sub + "\n"
320
324
 
321
325
  preprocessed = preprocessed[:-1]
pipelime/cli/tui/utils.py CHANGED
@@ -1,8 +1,8 @@
1
1
  from enum import Enum
2
2
  from typing import List, Mapping, Tuple, Type, cast
3
3
 
4
- from pydantic import BaseModel
5
- from pydantic.fields import ModelField
4
+ from pydantic.v1 import BaseModel
5
+ from pydantic.v1.fields import ModelField
6
6
 
7
7
  from pipelime.cli.utils import PipelimeSymbolsHelper
8
8
  from pipelime.piper import PipelimeCommand
pipelime/cli/utils.py CHANGED
@@ -1,24 +1,24 @@
1
1
  import json
2
+ import os
3
+ import shutil
2
4
  import typing as t
3
5
  from ast import literal_eval
4
6
  from json import JSONDecodeError
5
7
  from pathlib import Path
6
8
  from types import ModuleType
7
- import shutil
8
9
 
9
10
  import yaml
10
11
  from loguru import logger
11
- from pydantic import BaseModel, ValidationError
12
+ from pydantic.v1 import BaseModel, ValidationError
12
13
  from rich import get_console
13
14
  from rich.prompt import Prompt
14
15
  from yaml.error import YAMLError
15
- import os
16
16
 
17
17
  if t.TYPE_CHECKING:
18
18
  from pipelime.piper import T_DAG_NODE, PipelimeCommand
19
19
  from pipelime.piper.checkpoint import CheckpointNamespace
20
- from pipelime.stages import SampleStage
21
20
  from pipelime.sequences import SamplesSequence
21
+ from pipelime.stages import SampleStage
22
22
 
23
23
 
24
24
  class ActionInfo(BaseModel):
@@ -108,7 +108,7 @@ class PipelimeSymbolsHelper:
108
108
 
109
109
  @classmethod
110
110
  def _symbol_name(cls, symbol):
111
- from pydantic import BaseModel
111
+ from pydantic.v1 import BaseModel
112
112
 
113
113
  return (
114
114
  symbol.__config__.title
@@ -175,9 +175,9 @@ class PipelimeSymbolsHelper:
175
175
  def import_everything(cls):
176
176
  import pipelime.choixe.utils.imports as pl_imports
177
177
  import pipelime.sequences as pl_seq
178
+ from pipelime.commands.piper import DagBaseCommand
178
179
  from pipelime.piper import PipelimeCommand
179
180
  from pipelime.stages import SampleStage
180
- from pipelime.commands.piper import DagBaseCommand
181
181
 
182
182
  if not cls.is_cache_valid():
183
183
  for module_name in cls.std_modules + cls.extra_modules:
@@ -631,7 +631,7 @@ def pl_print(
631
631
  """
632
632
  import inspect
633
633
 
634
- from pydantic import BaseModel
634
+ from pydantic.v1 import BaseModel
635
635
  from rich import print as rprint
636
636
 
637
637
  from pipelime.cli.pretty_print import print_model_info
@@ -1,29 +1,27 @@
1
1
  from pipelime.commands.general import (
2
- TimeItCommand,
3
- StageTimingCommand,
4
- PipeCommand,
5
2
  CloneCommand,
6
3
  ConcatCommand,
7
- ZipCommand,
8
- AddRemoteCommand,
9
- RemoveRemoteCommand,
10
- ValidateCommand,
4
+ CopySharedItemsCommand,
5
+ FilterCommand,
6
+ FilterDuplicatesCommand,
11
7
  MapCommand,
12
8
  MapIfCommand,
13
- SortCommand,
14
- FilterCommand,
15
- SliceCommand,
9
+ PipeCommand,
16
10
  SetMetadataCommand,
17
- FilterDuplicatesCommand,
18
- CopySharedItemsCommand,
11
+ SliceCommand,
12
+ SortCommand,
13
+ StageTimingCommand,
14
+ TimeItCommand,
15
+ ValidateCommand,
16
+ ZipCommand,
19
17
  )
18
+ from pipelime.commands.piper import DrawCommand, RunCommand, WatchCommand
19
+ from pipelime.commands.resume import ResumeCommand
20
20
  from pipelime.commands.shell import ShellCommand
21
21
  from pipelime.commands.split_ops import (
22
22
  SplitByQueryCommand,
23
23
  SplitByValueCommand,
24
24
  SplitCommand,
25
25
  )
26
- from pipelime.commands.toy_dataset import ToyDatasetCommand
27
- from pipelime.commands.piper import RunCommand, DrawCommand, WatchCommand
28
26
  from pipelime.commands.tempman import TempCommand
29
- from pipelime.commands.resume import ResumeCommand
27
+ from pipelime.commands.toy_dataset import ToyDatasetCommand
@@ -1,6 +1,6 @@
1
1
  import typing as t
2
2
 
3
- import pydantic as pyd
3
+ import pydantic.v1 as pyd
4
4
 
5
5
  import pipelime.commands.interfaces as pl_interfaces
6
6
  import pipelime.utils.pydantic_types as pl_types
@@ -37,22 +37,22 @@ class OutputStageTime(pyd.BaseModel):
37
37
  class TimeItCommand(PipelimeCommand, title="timeit"):
38
38
  """Measures the average time to get a sample from a sequence."""
39
39
 
40
- input: t.Optional[
41
- pl_interfaces.InputDatasetInterface
42
- ] = pl_interfaces.InputDatasetInterface.pyd_field(
43
- alias="i",
44
- is_required=False,
45
- description=(
46
- "The input dataset. If None, the first operation "
47
- "must be a sequence generator."
48
- ),
49
- piper_port=PiperPortType.INPUT,
40
+ input: t.Optional[pl_interfaces.InputDatasetInterface] = (
41
+ pl_interfaces.InputDatasetInterface.pyd_field(
42
+ alias="i",
43
+ is_required=False,
44
+ description=(
45
+ "The input dataset. If None, the first operation "
46
+ "must be a sequence generator."
47
+ ),
48
+ piper_port=PiperPortType.INPUT,
49
+ )
50
50
  )
51
51
 
52
- output: t.Optional[
53
- pl_interfaces.OutputDatasetInterface
54
- ] = pl_interfaces.OutputDatasetInterface.pyd_field(
55
- alias="o", is_required=False, piper_port=PiperPortType.OUTPUT
52
+ output: t.Optional[pl_interfaces.OutputDatasetInterface] = (
53
+ pl_interfaces.OutputDatasetInterface.pyd_field(
54
+ alias="o", is_required=False, piper_port=PiperPortType.OUTPUT
55
+ )
56
56
  )
57
57
 
58
58
  operations: t.Optional[pl_types.YamlInput] = pyd.Field(
@@ -287,16 +287,16 @@ class PipeCommand(PipelimeCommand, title="pipe"):
287
287
  ),
288
288
  )
289
289
 
290
- input: t.Optional[
291
- pl_interfaces.InputDatasetInterface
292
- ] = pl_interfaces.InputDatasetInterface.pyd_field(
293
- alias="i",
294
- is_required=False,
295
- description=(
296
- "The input dataset. If None, the first operation "
297
- "must be a sequence generator."
298
- ),
299
- piper_port=PiperPortType.INPUT,
290
+ input: t.Optional[pl_interfaces.InputDatasetInterface] = (
291
+ pl_interfaces.InputDatasetInterface.pyd_field(
292
+ alias="i",
293
+ is_required=False,
294
+ description=(
295
+ "The input dataset. If None, the first operation "
296
+ "must be a sequence generator."
297
+ ),
298
+ piper_port=PiperPortType.INPUT,
299
+ )
300
300
  )
301
301
 
302
302
  output: pl_interfaces.OutputDatasetInterface = (
@@ -332,11 +332,7 @@ class PipeCommand(PipelimeCommand, title="pipe"):
332
332
 
333
333
 
334
334
  class CloneCommand(PipelimeCommand, title="clone"):
335
- """Clone a dataset.
336
-
337
- You can use this command to create a local copy of a dataset
338
- hosted on a remote data lake by disabling the `REMOTE_FILE` serialization option.
339
- """
335
+ """Clone a dataset."""
340
336
 
341
337
  input: pl_interfaces.InputDatasetInterface = (
342
338
  pl_interfaces.InputDatasetInterface.pyd_field(
@@ -470,118 +466,6 @@ class ZipCommand(PipelimeCommand, title="zip"):
470
466
  )
471
467
 
472
468
 
473
- class RemoteCommandBase(PipelimeCommand):
474
- input: pl_interfaces.InputDatasetInterface = (
475
- pl_interfaces.InputDatasetInterface.pyd_field(
476
- alias="i", piper_port=PiperPortType.INPUT
477
- )
478
- )
479
-
480
- remotes: t.Union[
481
- pl_interfaces.RemoteInterface, t.Sequence[pl_interfaces.RemoteInterface]
482
- ] = pl_interfaces.RemoteInterface.pyd_field(alias="r")
483
-
484
- keys: t.Union[str, t.Sequence[str]] = pyd.Field(
485
- default_factory=list,
486
- alias="k",
487
- description="Affected keys. Leave empty to take all the keys.",
488
- )
489
-
490
- start: int = pyd.Field(
491
- 0,
492
- description=(
493
- "The first sample (included), defaults to the first element. "
494
- "Can be negative, in which case it counts from the end."
495
- ),
496
- )
497
- stop: t.Optional[int] = pyd.Field(
498
- None,
499
- description=(
500
- "The last sample (excluded), defaults to the whole sequence."
501
- "Can be negative, in which case it counts from the end."
502
- ),
503
- )
504
- step: int = pyd.Field(
505
- 1, description="The slice step, defaults to 1. Can be negative."
506
- )
507
-
508
- output: pl_interfaces.OutputDatasetInterface = (
509
- pl_interfaces.OutputDatasetInterface.pyd_field(
510
- alias="o", piper_port=PiperPortType.OUTPUT
511
- )
512
- )
513
-
514
- grabber: pl_interfaces.GrabberInterface = pl_interfaces.GrabberInterface.pyd_field(
515
- alias="g"
516
- )
517
-
518
- @pyd.validator("remotes", "keys")
519
- def validate_remotes(cls, v):
520
- return (
521
- v if not isinstance(v, (str, bytes)) and isinstance(v, t.Sequence) else [v]
522
- )
523
-
524
- def _run_remote_op(self, stage, message):
525
- from pipelime.sequences.pipes.mapping import MappingConditionIndexRange
526
-
527
- seq = self.input.create_reader().map_if(
528
- stage=stage,
529
- condition=MappingConditionIndexRange(
530
- start=self.start,
531
- stop=self.stop,
532
- step=self.step,
533
- ),
534
- )
535
-
536
- self.grabber.grab_all(
537
- self.output.append_writer(seq),
538
- grab_context_manager=self.output.serialization_cm(),
539
- keep_order=False,
540
- parent_cmd=self,
541
- track_message=message,
542
- )
543
-
544
-
545
- class AddRemoteCommand(RemoteCommandBase, title="remote-add"):
546
- """Upload samples to one or more remotes.
547
-
548
- Slicing and key options filter the samples to upload,
549
- but the whole dataset is always written out.
550
- """
551
-
552
- def run(self):
553
- from pipelime.stages import StageUploadToRemote
554
-
555
- self._run_remote_op(
556
- StageUploadToRemote(
557
- remotes=[r.get_url() for r in self.remotes], # type: ignore
558
- keys_to_upload=self.keys,
559
- ),
560
- "Uploading data",
561
- )
562
-
563
-
564
- class RemoveRemoteCommand(RemoteCommandBase, title="remote-remove"):
565
- """Remove one or more remote from a dataset.
566
-
567
- Slicing and key options filter the samples,
568
- but the whole dataset is always written out.
569
-
570
- NB: data is not removed from the remote data lake.
571
- """
572
-
573
- def run(self):
574
- from pipelime.stages import StageForgetSource
575
-
576
- remotes = [r.get_url() for r in self.remotes] # type: ignore
577
- remove_all = remotes if not self.keys else []
578
- remove_by_key = {k: remotes for k in self.keys}
579
-
580
- self._run_remote_op(
581
- StageForgetSource(*remove_all, **remove_by_key), "Removing remote sources"
582
- )
583
-
584
-
585
469
  class ValidateCommand(PipelimeCommand, title="validate"):
586
470
  """Outputs a minimal schema which will validate the given input."""
587
471