pipelime-python 1.9.0__py3-none-any.whl → 2.0.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 (57) hide show
  1. pipelime/__init__.py +1 -1
  2. pipelime/choixe/ast/nodes.py +3 -3
  3. pipelime/choixe/utils/io.py +4 -3
  4. pipelime/choixe/visitors/decoder.py +1 -1
  5. pipelime/cli/main.py +68 -4
  6. pipelime/cli/pretty_print.py +10 -10
  7. pipelime/cli/tui/tui.css +1 -1
  8. pipelime/cli/tui/tui.py +22 -18
  9. pipelime/cli/tui/utils.py +2 -2
  10. pipelime/cli/utils.py +7 -7
  11. pipelime/commands/__init__.py +13 -15
  12. pipelime/commands/general.py +26 -142
  13. pipelime/commands/interfaces.py +34 -107
  14. pipelime/commands/piper.py +10 -2
  15. pipelime/commands/resume.py +1 -1
  16. pipelime/commands/shell.py +5 -5
  17. pipelime/commands/split_ops.py +38 -38
  18. pipelime/commands/tempman.py +13 -9
  19. pipelime/commands/toy_dataset.py +1 -1
  20. pipelime/items/base.py +25 -138
  21. pipelime/piper/checkpoint.py +5 -4
  22. pipelime/piper/drawing/mermaid.py +1 -1
  23. pipelime/piper/executors/base.py +2 -0
  24. pipelime/piper/executors/factory.py +1 -1
  25. pipelime/piper/model.py +9 -8
  26. pipelime/piper/progress/model.py +1 -1
  27. pipelime/sequences/grabber.py +61 -7
  28. pipelime/sequences/pipes/base.py +3 -2
  29. pipelime/sequences/pipes/mapping.py +2 -1
  30. pipelime/sequences/pipes/operations.py +5 -4
  31. pipelime/sequences/pipes/validation.py +3 -3
  32. pipelime/sequences/pipes/writers.py +2 -2
  33. pipelime/sequences/samples_sequence.py +22 -6
  34. pipelime/sequences/sources/from_callable.py +1 -1
  35. pipelime/sequences/sources/raw.py +1 -1
  36. pipelime/sequences/sources/readers.py +53 -2
  37. pipelime/sequences/sources/toy_dataset.py +7 -6
  38. pipelime/sequences/utils.py +7 -7
  39. pipelime/stages/__init__.py +13 -10
  40. pipelime/stages/augmentations.py +2 -2
  41. pipelime/stages/base.py +1 -1
  42. pipelime/stages/entities.py +9 -8
  43. pipelime/stages/item_info.py +2 -2
  44. pipelime/stages/item_replacement.py +3 -3
  45. pipelime/stages/item_sources.py +3 -24
  46. pipelime/stages/key_transformations.py +1 -1
  47. pipelime/utils/deprecated.py +51 -0
  48. pipelime/utils/pydantic_types.py +10 -7
  49. {pipelime_python-1.9.0.dist-info → pipelime_python-2.0.0.dist-info}/METADATA +10 -10
  50. {pipelime_python-1.9.0.dist-info → pipelime_python-2.0.0.dist-info}/RECORD +53 -56
  51. {pipelime_python-1.9.0.dist-info → pipelime_python-2.0.0.dist-info}/WHEEL +1 -1
  52. pipelime/remotes/__init__.py +0 -5
  53. pipelime/remotes/base.py +0 -415
  54. pipelime/remotes/s3_remote.py +0 -184
  55. pipelime/remotes/shared_folder_remote.py +0 -144
  56. {pipelime_python-1.9.0.dist-info → pipelime_python-2.0.0.dist-info}/entry_points.txt +0 -0
  57. {pipelime_python-1.9.0.dist-info → pipelime_python-2.0.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.0"
5
+ __version__ = "2.0.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__()
@@ -111,9 +111,9 @@ class PipelimeTmp:
111
111
 
112
112
  user_dirs: Dict[str, List[str]] = {}
113
113
  for d in iglob(str(PipelimeTmp.base_dir() / (PipelimeTmp.prefix() + "*"))):
114
- if os.path.isdir(d):
114
+ if os.path.isdir(d): # pragma: no branch
115
115
  names = os.path.basename(d).split("-")
116
- if len(names) >= 3:
116
+ if len(names) >= 3: # pragma: no branch
117
117
  user_dirs.setdefault(names[2], []).append(d)
118
118
  return user_dirs
119
119
 
@@ -135,7 +135,8 @@ class PipelimeTemporaryDirectory:
135
135
  import shutil
136
136
 
137
137
  def onerror(func, path, exc_info):
138
- if issubclass(exc_info[0], PermissionError):
138
+ # this code comes from TemporaryDirectory
139
+ if issubclass(exc_info[0], PermissionError): # pragma: no cover
139
140
 
140
141
  def resetperms(path):
141
142
  try:
@@ -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
@@ -57,7 +58,57 @@ class PlCliOptions(BaseModel):
57
58
  return data
58
59
 
59
60
 
60
- def _complete_yaml(incomplete: str):
61
+ def _set_logger_level(verbose: int):
62
+ """Set the logger level if not forced by the user."""
63
+ import os
64
+ import sys
65
+
66
+ from loguru import logger
67
+
68
+ if "LOGURU_LEVEL" not in os.environ:
69
+ if verbose == 0:
70
+ level = "WARNING"
71
+ elif verbose == 1:
72
+ level = "INFO"
73
+ elif verbose == 2:
74
+ level = "DEBUG"
75
+ else:
76
+ level = "TRACE"
77
+ logger.remove()
78
+ logger.add(sys.stderr, level=level)
79
+
80
+ # set the level in the environment so that it is inherited by subprocesses
81
+ os.environ["LOGURU_LEVEL"] = level
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
+
111
+ def _complete_yaml(incomplete: str): # pragma: no cover
61
112
  for v in Path(".").glob(f"{incomplete}*.yaml"):
62
113
  yield str(v)
63
114
 
@@ -399,6 +450,13 @@ def pl_main(
399
450
  resolve_path=True,
400
451
  help="The checkpoint folder. If it already exists, it must be empty.",
401
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
+ ),
402
460
  verbose: int = typer.Option(
403
461
  0,
404
462
  "--verbose",
@@ -468,6 +526,8 @@ def pl_main(
468
526
  TRUE boolean values. Use `false` or `true` to explicitly set a boolean
469
527
  and `none`/`null`/`nul` to enforce `None`.
470
528
  """
529
+ _set_logger_level(verbose)
530
+
471
531
  PipelimeSymbolsHelper.set_extra_modules(extra_modules)
472
532
 
473
533
  if command_args is None:
@@ -549,6 +609,7 @@ def pl_main(
549
609
  output_ctx=output_ctx,
550
610
  command_outputs=command_outputs,
551
611
  verbose=verbose,
612
+ data_cache=data_cache,
552
613
  dry_run=dry_run,
553
614
  no_ui=no_ui,
554
615
  command=command,
@@ -593,6 +654,7 @@ def run_with_checkpoint(
593
654
  from pipelime.choixe import XConfig
594
655
  from pipelime.cli.pretty_print import print_error, print_info, print_warning
595
656
 
657
+ _set_item_data_cache(cli_opts.data_cache)
596
658
  PipelimeSymbolsHelper.set_extra_modules(cli_opts.extra_modules)
597
659
 
598
660
  if cli_opts.pipelime_tmp:
@@ -780,7 +842,9 @@ def run_with_checkpoint(
780
842
 
781
843
  cfg_size = len(effective_configs)
782
844
  pls = "s" if cfg_size != 1 else ""
783
- print_info(f"🎉 Configuration successfully processed ({cfg_size} variant{pls}).")
845
+ print_info(
846
+ f"🎉 Configuration successfully processed ({cfg_size} variant{pls})."
847
+ )
784
848
 
785
849
  if cli_opts.verbose > 2:
786
850
  print_info("\nFinal effective configurations:")
@@ -854,7 +918,7 @@ def run_command(
854
918
 
855
919
  import time
856
920
 
857
- from pydantic.error_wrappers import ValidationError
921
+ from pydantic.v1.error_wrappers import ValidationError
858
922
 
859
923
  from pipelime.choixe.utils.io import PipelimeTmp, dump
860
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