pipen-cli-gbatch 0.0.5__py3-none-any.whl → 0.0.7__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,8 +79,9 @@ 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.5"
82
+ __version__ = "0.0.7"
83
83
  __all__ = ("CliGbatchPlugin", "CliGbatchDaemon")
84
+ MOUNTED_CWD = "/mnt/disks/.cwd"
84
85
 
85
86
 
86
87
  class CliGbatchDaemon:
@@ -115,6 +116,17 @@ class CliGbatchDaemon:
115
116
  else:
116
117
  self.config = Diot(config)
117
118
 
119
+ self.mount_as_cwd = self.config.pop("mount_as_cwd", None)
120
+ if self.mount_as_cwd:
121
+ if self.config.cwd:
122
+ print(
123
+ "\033[1;4mError\033[0m: --mount-as-cwd cannot be used with "
124
+ "--cwd at the same time.\n"
125
+ )
126
+ sys.exit(1)
127
+ self.config.cwd = MOUNTED_CWD
128
+ self._add_mount(self.mount_as_cwd, MOUNTED_CWD)
129
+
118
130
  self.config.prescript = self.config.get("prescript", None) or ""
119
131
  self.config.postscript = self.config.get("postscript", None) or ""
120
132
  if "labels" in self.config and isinstance(self.config.labels, list):
@@ -201,6 +213,11 @@ class CliGbatchDaemon:
201
213
  Raises:
202
214
  SystemExit: If workdir is not a valid Google Storage bucket path.
203
215
  """
216
+ command_name = self._get_arg_from_command("name") or self.config["name"]
217
+ from_mount_as_cwd = self.mount_as_cwd and not self.config.workdir
218
+ if from_mount_as_cwd:
219
+ self.config.workdir = f"{self.mount_as_cwd}/.pipen/{command_name}"
220
+
204
221
  command_workdir = self._get_arg_from_command("workdir")
205
222
  workdir = self.config.get("workdir", None) or command_workdir
206
223
 
@@ -212,11 +229,14 @@ class CliGbatchDaemon:
212
229
  sys.exit(1)
213
230
 
214
231
  self.config["workdir"] = workdir
215
- # If command workdir is different from config workdir, we need to mount it
216
- self._add_mount(workdir, GbatchScheduler.MOUNTED_METADIR)
232
+ if from_mount_as_cwd: # already mounted
233
+ self._replace_arg_in_command("workdir", f"{MOUNTED_CWD}/.pipen")
234
+ else:
235
+ # If command workdir is different from config workdir, we need to mount it
236
+ self._add_mount(workdir, GbatchScheduler.MOUNTED_METADIR)
217
237
 
218
- # replace --workdir value with the mounted workdir in the command
219
- self._replace_arg_in_command("workdir", GbatchScheduler.MOUNTED_METADIR)
238
+ # replace --workdir value with the mounted workdir in the command
239
+ self._replace_arg_in_command("workdir", GbatchScheduler.MOUNTED_METADIR)
220
240
 
221
241
  def _handle_outdir(self):
222
242
  """Handle output directory configuration and mounting.
@@ -227,8 +247,22 @@ class CliGbatchDaemon:
227
247
  command_outdir = self._get_arg_from_command("outdir")
228
248
 
229
249
  if command_outdir:
230
- self._add_mount(command_outdir, GbatchScheduler.MOUNTED_OUTDIR)
231
- self._replace_arg_in_command("outdir", GbatchScheduler.MOUNTED_OUTDIR)
250
+ coudir = AnyPath(command_outdir)
251
+ if (
252
+ not isinstance(coudir, GSPath)
253
+ and not coudir.is_absolute()
254
+ and self.mount_as_cwd
255
+ ):
256
+ self._replace_arg_in_command("outdir", f"{MOUNTED_CWD}/{coudir}")
257
+ else:
258
+ self._add_mount(command_outdir, GbatchScheduler.MOUNTED_OUTDIR)
259
+ self._replace_arg_in_command("outdir", GbatchScheduler.MOUNTED_OUTDIR)
260
+ elif self.mount_as_cwd:
261
+ command_name = self._get_arg_from_command("name") or self.config.name
262
+ self._replace_arg_in_command(
263
+ "outdir",
264
+ f"{MOUNTED_CWD}/{command_name}-output",
265
+ )
232
266
 
233
267
  def _infer_name(self):
