Skip to content

Commit 55eea51

Browse files
committed
Format comments
1 parent a545acf commit 55eea51

File tree

5 files changed

+57
-30
lines changed

5 files changed

+57
-30
lines changed

slicer_cli_web/singularity/slicer_cli_web_singularity/commands.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ def singularity_version():
1616
@staticmethod
1717
def singularity_pull(name: str, uri: str = 'docker'):
1818
"""
19-
This method is used to generate the command for the singualrity pull function for pulling images from online.
19+
This method is used to generate the command for the singualrity pull function for pulling
20+
images from online.
2021
Args:
21-
name(str.required) - Takes in a string that should specify the image name and tag as a single string '<image_name>:<tag>'
22-
uri(str, optional) - If you want to pull the images from other that Dockerhub, you need to pass in that uri as a string
22+
name(str.required) - image name and tag as a single string '<image_name>:<tag>'
23+
uri(str, optional) - image uri (necessary for Dockerhub)
2324
2425
Returns:
25-
A list of strings formatted to be supplied to the subprocess module of python that handles pull.
26+
List of strings for singularity subprocess command.
2627
"""
2728
sif_name = generate_image_name_for_singularity(name)
2829
return ['apptainer', 'pull', '--force', sif_name, f'{uri}://{name}']
@@ -54,8 +55,9 @@ def singularity_get_env(image: str, run_parameters=None):
5455
@staticmethod
5556
def singularity_inspect(imageName, option='-l', json_format=True):
5657
"""
57-
This function is used to get the apptainer command for inspecting the sif file. By default, it inspects the labels in a json format,
58-
but you can you any option allowed by apptainer by setting the option flag appropriately and also the json flag is set to True by default.
58+
This function is used to get the apptainer command for inspecting the sif file. By default,
59+
it inspects the labels in a json format, but you can you any option allowed by apptainer
60+
by setting the option flag appropriately and also the json flag is set to True by default.
5961
"""
6062
sif_name = generate_image_name_for_singularity(imageName)
6163
cmd = ['apptainer', 'inspect']

slicer_cli_web/singularity/slicer_cli_web_singularity/girder_worker_plugin/direct_singularity_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def __call__(self, *args, **kwargs):
2828

2929
def check_local_sif_image(image):
3030
"""
31-
Pulls the specified Plugin image (Ususally a docker image) onto the singularity container if the image is not present
31+
Pulls the specified Plugin image (Ususally a docker image) onto the singularity container
32+
if the image is not present
3233
"""
3334
# Image path - Image path has to be present in tmp/images folder
3435
if not image:

slicer_cli_web/singularity/slicer_cli_web_singularity/job.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ def is_valid_path(path):
2626

2727

2828
def is_singularity_installed(path=None):
29-
"""This function is used to check whether singularity is availble on the target system.
30-
This function is useful to make sure that singularity is accessible from a SLURM job submitted to HiperGator
29+
"""
30+
This function is used to check whether singularity is availble on the target system.
31+
This function is useful to make sure that singularity is accessible from a SLURM job submitted
32+
to HiperGator
3133
3234
Args:
33-
path (str, optional): If the user wants to provide a specific path where singularity is installed, you can provide that path. Defaults to None.
35+
path (str, optional): If the user wants to provide a specific path where singularity is
36+
installed, you can provide that path. Defaults to None.
3437
3538
Returns:
3639
bool: True if singualrity is successfully accessible on the target system. False otherwise
@@ -54,14 +57,16 @@ def is_singularity_installed(path=None):
5457

5558
def find_local_singularity_image(name: str, path=''):
5659
"""
57-
Check if the image is present locally on the system in a specified path. For our usecase, we insall the images to a specific path on /blue directory, which can be modified
58-
via the argument to the function
60+
Check if the image is present locally on the system in a specified path. For our usecase, we
61+
insall the images to a specific path on /blue directory, which can be modified via the argument
62+
to the function
5963
6064
Args:
6165
name(str, required) - The name of the docker image with the tag <image>:<tag>.
62-
path(str, optional) - This path refers to the path on the local file system designated for placing singularity images after they are pulled from the interweb.
66+
path(str, optional) - This path refers to the path on the local file system designated for
67+
placing singularity images after they are pulled from the interweb.
6368
Returns:
64-
bool: True if the singularity image is avaialble on the given path on the local host system. False otherwise.
69+
bool: True if singularity image is avaialble on the given path on host system. False otherwise.
6570
6671
"""
6772
try:
@@ -73,20 +78,24 @@ def find_local_singularity_image(name: str, path=''):
7378
path = os.getenv('SIF_IMAGE_PATH', '')
7479
if not is_valid_path(path):
7580
logger.exception(
76-
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and ensure the path has appropriate access')
81+
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and'
82+
'ensure the path has appropriate access')
7783
raise Exception(
78-
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and ensure the path has appropriate access')
84+
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and'
85+
'ensure the path has appropriate access')
7986
return os.path.exists(path + sif_name)
8087

8188

