Skip to content

Commit 4e37673

Browse files
committed
adding first go at oci functions, needs lots of testing and more work!
1 parent f56cb1c commit 4e37673

21 files changed

Lines changed: 884 additions & 57 deletions

.circleci/config.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ install_python_2: &install_python_2
5757
fi
5858
5959
test_spython: &test_spython
60-
name: Test Singularity Python
60+
name: Test Singularity Python (Singularity Version 2 and 3)
6161
command: |
6262
cd ~/repo/spython
63-
ls
64-
export PATH=$PATH:/opt/circleci/.pyenv/shims
6563
$HOME/conda/bin/python -m unittest tests.test_client
6664
$HOME/conda/bin/python -m unittest tests.test_utils
65+
$HOME/conda/bin/python -m unittest tests.test_instances
66+
67+
test_spython_3: &test_spython_3
68+
name: Test Singularity Python (Singularity Version 3 Only)
69+
command: |
70+
cd ~/repo/spython
71+
$HOME/conda/bin/python -m unittest tests.test_oci
6772
6873
6974
jobs:

spython/instance/cmd/iutils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Copyright (C) 2017-2018 Vanessa Sochat.
2+
# Copyright (C) 2017-2019 Vanessa Sochat.
33

44
# This Source Code Form is subject to the terms of the
55
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
@@ -37,13 +37,13 @@ def get(self, name, return_json=False, quiet=False):
3737
'''get is a list for a single instance. It is assumed to be running,
3838
and we need to look up the PID, etc.
3939
'''
40-
from spython.utils import ( check_install, get_singularity_version )
40+
from spython.utils import check_install
4141
check_install()
4242

4343
# Ensure compatible for singularity prior to 3.0, and after 3.0
4444
subgroup = "instance.list"
4545

46-
if 'version 3' in get_singularity_version():
46+
if 'version 3' in self.version():
4747
subgroup = ["instance", "list"]
4848

4949
cmd = self._init_command(subgroup)

spython/instance/cmd/start.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11

2-
# Copyright (C) 2017-2018 Vanessa Sochat.
2+
# Copyright (C) 2017-2019 Vanessa Sochat.
33

44
# This Source Code Form is subject to the terms of the
55
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
66
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
77

88

99
from spython.logger import bot
10-
import sys
1110

1211
def start(self, image=None, name=None, args=None, sudo=False, options=[], capture=False):
1312
'''start an instance. This is done by default when an instance is created.
@@ -27,8 +26,7 @@ def start(self, image=None, name=None, args=None, sudo=False, options=[], captur
2726
2827
'''
2928
from spython.utils import ( run_command,
30-
check_install,
31-
get_singularity_version )
29+
check_install )
3230
check_install()
3331

3432
# If no name provided, give it an excellent one!
@@ -41,14 +39,13 @@ def start(self, image=None, name=None, args=None, sudo=False, options=[], captur
4139

4240
# Not having this means it was called as a command, without an image
4341
if not hasattr(self, "_image"):
44-
bot.error('Please provide an image, or create an Instance first.')
45-
sys.exit(1)
42+
bot.exit('Please provide an image, or create an Instance first.')
4643

4744
image = self._image
4845

4946
# Derive subgroup command based on singularity version
5047
subgroup = 'instance.start'
51-
if 'version 3' in get_singularity_version():
48+
if 'version 3' in self.version():
5249
subgroup = ["instance", "start"]
5350

5451
cmd = self._init_command(subgroup)

spython/instance/cmd/stop.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11

2-
# Copyright (C) 2017-2018 Vanessa Sochat.
2+
# Copyright (C) 2017-2019 Vanessa Sochat.
33

44
# This Source Code Form is subject to the terms of the
55
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
66
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
77

88

99
from spython.logger import bot
10-
import sys
1110

1211
def stop(self, name=None, sudo=False):
1312
'''stop an instance. This is done by default when an instance is created.
@@ -22,13 +21,12 @@ def stop(self, name=None, sudo=False):
2221
2322
'''
2423
from spython.utils import ( check_install,
25-
run_command,
26-
get_singularity_version )
24+
run_command )
2725
check_install()
2826

2927
subgroup = 'instance.stop'
3028

31-
if 'version 3' in get_singularity_version():
29+
if 'version 3' in self.version():
3230
subgroup = ["instance", "stop"]
3331

3432
cmd = self._init_command(subgroup)

spython/logger/message.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def __init__(self, MESSAGELEVEL=None):
5555

