pipen-cli-gbatch 0.0.2__py3-none-any.whl → 0.0.4__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.

Potentially problematic release.


This version of pipen-cli-gbatch might be problematic. Click here for more details.

@@ -79,7 +79,7 @@ from pipen.cli import CLIPlugin
79
79
  from pipen.scheduler import GbatchScheduler
80
80
  from pipen_poplog import LogsPopulator
81
81
 
82
- __version__ = "0.0.2"
82
+ __version__ = "0.0.4"
83
83
  __all__ = ("CliGbatchPlugin", "CliGbatchDaemon")
84
84
 
85
85
 
@@ -117,6 +117,11 @@ class CliGbatchDaemon:
117
117
 
118
118
  self.config.prescript = self.config.get("prescript", None) or ""
119
119
  self.config.postscript = self.config.get("postscript", None) or ""
120
+ if "labels" in self.config and isinstance(self.config.labels, list):
121
+ self.config.labels = {
122
+ key: val
123
+ for key, val in (item.split("=", 1) for item in self.config.labels)
124
+ }
120
125
  self.command = command
121
126
 
122
127
  def _get_arg_from_command(self, arg: str) -> str | None:
@@ -183,7 +188,7 @@ class CliGbatchDaemon:
183
188
  """
184
189
  mount = self.config.get("mount", [])
185
190
  # mount the workdir
186
- mount.append(f'{source}:{target}')
191
+ mount.append(f"{source}:{target}")
187
192
 
188
193
  self.config["mount"] = mount
189
194
 
@@ -197,7 +202,7 @@ class CliGbatchDaemon:
197
202
  SystemExit: If workdir is not a valid Google Storage bucket path.
198
203
  """
199
204
  command_workdir = self._get_arg_from_command("workdir")
200
- workdir = self.config.get("workdir", command_workdir)
205
+ workdir = self.config.get("workdir", None) or command_workdir
201
206
 
202
207
  if not workdir or not isinstance(AnyPath(workdir), GSPath):