234
268
  """Infer the daemon name from configuration or command arguments.
@@ -303,6 +337,7 @@ class CliGbatchDaemon:
303
337
  "version",
304
338
  "loglevel",
305
339
  "mounts",
340
+ "mount_as_cwd",
306
341
  "plain",
307
342
  )
308
343
  },
@@ -333,6 +368,7 @@ class CliGbatchDaemon:
333
368
  "version",
334
369
  "loglevel",
335
370
  "mounts",
371
+ "mount_as_cwd",
336
372
  "plain",
337
373
  ):
338
374
  continue
@@ -483,11 +519,17 @@ class CliGbatchDaemon:
483
519
  logger.setLevel(self.config.loglevel.upper())
484
520
 
485
521
  if not self.config.plain:
522
+ self._infer_name()
486
523
  self._handle_workdir()
487
524
  self._handle_outdir()
488
- self._infer_name()
489
525
  self._infer_jobname_prefix()
490
526
  else:
527
+ if "name" not in self.config or not self.config.name:
528
+ self.config["name"] = "PipenCliGbatchDaemon"
529
+
530
+ if not self.config.workdir and self.mount_as_cwd:
531
+ self.config.workdir = f"{self.mount_as_cwd}/.pipen"
532
+
491
533
  if not self.config.workdir or not isinstance(
492
534
  AnyPath(self.config.workdir),
493
535
  GSPath,
@@ -498,8 +540,6 @@ class CliGbatchDaemon:
498
540
  )
499
541
  sys.exit(1)
500
542
 
501
- if "name" not in self.config or not self.config.name:
502
- self.config["name"] = "PipenCliGbatchDaemon"
503
543
 
504
544
  async def run(self): # pragma: no cover
505
545
  """Execute the daemon pipeline based on configuration.
@@ -804,22 +844,6 @@ class CliGbatchPlugin(CLIPlugin): # pragma: no cover
804
844
 
805
845
  setattr(known_parsed, key, val)
806
846
 
807
- mount_as_cwd = getattr(known_parsed, "mount_as_cwd", None)
808
- cwd = getattr(known_parsed, "cwd", None)
809
- delattr(known_parsed, "mount_as_cwd")
810
- if mount_as_cwd and cwd:
811
- print(
812
- "\033[1;4mError\033[0m: --mount-as-cwd and --cwd "
813
- "cannot be used together.\n"
814
- )
815
- sys.exit(1)
816
-
817
- mount = getattr(known_parsed, "mount", None) or []
818
- if mount_as_cwd:
819
- mount.append(f"{mount_as_cwd}:/mnt/disks/.cwd")
820
- setattr(known_parsed, "mount", mount)
821
- setattr(known_parsed, "cwd", "/mnt/disks/.cwd")
822
-
823
847
  return known_parsed
824
848
 
825
849
  def exec_command(self, args: Namespace) -> None:
@@ -133,7 +133,9 @@ flags = ["--mount-as-cwd"]
133
133
  type = "str"
134
134
  help = """The directory to mount as the current working directory of the command.
135
135
  This is a shortcut for `--mount <cloudpath>:/mnt/disks/.cwd --cwd /mnt/disks/.cwd`.
136
- The <cloudpath> must be a Google Storage Bucket path (gs://...).
136
+ The <cloudpath> must be a Google Storage Bucket path (gs://...). When this option is used,
137
+ and `--workdir` is not provided, the workdir will be set to `<cloudpath>/.pipen/<command_name>`,
138
+ where <command_name> is the name of the command (or the value of `--name` if provided).
137
139
  """
138
140
 
139
141
  [[groups.arguments]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipen-cli-gbatch
3
- Version: 0.0.5
3
+ Version: 0.0.7
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=xiYBNz3z3Eu8vmFECPFpOt1EE501T_gZx_iPUDajCd4,31309
2
+ pipen_cli_gbatch/daemon_args.toml,sha256=XrCDwTaJ7xPgGLtZev4qikjrZWqixdE8tqSsFnIvmjc,7381
3
+ pipen_cli_gbatch-0.0.7.dist-info/METADATA,sha256=pxmFaIpwMG6GU4wZF_1EBqtWa9l44KI-m1Lhi3TI1Dw,11301
4
+ pipen_cli_gbatch-0.0.7.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
5
+ pipen_cli_gbatch-0.0.7.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
+ pipen_cli_gbatch-0.0.7.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- pipen_cli_gbatch/__init__.py,sha256=2LBMKrJyLLGIjYbquvMyerJYXoD9WJzYgrLEM9yNwEE,30280
2
- pipen_cli_gbatch/daemon_args.toml,sha256=Yqty1vsNTUQKf411tFTExE1dGM5OHGYcI7ANQm0N-CQ,7170
3
- pipen_cli_gbatch-0.0.5.dist-info/METADATA,sha256=tD81_KwxU8f-H-AFV7hAAPDj_H8ay7zdG-u93Ezgfmc,11301
4
- pipen_cli_gbatch-0.0.5.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
5
- pipen_cli_gbatch-0.0.5.dist-info/entry_points.txt,sha256=Z9NLeCpRo-rb8wss5mB5TBcG-_RbdlPA49b8Ma5pvQA,57
6
- pipen_cli_gbatch-0.0.5.dist-info/RECORD,,