pipen-cli-gbatch 0.0.6__py3-none-any.whl → 0.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.

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.6"
82
+ __version__ = "0.1.0"
83
83
  __all__ = ("CliGbatchPlugin", "CliGbatchDaemon")
84
84
  MOUNTED_CWD = "/mnt/disks/.cwd"
85
85
 
@@ -135,6 +135,7 @@ class CliGbatchDaemon:
135
135
  for key, val in (item.split("=", 1) for item in self.config.labels)
136
136
  }
137
137
  self.command = command
138
+ self._command_workdir = None
138
139
 
139
140
  def _get_arg_from_command(self, arg: str) -> str | None:
140
141
  """Get the value of the given argument from the command line.
@@ -218,8 +219,10 @@ class CliGbatchDaemon:
218
219
  if from_mount_as_cwd:
219
220
  self.config.workdir = f"{self.mount_as_cwd}/.pipen/{command_name}"
220
221
 
221
- command_workdir = self._get_arg_from_command("workdir")
222
- workdir = self.config.get("workdir", None) or command_workdir
222
+ # self._command_workdir to save the original command workdir
223
+ self._command_workdir = workdir = (
224
+ self.config.get("workdir", None) or self._get_arg_from_command("workdir")
225
+ )
223
226
 
224
227
  if not workdir or not isinstance(AnyPath(workdir), GSPath):
225
228
  print(
@@ -247,8 +250,16 @@ class CliGbatchDaemon:
247
250
  command_outdir = self._get_arg_from_command("outdir")
248
251
 
249
252
  if command_outdir:
250
- self._add_mount(command_outdir, GbatchScheduler.MOUNTED_OUTDIR)
251
- self._replace_arg_in_command("outdir", GbatchScheduler.MOUNTED_OUTDIR)
253
+ coudir = AnyPath(command_outdir)
254
+ if (
255
+ not isinstance(coudir, GSPath)
256
+ and not coudir.is_absolute()
257
+ and self.mount_as_cwd
258
+ ):
259
+ self._replace_arg_in_command("outdir", f"{MOUNTED_CWD}/{coudir}")
260
+ else:
261
+ self._add_mount(command_outdir, GbatchScheduler.MOUNTED_OUTDIR)
262
+ self._replace_arg_in_command("outdir", GbatchScheduler.MOUNTED_OUTDIR)
252
263
  elif self.mount_as_cwd:
253
264
  command_name = self._get_arg_from_command("name") or self.config.name
254
265
  self._replace_arg_in_command(
@@ -304,7 +315,13 @@ class CliGbatchDaemon:
304
315
  and not self.config.view_logs
305
316
  and "logging" not in plugin.get_all_plugin_names()
306
317
  ):
307
- plugins.append(XquteCliGbatchPlugin())
318
+ if self.config.plain:
319
+ # use the stdout file from daemon
320
+ stdout_file = None
321
+ else:
322
+ stdout_file = AnyPath(f"{self._command_workdir}/run-latest.log")
323
+
324
+ plugins.append(XquteCliGbatchPlugin(stdout_file=stdout_file))
308
325
 
309
326
  return Xqute(
310
327
  "gbatch",
@@ -516,6 +533,12 @@ class CliGbatchDaemon:
516
533
  self._handle_outdir()
517
534
  self._infer_jobname_prefix()
518
535
  else:
536
+ if "name" not in self.config or not self.config.name:
537
+ self.config["name"] = "PipenCliGbatchDaemon"
538
+
539
+ if not self.config.workdir and self.mount_as_cwd:
540
+ self.config.workdir = f"{self.mount_as_cwd}/.pipen"
541
+
519
542
  if not self.config.workdir or not isinstance(
520
543
  AnyPath(self.config.workdir),
521
544
  GSPath,
@@ -526,9 +549,6 @@ class CliGbatchDaemon:
526
549
  )
527
550
  sys.exit(1)
528
551
 
529
- if "name" not in self.config or not self.config.name:
530
- self.config["name"] = "PipenCliGbatchDaemon"
531
-
532
552
  async def run(self): # pragma: no cover
533
553
  """Execute the daemon pipeline based on configuration.
534
554
 
@@ -560,12 +580,15 @@ class XquteCliGbatchPlugin: # pragma: no cover
560
580
 
561
581
  Attributes:
562
582
  name (str): The plugin name.
563
- log_start (bool): Whether to start logging when job starts.
564
583
  stdout_populator (LogsPopulator): Handles stdout log population.
565
584
  stderr_populator (LogsPopulator): Handles stderr log population.
566
585
  """
567
586
 
568
- def __init__(self, name: str = "logging", log_start: bool = True):
587
+ def __init__(
588
+ self,
589
+ name: str = "logging",
590
+ stdout_file: str | Path | GSPath | None = None,
591
+ ):
569
592
  """Initialize the logging plugin.
570
593
 
571
594
  Args:
@@ -573,7 +596,7 @@ class XquteCliGbatchPlugin: # pragma: no cover
573
596
  log_start: Whether to start logging when job starts.