203
208
  print(
@@ -312,7 +317,7 @@ class CliGbatchDaemon:
312
317
 
313
318
  def _show_scheduler_opts(self):
314
319
  """Log the scheduler options for debugging purposes."""
315
- logger.debug("Scheduler Options:")
320
+ logger.info("Scheduler Options:")
316
321
  for key, val in self.config.items():
317
322
  if key in (
318
323
  "workdir",
@@ -332,7 +337,7 @@ class CliGbatchDaemon:
332
337
  ):
333
338
  continue
334
339
 
335
- logger.debug(f"- {key}: {val}")
340
+ logger.info(f"- {key}: {val}")
336
341
 
337
342
  async def _run_wait(self): # pragma: no cover
338
343
  """Run the pipeline and wait for completion.
@@ -493,7 +498,7 @@ class CliGbatchDaemon:
493
498
  )
494
499
  sys.exit(1)
495
500
 
496
- if 'name' not in self.config:
501
+ if "name" not in self.config or not self.config.name:
497
502
  self.config["name"] = "PipenCliGbatchDaemon"
498
503
 
499
504
  async def run(self): # pragma: no cover
@@ -553,6 +558,17 @@ class XquteCliGbatchPlugin: # pragma: no cover
553
558
  logger.error(f"/STDERR {self.stderr_populator.residue}")
554
559
  self.stderr_populator.residue = ""
555
560
 
561
+ @plugin.impl
562
+ async def on_job_init(self, scheduler, job):
563
+ """Handle job initialization event.
564
+
565
+ Args:
566
+ scheduler: The scheduler instance.
567
+ job: The job being initialized.
568
+ """
569
+ self.stdout_populator.logfile = scheduler.workdir.joinpath("0", "job.stdout")
570
+ self.stderr_populator.logfile = scheduler.workdir.joinpath("0", "job.stderr")
571
+
556
572
  @plugin.impl
557
573
  async def on_job_started(self, scheduler, job):
558
574
  """Handle job start event by setting up log file paths.
@@ -564,8 +580,6 @@ class XquteCliGbatchPlugin: # pragma: no cover
564
580
  if not self.log_start:
565
581
  return
566
582
 
567
- self.stdout_populator.logfile = scheduler.workdir.joinpath("0", "job.stdout")
568
- self.stderr_populator.logfile = scheduler.workdir.joinpath("0", "job.stderr")
569
583
  logger.info("Job is picked up by Google Batch, pulling stdout/stderr...")
570
584
 
571
585
  @plugin.impl
@@ -693,29 +707,29 @@ class CliGbatchPlugin(CLIPlugin): # pragma: no cover
693
707
  super().__init__(parser, subparser)
694
708
  subparser.epilog = """\033[1;4mExamples\033[0m:
695
709
 
696
- \u200B
710
+ \u200b
697
711
  # Run a command and wait for it to complete
698
712
  > pipen gbatch --workdir gs://my-bucket/workdir -- \\
699
713
  python myscript.py --input input.txt --output output.txt
700
714
 
701
- \u200B
715
+ \u200b
702
716
  # Use named mounts
703
717
  > pipen gbatch --workdir gs://my-bucket/workdir --mount INFILE=gs://bucket/path/to/file \\
704
718
  --mount OUTDIR=gs://bucket/path/to/outdir -- \\
705
719
  bash -c 'cat $INFILE > $OUTDIR/output.txt'
706
720
 
707
- \u200B
721
+ \u200b
708
722
  # Run a command in a detached mode
709
723
  > pipen gbatch --nowait --project $PROJECT --location $LOCATION \\
710
724
  --workdir gs://my-bucket/workdir -- \\
711
725
  python myscript.py --input input.txt --output output.txt
712
726
 
713
- \u200B
727
+ \u200b
714
728
  # If you have a profile defined in ~/.pipen.toml or ./.pipen.toml
715
729
  > pipen gbatch --profile myprofile -- \\
716
730
  python myscript.py --input input.txt --output output.txt
717
731
 
718
- \u200B
732
+ \u200b
719
733
  # View the logs of a previously run command
720
734
  > pipen gbatch --view-logs all --name my-daemon-name \\
721
735
  --workdir gs://my-bucket/workdir
@@ -753,12 +767,36 @@ class CliGbatchPlugin(CLIPlugin): # pragma: no cover
753
767
  CONFIG_FILES,
754
768
  known_parsed.profile,
755
769
  )
770
+
771
+ def is_valid(val: Any) -> bool:
772
+ """Check if a value is valid (not None, not empty string, not empty list).
773
+ """
774
+ if val is None:
775
+ return False
776
+ if isinstance(val, bool):
777
+ return True
778
+ return bool(val)
779
+
756
780
  # update parsed with the defaults
757
781
  for key, val in defaults.items():
782
+ if (
783
+ key == "mount"
784
+ and val
785
+ and getattr(known_parsed, key, None)
786
+ ):
787
+ if not isinstance(val, (tuple, list)):
788
+ val = [val]
789
+ val = list(val)
790
+
791
+ kp_mount = getattr(known_parsed, key)
792
+ val.extend(kp_mount)
793
+ setattr(known_parsed, key, val)
794
+ continue
795
+
758
796
  if (
759
797
  key == "command"
760
798
  or val is None
761
- or getattr(known_parsed, key, None) is not None
799
+ or is_valid(getattr(known_parsed, key, None))
762
800
  ):
763
801
  continue
764
802
 
@@ -120,7 +120,7 @@ help = "The location to run the job."
120
120
  flags = ["--mount"]
121
121
  # type = "list"
122
122
  default = []
123
- action = "clear_append"
123
+ action = "append"
124
124
  help = """The list of mounts to mount to the VM, each in the format of SOURCE:TARGET, where SOURCE must be either a Google Storage Bucket path (gs://...).
125
125
  You can also use named mounts like `INDIR=gs://my-bucket/inputs` and the directory will be mounted to `/mnt/disks/INDIR` in the VM;
126
126
  then you can use environment variable `$INDIR` in the command/script to refer to the mounted path.
@@ -186,20 +186,21 @@ and positive values mean to run after the main command."""
186
186
  [[groups.arguments]]
187
187
  flags = ["--allocationPolicy"]
188
188
  type = "json"
189
- default = "{}"
189
+ default = {}
190
190
  help = "The JSON string of extra settings of allocationPolicy add to the job.json. Refer to https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#AllocationPolicy for details."
191
191
 
192
192
  [[groups.arguments]]
193
193
  flags = ["--taskGroups"]
194
194
  type = "json"
195
- default = "[]"
195
+ default = []
196
196
  help = "The JSON string of extra settings of taskGroups add to the job.json. Refer to https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#TaskGroup for details."
197
197
 
198
198
  [[groups.arguments]]
199
199
  flags = ["--labels"]
200
- type = "json"
201
- default = "{}"
202
- help = "The JSON string of labels to add to the job. Refer to https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#Job.FIELDS.labels for details."
200
+ # type = "json"
201
+ default = []
202
+ action = "clear_append"
203
+ help = "The strings of labels to add to the job (key=value). Refer to https://cloud.google.com/batch/docs/reference/rest/v1/projects.locations.jobs#Job.FIELDS.labels for details."
203
204
 
204
205
  [[groups.arguments]]
205
206
  flags = ["--gcloud"]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: pipen-cli-gbatch
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: A pipen cli plugin to run command via Google Cloud Batch
5
5
  License: MIT
6
6
  Author: pwwang
@@ -13,9 +13,12 @@ Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
16
17
  Requires-Dist: google-cloud-storage (>=3.0.0,<4.0.0)
17
18
  Requires-Dist: pipen (>=0.17.19,<0.18.0)
18
19
  Requires-Dist: pipen-poplog (>=0.3.6,<0.4.0)
20
+ Project-URL: Homepage, https://github.com/pwwang/pipen-cli-gbatch
21
+ Project-URL: Repository, https://github.com/pwwang/pipen-cli-gbatch
19
22
  Description-Content-Type: text/markdown
20
23
 
21
24
  # pipen-cli-gbatch
@@ -0,0 +1,6 @@
1
+ pipen_cli_gbatch/__init__.py,sha256=x5R1wU-TyXS_Z1EqJ1jWhFn66sKLt_fg8eyXtz9k7rg,29508
2
+ pipen_cli_gbatch/daemon_args.toml,sha256=YzqLumFjIY8mRMzRt3M5D1fEjK93QvQJ0XynDnimPIo,6873
3
+ pipen_cli_gbatch-0.0.4.dist-info/METADATA,sha256=5i6JjljULy5Km96zlHt0dcI97Wleq73yzYpakX5j8Zw,11301
4
+ pipen_cli_gbatch-0.0.4.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
5
+ pipen_cli_gbatch-0.0.4.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
+ pipen_cli_gbatch-0.0.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- pipen_cli_gbatch/__init__.py,sha256=cTX5Sdt-42el8s4mW2daAUQcCieP_2kOiJpzR0zzags,28294
2
- pipen_cli_gbatch/daemon_args.toml,sha256=Q_fbj1Eesj02A74RDteSCXGE8s9iaRF9pAzYZOyF8ek,6851
3
- pipen_cli_gbatch-0.0.2.dist-info/METADATA,sha256=y7v2ah3bPm8RzFeSqvA78jC7GUU8g4SRPPzSOgMp9vk,11116
4
- pipen_cli_gbatch-0.0.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
5
- pipen_cli_gbatch-0.0.2.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
- pipen_cli_gbatch-0.0.2.dist-info/RECORD,,