Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to
singularity on pypi), and the versions here will coincide with these releases.

## [master](https://github.com/singularityhub/singularity-cli/tree/master)
- add singularity options parameters to send to singularity (0.0.79)
- add support for library:// urls (0.0.78)
- instance stop with timeout argument (0.0.77)
- instance list includes ip address (0.0.76)
Expand Down
6 changes: 3 additions & 3 deletions spython/image/cmd/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
from spython.logger import bot


def create(self, image_path, size=1024, sudo=False):
def create(self, image_path, size=1024, sudo=False, singularity_options=None):
"""create will create a a new image

Parameters
==========
image_path: full path to image
size: image sizein MiB, default is 1024MiB
filesystem: supported file systems ext3/ext4 (ext[2/3]: default ext3

singularity_options: a list of options to provide to the singularity client
"""
from spython.utils import check_install

check_install()

cmd = self.init_command("image.create")
cmd = self.init_command("image.create", singularity_options)
cmd = cmd + ["--size", str(size), image_path]

output = self.run_command(cmd, sudo=sudo)
Expand Down
4 changes: 2 additions & 2 deletions spython/instance/cmd/iutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_table(table_string, header, remove_rows=1):
return parsed


def get(self, name, return_json=False, quiet=False):
def get(self, name, return_json=False, quiet=False, singularity_options=None):
"""get is a list for a single instance. It is assumed to be running,
and we need to look up the PID, etc.
"""
Expand All @@ -49,7 +49,7 @@ def get(self, name, return_json=False, quiet=False):
if "version 3" in self.version():
subgroup = ["instance", "list"]

cmd = self._init_command(subgroup)
cmd = self._init_command(subgroup, singularity_options)

cmd.append(name)
output = self.run_command(cmd, quiet=True)
Expand Down
12 changes: 10 additions & 2 deletions spython/instance/cmd/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@


def start(
self, image=None, name=None, args=None, sudo=False, options=None, capture=False
self,
image=None,
name=None,
args=None,
sudo=False,
options=None,
capture=False,
singularity_options=None,
):
"""start an instance. This is done by default when an instance is created.

Expand All @@ -20,6 +27,7 @@ def start(
sudo: if the user wants to run the command with sudo
capture: capture output, default is False. With True likely to hang.
args: arguments to provide to the instance (supported Singularity 3.1+)
singularity_options: a list of options to provide to the singularity client
options: a list of tuples, each an option to give to the start command
[("--bind", "/tmp"),...]

Expand Down Expand Up @@ -49,7 +57,7 @@ def start(
if "version 3" in self.version():
subgroup = ["instance", "start"]

cmd = self._init_command(subgroup)
cmd = self._init_command(subgroup, singularity_options)

# Add options, if they are provided
if not isinstance(options, list):
Expand Down
5 changes: 3 additions & 2 deletions spython/instance/cmd/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from spython.logger import bot


def stop(self, name=None, sudo=False, timeout=None):
def stop(self, name=None, sudo=False, timeout=None, singularity_options=None):
"""stop an instance. This is done by default when an instance is created.

Parameters
==========
name: a name for the instance
sudo: if the user wants to run the command with sudo
singularity_options: a list of options to provide to the singularity client
timeout: forcebly kill non-stopped instance after the
timeout specified in seconds

Expand All @@ -33,7 +34,7 @@ def stop(self, name=None, sudo=False, timeout=None):
if timeout:
subgroup += ["-t", str(timeout)]

cmd = self._init_command(subgroup)
cmd = self._init_command(subgroup, singularity_options)

# If name is provided assume referencing an instance
instance_name = self.name
Expand Down
3 changes: 2 additions & 1 deletion spython/main/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def apps(self, image=None, full_path=False, root=""):
return list of SCIF apps in image. The Singularity software serves
a scientific filesystem integration that will install apps to
/scif/apps and associated data to /scif/data. For more information
about SCIF, see https://sci-f.github.io
about SCIF, see https://sci-f.github.io. Note that this seems
to be deprecated in Singularity 3.x.