574
597
  """
575
598
  self.name = name
576
- self.log_start = log_start
599
+ self.stdout_file = stdout_file
577
600
  self.stdout_populator = LogsPopulator()
578
601
  self.stderr_populator = LogsPopulator()
579
602
 
@@ -586,17 +609,6 @@ class XquteCliGbatchPlugin: # pragma: no cover
586
609
  logger.error(f"/STDERR {self.stderr_populator.residue}")
587
610
  self.stderr_populator.residue = ""
588
611
 
589
- @plugin.impl
590
- async def on_job_init(self, scheduler, job):
591
- """Handle job initialization event.
592
-
593
- Args:
594
- scheduler: The scheduler instance.
595
- job: The job being initialized.
596
- """
597
- self.stdout_populator.logfile = scheduler.workdir.joinpath("0", "job.stdout")
598
- self.stderr_populator.logfile = scheduler.workdir.joinpath("0", "job.stderr")
599
-
600
612
  @plugin.impl
601
613
  async def on_job_started(self, scheduler, job):
602
614
  """Handle job start event by setting up log file paths.
@@ -605,10 +617,31 @@ class XquteCliGbatchPlugin: # pragma: no cover
605
617
  scheduler: The scheduler instance.
606
618
  job: The job that started.
607
619
  """
608
- if not self.log_start:
609
- return
610
-
611
620
  logger.info("Job is picked up by Google Batch, pulling stdout/stderr...")
621
+ if not self.stdout_file:
622
+ self.stdout_populator.logfile = scheduler.workdir.joinpath(
623
+ "0", "job.stdout"
624
+ )
625
+ elif not self.stdout_file.exists():
626
+ await asyncio.sleep(3) # wait a bit for the file to be created
627
+ if not self.stdout_file.exists():
628
+ logger.warning(f"Running logs not found: {self.stdout_file}")
629
+ logger.warning(
630
+ "Make sure pipen-log2file plugin is enabled for your pipeline."
631
+ )
632
+ logger.warning("Falling back to pull logs from daemon...")
633
+ self.stdout_populator.logfile = scheduler.workdir.joinpath(
634
+ "0", "job.stdout"
635
+ )
636
+ else:
637
+ self.stdout_populator.logfile = (
638
+ self.stdout_file.resolve()
639
+ if self.stdout_file.is_symlink()
640
+ else self.stdout_file
641
+ )
642
+ else:
643
+ self.stdout_populator.logfile = self.stdout_file
644
+ self.stderr_populator.logfile = scheduler.workdir.joinpath("0", "job.stderr")
612
645
 
613
646
  @plugin.impl
614
647
  async def on_job_polling(self, scheduler, job, counter):
@@ -809,11 +842,7 @@ class CliGbatchPlugin(CLIPlugin): # pragma: no cover
809
842
 
810
843
  # update parsed with the defaults
811
844
  for key, val in defaults.items():
812
- if (
813
- key == "mount"
814
- and val
815
- and getattr(known_parsed, key, None)
816
- ):
845
+ if key == "mount" and val and getattr(known_parsed, key, None):
817
846
  if not isinstance(val, (tuple, list)):
818
847
  val = [val]
819
848
  val = list(val)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipen-cli-gbatch
3
- Version: 0.0.6
3
+ Version: 0.1.0
4
4
  Summary: A pipen cli plugin to run command via Google Cloud Batch
5
5
  License: MIT
6
6
  Author: pwwang
@@ -0,0 +1,6 @@
1
+ pipen_cli_gbatch/__init__.py,sha256=e2nJIiWPFzlzNAbOxzTanCtXg0oot28HrxHpH7KGyxI,32264
2
+ pipen_cli_gbatch/daemon_args.toml,sha256=XrCDwTaJ7xPgGLtZev4qikjrZWqixdE8tqSsFnIvmjc,7381
3
+ pipen_cli_gbatch-0.1.0.dist-info/METADATA,sha256=sNcCQTI7p7ibwuWIFT-SQo8RT-gLbjlE8TO2Bv592Q0,11301
4
+ pipen_cli_gbatch-0.1.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
5
+ pipen_cli_gbatch-0.1.0.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
+ pipen_cli_gbatch-0.1.0.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- pipen_cli_gbatch/__init__.py,sha256=5ChKkEGzq1S2irrwHpNts2oqezfB1zKs5IA2i3YJd-c,30862
2
- pipen_cli_gbatch/daemon_args.toml,sha256=XrCDwTaJ7xPgGLtZev4qikjrZWqixdE8tqSsFnIvmjc,7381
3
- pipen_cli_gbatch-0.0.6.dist-info/METADATA,sha256=ZvlRbQNOG6k2EIe2UeE4f469VP8AZM_IcLDlkuw91wg,11301
4
- pipen_cli_gbatch-0.0.6.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
5
- pipen_cli_gbatch-0.0.6.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
- pipen_cli_gbatch-0.0.6.dist-info/RECORD,,