8289
def pull_image_and_convert_to_sif(names):
8390
"""
84-
This is the function similar to the pullDockerImage function that pulls the image from Dockerhub or other instances if it's supported in the future
91+
This is the function similar to the pullDockerImage function that pulls the image from
92+
Dockerhub or other instances if it's supported in the future
8593
Args:
86-
names(List(str), required) -> The list of image names of the format <img>:<tag> provided as a string
94+
names(List(str), required) -> The list of image names of the format <img>:<tag>
8795
8896
Raises:
89-
If pulling of any of the images fails, the function raises an error with the list of images that failed.
97+
If pulling of any of the images fails, the function raises an error with the list of images
98+
that failed.
9099
"""
91100
failedImageList = []
92101
for name in names:
@@ -209,7 +218,9 @@ def _get_last_workdir(imageName):
209218

210219
def get_local_singularity_output(imgName, cmdArg: str):
211220
"""
212-
This function is used to run the singularity command locally for non-resource intensive tasks such as getting schema, environment variables and so on and return that output to the calling function
221+
This function is used to run the singularity command locally for non-resource intensive tasks
222+
such as getting schema, environment variables and so on and return that output to the calling
223+
function
213224
"""
214225
try:
215226
pwd = _get_last_workdir(imgName)
@@ -235,9 +246,11 @@ def find_and_remove_local_sif_files(name: str, path=None):
235246
path = os.getenv('SIF_IMAGE_PATH', '')
236247
if not is_valid_path(path):
237248
logger.exception(
238-
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and ensure the path has appropriate access')
249+
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and'
250+
'ensure the path has appropriate access')
239251
raise Exception(
240-
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and ensure the path has appropriate access')
252+
'Please provide a valid path or set the environment variable "SIF_IMAGE_PATH" and'
253+
'ensure the path has appropriate access')
241254
filename = os.path.join(path, sif_name)
242255
if os.path.exists(filename):
243256
os.remove(filename)

slicer_cli_web/singularity/slicer_cli_web_singularity/singularity_image.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def _split(name):
3838

3939
class SingularityImage:
4040
"""
41-
This class is used to produce the Singularity equivalent of the Docker Image object as part of the Python SDK. This helps us to
42-
reuse all the functions where Docker is not not directly involved rather the snapshort of the Docker Image object should suffice to perform the necessaray operations
41+
This class is used to produce the Singularity equivalent of the Docker Image object as part
42+
of the Python SDK. This helps us to reuse all the functions where Docker is not not directly
43+
involved rather the snapshort of the Docker Image object should suffice to perform the
44+
necessaray operations
4345
"""
4446

4547
def __init__(self, local_sif_file: str):
@@ -182,7 +184,10 @@ def _create(name, singularity_image_object, user, baseFolder):
182184
creator=user, reuseExisting=True)
183185

184186
# add docker image labels as meta data
185-
labels = {} if not singularity_image_object.labels else singularity_image_object.labels.copy()
187+
labels = {}
188+
if singularity_image_object.labels:
189+
labels = singularity_image_object.labels.copy()
190+
186191
if 'description' in labels:
187192
tag['description'] = labels['description']
188193
del labels['description']

slicer_cli_web/singularity/slicer_cli_web_singularity/utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def sanitize_and_return_json(res: str):
66
"""
7-
This function tries to parse the given str as json in couple different ways. If the output is still not json or a python dictionary, it raises an error.
7+
This function tries to parse the given str as json in couple different ways. If the output is
8+
still not json or a python dictionary, it raises an error.
89
"""
910
try:
1011
res = json.loads(res)
@@ -26,7 +27,8 @@ def sanitize_and_return_json(res: str):
2627

2728
def is_valid_image_name_format(image_str: str):
2829
"""
29-
This function is used to validate whether the user supplied a valid string <img>:<tag> as an argument for functions like singularity pull
30+
This function is used to validate whether the user supplied a valid string <img>:<tag> as an
31+
argument for functions like singularity pull
3032
3133
Args:
3234
image_str(str, required) - The string that needs to be validated.
@@ -41,7 +43,8 @@ def is_valid_image_name_format(image_str: str):
4143

4244
def generate_image_name_for_singularity(image_str: str):
4345
"""
44-
We need to generate the image name for storing the .sif files on the filesystem so that it is standardized, so it can be referenced in future calls.
46+
We need to generate the image name for storing the .sif files on the filesystem so that it is
47+
standardized, so it can be referenced in future calls.
4548
4649
Args:
4750
image_str (str,required) - the image_name in the format <img>:<tag>
@@ -58,11 +61,14 @@ def generate_image_name_for_singularity(image_str: str):
5861

5962
def switch_to_sif_image_folder(image_path: str = ''):
6063
"""
61-
This function is used to handle Issues that is occuring when Singularity switches directory when running a plugin and not having the context of where the SIF IMAGES are located for subsequent image pulls.
64+
This function is used to handle Issues that is occuring when Singularity switches directory
65+
when running a plugin and not having the context of where the SIF IMAGES are located for
66+
subsequent image pulls.
6267
This function ensures that Singularity always looks for the plugins in the proper location
6368
6469
Args:
65-
image_path (str, optional) - This parameter is highly optional and is not recommended unless a specific use-case arises in the future
70+
image_path (str, optional) - This parameter is highly optional and is not recommended unless a
71+
specific use-case arises in the future
6672
6773
Returns:
6874
None

0 commit comments

Comments
 (0)