Parameters
==========
Expand Down
6 changes: 3 additions & 3 deletions spython/main/base/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def init_command(self, action, flags=None):
Parameters
==========
action: the main action to perform (e.g., build)
flags: one or more additional flags (e.g, volumes)
not implemented yet.
flags: one or more additional singularity options
"""
flags = flags or []

if not isinstance(action, list):
action = [action]
cmd = ["singularity"] + action
cmd = ["singularity"] + flags + action

if self.quiet:
cmd.insert(1, "--quiet")
Expand Down
7 changes: 4 additions & 3 deletions spython/main/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def build(
quiet=False,
return_result=False,
sudo_options=None,
singularity_options=None,
):

"""build a singularity image, optionally for an isolated build
Expand All @@ -53,18 +54,18 @@ def build(
sudo: give sudo to the command (or not) default is True for build
sudo_options: options to pass to sudo (e.g. --preserve-env=SINGULARITY_CACHEDIR,SINGULARITY_TMPDIR)
options: for all other options, specify them in this list.
singularity_options: a list of options to provide to the singularity client
quiet: quiet verbose printing from the client.
return_result: if True, return complete error code / message dictionary
"""
from spython.utils import check_install

check_install()

cmd = self._init_command("build")
cmd = self._init_command("build", singularity_options)

# If no extra options
if not options:
options = []
options = options or []

if "version 3" in self.version():
ext = "sif"
Expand Down
8 changes: 6 additions & 2 deletions spython/main/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def execute(
nv=False,
return_result=False,
options=None,
singularity_options=None,
sudo=False,
quiet=True,
):
Expand All @@ -38,6 +39,7 @@ def execute(
contain: This option disables the automatic sharing of writable
filesystems on your host
options: an optional list of options to provide to execute.
singularity_options: a list of options to provide to the singularity client
bind: list or single string of bind paths.
This option allows you to map directories on your host system to
directories within your container using bind mounts
Expand All @@ -49,7 +51,7 @@ def execute(

check_install()

cmd = self._init_command("exec")
cmd = self._init_command("exec", singularity_options)

# nv option leverages any GPU cards
if nv:
Expand Down Expand Up @@ -113,6 +115,7 @@ def shell(
bind=None,
nv=False,
options=None,
singularity_options=None,
sudo=False,
):
""" shell into a container. A user is advised to use singularity to do
Expand All @@ -127,6 +130,7 @@ def shell(
contain: This option disables the automatic sharing of writable
filesystems on your host
options: an optional list of options to provide to shell.
singularity_options: a list of options to provide to the singularity client
bind: list or single string of bind paths.
This option allows you to map directories on your host system to
directories within your container using bind mounts
Expand All @@ -136,7 +140,7 @@ def shell(

check_install()

cmd = self._init_command("shell")
cmd = self._init_command("shell", singularity_options)

# nv option leverages any GPU cards
if nv:
Expand Down
35 changes: 30 additions & 5 deletions spython/main/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
import os


def export(self, image_path, pipe=False, output_file=None, command=None, sudo=False):
def export(
self,
image_path,
pipe=False,
output_file=None,
command=None,
sudo=False,
singularity_options=None,
):

"""export will export an image, sudo must be used. If we have Singularity
versions after 3, export is replaced with building into a sandbox.
Expand All @@ -20,6 +28,7 @@ def export(self, image_path, pipe=False, output_file=None, command=None, sudo=Fa
==========
image_path: full path to image
pipe: export to pipe and not file (default, False)
singularity_options: a list of options to provide to the singularity client
output_file: if pipe=False, export tar to this file. If not specified,
will generate temporary directory.
"""
Expand All @@ -39,19 +48,35 @@ def export(self, image_path, pipe=False, output_file=None, command=None, sudo=Fa
output_file = self._get_filename(basename, "sandbox", pwd=False)

return self.build(
recipe=image_path, image=output_file, sandbox=True, force=True, sudo=sudo
recipe=image_path,
image=output_file,
sandbox=True,
force=True,
sudo=sudo,
singularity_options=singularity_options,
)

# If not version 3, run deprecated command
elif "2.5" in self.version():
return self._export(
image_path=image_path, pipe=pipe, output_file=output_file, command=command
image_path=image_path,
pipe=pipe,
output_file=output_file,
command=command,
singularity_options=singularity_options,
)

bot.warning("Unsupported version of Singularity, %s" % self.version())


def _export(self, image_path, pipe=False, output_file=None, command=None):
def _export(
self,
image_path,
pipe=False,
output_file=None,
command=None,
singularity_options=None,
):
""" the older deprecated function, running export for previous
versions of Singularity that support it

Expand All @@ -69,7 +94,7 @@ def _export(self, image_path, pipe=False, output_file=None, command=None):

"""
sudo = True
cmd = self._init_command("export")
cmd = self._init_command("export", singularity_options)

# If the user has specified export to pipe, we don't need a file
if pipe:
Expand Down
7 changes: 5 additions & 2 deletions spython/main/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from spython.utils import check_install, run_command


def inspect(self, image=None, json=True, app=None, quiet=True):
def inspect(
self, image=None, json=True, app=None, quiet=True, singularity_options=None
):
"""inspect will show labels, defile, runscript, and tests for an image

Parameters
Expand All @@ -19,6 +21,7 @@ def inspect(self, image=None, json=True, app=None, quiet=True):
json: print json instead of raw text (default True)
quiet: Don't print result to the screen (default True)
app: if defined, return help in context of an app
singularity_options: a list of options to provide to the singularity client

"""
check_install()
Expand All @@ -31,7 +34,7 @@ def inspect(self, image=None, json=True, app=None, quiet=True):
if not image:
bot.exit("Please provide an image to inspect.")

cmd = self._init_command("inspect")
cmd = self._init_command("inspect", singularity_options)
if app:
cmd = cmd + ["--app", app]

Expand Down
16 changes: 12 additions & 4 deletions spython/main/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
from spython.utils import run_command


def list_instances(self, name=None, return_json=False, quiet=False, sudo=False):
def list_instances(
self,
name=None,
return_json=False,
quiet=False,
sudo=False,
singularity_options=None,
):
"""list instances. For Singularity, this is provided as a command sub
group.

Expand All @@ -22,6 +29,7 @@ def list_instances(self, name=None, return_json=False, quiet=False, sudo=False):
==========
return_json: return a json list of instances instead of objects (False)
name: if defined, return the list for just one instance (used to ged pid)
singularity_options: a list of options to provide to the singularity client

Return Code -- Reason
0 -- Instances Found
Expand All @@ -39,7 +47,7 @@ def list_instances(self, name=None, return_json=False, quiet=False, sudo=False):
if "version 3" in self.version():
subgroup = ["instance", "list"]

cmd = self._init_command(subgroup)
cmd = self._init_command(subgroup, singularity_options)

# If the user has provided a name, we want to see a particular instance
if name is not None:
Expand Down Expand Up @@ -103,7 +111,7 @@ def list_instances(self, name=None, return_json=False, quiet=False, sudo=False):
return instances


def stopall(self, sudo=False, quiet=True):
def stopall(self, sudo=False, quiet=True, singularity_options=None):
"""stop ALL instances. This command is only added to the command group
as it doesn't make sense to call from a single instance

Expand All @@ -122,7 +130,7 @@ def stopall(self, sudo=False, quiet=True):
if "version 3" in self.version():
subgroup = ["instance", "stop"]

cmd = self._init_command(subgroup)
cmd = self._init_command(subgroup, singularity_options)
cmd = cmd + ["--all"]
output = run_command(cmd, sudo=sudo, quiet=quiet)

Expand Down
4 changes: 3 additions & 1 deletion spython/main/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ def pull(
capture=False,
stream=False,
quiet=False,
singularity_options=None,
):

"""pull will pull a singularity hub or Docker image

Parameters
==========
image: the complete image uri. If not provided, the client loaded is used
singularity_options: a list of options to provide to the singularity client
pull_folder: if not defined, pulls to $PWD (''). If defined, pulls to
user specified location instead.

Expand All @@ -41,7 +43,7 @@ def pull(

check_install()

cmd = self._init_command("pull")
cmd = self._init_command("pull", singularity_options)

# Quiet is honored if set by the client, or user
quiet = quiet or self.quiet
Expand Down
Loading