pipen-cli-gbatch 0.0.5__py3-none-any.whl → 0.0.6__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.6"
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.
@@ -229,6 +249,12 @@ class CliGbatchDaemon:
229
249
  if command_outdir:
230
250
  self._add_mount(command_outdir, GbatchScheduler.MOUNTED_OUTDIR)
231
251
  self._replace_arg_in_command("outdir", GbatchScheduler.MOUNTED_OUTDIR)
252
+ elif self.mount_as_cwd:
253
+ command_name = self._get_arg_from_command("name") or self.config.name
254
+ self._replace_arg_in_command(
255
+ "outdir",
256
+ f"{MOUNTED_CWD}/{command_name}-output",
257
+ )
232
258
 
233
259
  def _infer_name(self):
234
260
  """Infer the daemon name from configuration or command arguments.
@@ -303,6 +329,7 @@ class CliGbatchDaemon:
303
329
  "version",
304
330
  "loglevel",
305
331
  "mounts",
332
+ "mount_as_cwd",
306
333
  "plain",
307
334
  )
308
335
  },
@@ -333,6 +360,7 @@ class CliGbatchDaemon:
333
360
  "version",
334
361
  "loglevel",
335
362
  "mounts",
363
+ "mount_as_cwd",
336
364
  "plain",
337
365
  ):
338
366
  continue
@@ -483,9 +511,9 @@ class CliGbatchDaemon:
483
511
  logger.setLevel(self.config.loglevel.upper())
484
512
 
485
513
  if not self.config.plain:
514
+ self._infer_name()
486
515
  self._handle_workdir()
487
516
  self._handle_outdir()
488
- self._infer_name()
489
517
  self._infer_jobname_prefix()
490
518
  else:
491
519
  if not self.config.workdir or not isinstance(
@@ -804,22 +832,6 @@ class CliGbatchPlugin(CLIPlugin): # pragma: no cover
804
832
 
805
833
  setattr(known_parsed, key, val)
806
834
 
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
835
  return known_parsed
824
836
 
825
837
  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.6
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=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,,
@@ -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,,