5656
def useColor(self):
5757
'''useColor will determine if color should be added
58-
to a print. Will check if being run in a terminal, and
59-
if has support for asci'''
58+
to a print. Will check if being run in a terminal, and
59+
if has support for ascii
60+
'''
6061
COLORIZE = get_user_color_preference()
6162
if COLORIZE is not None:
6263
return COLORIZE
@@ -70,7 +71,8 @@ def useColor(self):
7071

7172
def addColor(self, level, text):
7273
'''addColor to the prompt (usually prefix) if terminal
73-
supports, and specified to do so'''
74+
supports, and specified to do so
75+
'''
7476
if self.colorize:
7577
if level in self.colors:
7678
text = "%s%s%s" % (self.colors[level],
@@ -80,7 +82,8 @@ def addColor(self, level, text):
8082

8183
def emitError(self, level):
8284
'''determine if a level should print to
83-
stderr, includes all levels but INFO and QUIET'''
85+
stderr, includes all levels but INFO and QUIET
86+
'''
8487
if level in [ABORT,
8588
ERROR,
8689
WARNING,
@@ -242,6 +245,9 @@ def newline(self):
242245
def verbose(self, message):
243246
self.emit(VERBOSE, message, "VERBOSE")
244247

248+
def print(self, message):
249+
print(message)
250+
245251
def verbose1(self, message):
246252
self.emit(VERBOSE, message, "VERBOSE1")
247253

spython/main/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_client(quiet=False, debug=False):
1717
debug: turn on debugging mode
1818
1919
'''
20+
from spython.utils import get_singularity_version
2021
from .base import Client
2122

2223
Client.quiet = quiet
@@ -51,14 +52,21 @@ def get_client(quiet=False, debug=False):
5152
Client.instance = generate_instance_commands()
5253
Client.instance_stopall = stopall
5354

55+
# Commands Groups, OCI (Singularity version 3 and up)
56+
if "version 3" in get_singularity_version:
57+
from spython.oci.cmd import generate_oci_commands
58+
Client.oci = generate_oci_commands()
59+
5460
# Initialize
5561
cli = Client()
5662

5763
# Pass on verbosity
64+
cli.oci.debug = cli.debug
65+
cli.oci.quiet = cli.quiet
5866
cli.image.debug = cli.debug
5967
cli.image.quiet = cli.quiet
6068
cli.instance.debug = cli.debug
61-
cli.instance.quiet = cli.quiet
69+
cli.instance.quiet = cli.quiet
6270

6371
return cli
6472

spython/main/base/__init__.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88

99
from spython.logger import bot
10-
from spython.utils import check_install
10+
from spython.utils import check_install (
11+
check_install,
12+
get_singularity_version
13+
)
1114

1215
import json
1316
import sys
@@ -40,26 +43,11 @@ def __init__(self):
4043
'''
4144
self._init_level()
4245

43-
44-
def version(self):
45-
'''return the version of singularity
46-
'''
47-
48-
if not check_install():
49-
bot.warning("Singularity version not found, so it's likely not installed.")
50-
else:
51-
cmd = ['singularity','--version']
52-
version = self._run_command(cmd).strip('\n')
53-
bot.debug("Singularity %s being used." % version)
54-
return version
55-
56-
5746
def _check_install(self):
5847
'''ensure that singularity is installed, and exit if not.
5948
'''
6049
if check_install() is not True:
61-
bot.error("Cannot find Singularity! Is it installed?")
62-
sys.exit(1)
50+
bot.exit("Cannot find Singularity! Is it installed?")
6351

6452

6553

@@ -73,6 +61,7 @@ def _check_install(self):
7361
Client._generate_bind_list = generate_bind_list
7462
Client._init_command = init_command
7563
Client._run_command = run_command
64+
Client.version = get_singularity_version
7665

7766
# Flags and Logger
7867
Client._parse_verbosity = parse_verbosity

spython/main/execute.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,4 @@ def execute(self,
8484
return self._run_command(cmd,sudo=sudo)
8585
return stream_command(cmd, sudo=sudo)
8686

87-
8887
bot.error('Please include a command (list) to execute.')

spython/main/help.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
77

88

9-
from spython.logger import bot
10-
11-
import requests
12-
import shutil
13-
import sys
14-
import os
15-
16-
179
def help(self, command=None):
1810
'''help prints the general function help, or help for a specific command
1911

spython/main/inspect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from spython.logger import bot
1111
from spython.utils import (
1212
check_install,
13-
get_singularity_version,
1413
run_command
1514
)
1615

@@ -39,7 +38,7 @@ def inspect(self, image=None, json=True, app=None, quiet=True):
3938

4039
# After Singularity 3.0, helpfile was changed to H from
4140

42-
if "version 3" in get_singularity_version():
41+
if "version 3" in self.version():
4342
options = ['e','d','l','r','H','t']
4443

4544
[cmd.append('-%s' % x) for x in options]

0 commit comments

Comments
 (0)