Skip to content

Commit

Permalink
Pydocstyle and pylint updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Nilsson committed Dec 5, 2023
1 parent 89a0d76 commit 9d78972
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
40 changes: 23 additions & 17 deletions pilot/user/atlas/resource/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,30 @@
# Authors:
# - Paul Nilsson, [email protected], 2019-23

from pilot.util.container import execute
from pilot.common.errorcodes import ErrorCodes
from ..setup import get_asetup, get_asetup_options
"""Default grid resources."""

import logging
from typing import Any

from pilot.common.errorcodes import ErrorCodes
from pilot.util.container import execute
from ..setup import (
get_asetup,
get_asetup_options
)

logger = logging.getLogger(__name__)

errors = ErrorCodes()


def verify_setup_command(cmd):
def verify_setup_command(cmd: str) -> (int, str):
"""
Verify the setup command (containerised).
:param cmd: command string to be verified (string).
:return: pilot error code (int), diagnostics (string).
:param cmd: command string to be verified (str)
:return: pilot error code (int), diagnostics (str).
"""

diagnostics = ""

exit_code, stdout, stderr = execute(cmd, timeout=5 * 60)
Expand All @@ -52,32 +58,32 @@ def verify_setup_command(cmd):
return exit_code, diagnostics


def get_setup_command(job, prepareasetup):
def get_setup_command(job: Any, prepareasetup: bool = True) -> str:
"""
Return the path to asetup command, the asetup command itself and add the options (if desired).
If prepareasetup is False, the function will only return the path to the asetup script. It is then assumed
to be part of the job parameters.
:param job: job object.
:param prepareasetup: should the pilot prepare the asetup command itself? boolean.
:return:
:param job: job object (Any)
:param prepareasetup: should the pilot prepare the asetup command itself? (bool)
:return: command string (str).
"""

# if cvmfs is not available, assume that asetup is not needed
# note that there is an exception for sites (BOINC, some HPCs) that have cvmfs but still
# uses is_cvmfs=False.. these sites do not use containers, so check for that instead
if job.infosys.queuedata.is_cvmfs or not job.infosys.queuedata.container_type:
logger.debug('return asetup path as normal since: is_cvmfs=%s, job.container_type=%s' %
(job.infosys.queuedata.is_cvmfs, job.infosys.queuedata.container_type))
logger.debug(f'return asetup path as normal since: is_cvmfs={job.infosys.queuedata.is_cvmfs}, '
f'job.container_type={job.infosys.queuedata.container_type}')
else:
# if not job.infosys.queuedata.is_cvmfs:
logger.debug('will not return asetup path since: is_cvmfs=%s, job.container_type=%s' %
(job.infosys.queuedata.is_cvmfs, job.infosys.queuedata.container_type))
logger.debug(f'will not return asetup path since: is_cvmfs={job.infosys.queuedata.is_cvmfs}, '
f'job.container_type={job.infosys.queuedata.container_type}')
return ""

# return immediately if there is no release or if user containers are used
# if job.swrelease == 'NULL' or (('--containerImage' in job.jobparams or job.imagename) and job.swrelease == 'NULL'):
if job.swrelease == 'NULL' or job.swrelease == '':
if job.swrelease in {'NULL', ''}:
logger.debug('will not return asetup path since there is no swrelease set')
return ""

Expand Down
2 changes: 2 additions & 0 deletions pilot/user/atlas/resource/jumbojobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
#
# Authors:
# - Paul Nilsson, [email protected], 2019-23

"""Resource related functions for jumbo jobs (nothing so far)."""
30 changes: 17 additions & 13 deletions pilot/user/atlas/resource/manytoone.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,50 @@
# Authors:
# - Paul Nilsson, [email protected], 2019-23

"""Resource related functions for many-to-one jobs."""

import logging
import os
from typing import Any

# from pilot.util.container import execute
from pilot.common.errorcodes import ErrorCodes

import logging
logger = logging.getLogger(__name__)

errors = ErrorCodes()


def verify_setup_command(cmd):
def verify_setup_command(cmd: str) -> (int, str):
"""
Verify the setup command.
:param cmd: command string to be verified (string).
:return: pilot error code (int), diagnostics (string).
:param cmd: command string to be verified (str)
:return: pilot error code (int), diagnostics (str).
"""
if not cmd:
logger.debug('cmd is not used by this function')

ec = 0
diagnostics = ""
return 0, ""

return ec, diagnostics


def get_setup_command(job, prepareasetup):
def get_setup_command(job: Any, prepareasetup: bool) -> str:
"""
Return the path to asetup command, the asetup command itself and add the options (if desired).
If prepareasetup is False, the function will only return the path to the asetup script. It is then assumed
to be part of the job parameters.
Handle the case where environmental variables are set -
HARVESTER_CONTAINER_RELEASE_SETUP_FILE, HARVESTER_LD_LIBRARY_PATH, HARVESTER_PYTHONPATH
This will create the string need for the pilot to execute to setup the environment.
:param job: job object.
:param prepareasetup: not used.
:return: setup command (string).
:param job: job object (Any)
:param prepareasetup: not used (bool)
:return: setup command (str).
"""

if not prepareasetup:
logger.debug('prepareasetup is not used by this function')
cmd = ""

# return immediately if there is no release or if user containers are used
Expand Down
27 changes: 15 additions & 12 deletions pilot/user/atlas/resource/nersc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,49 @@
# Authors:
# - Paul Nilsson, [email protected], 2019-23

"""Resource related functions for NERSC."""

import logging
import os
from typing import Any

# from pilot.util.container import execute
from pilot.common.errorcodes import ErrorCodes

import logging
logger = logging.getLogger(__name__)

errors = ErrorCodes()


def verify_setup_command(cmd):
def verify_setup_command(cmd: str) -> (int, str):
"""
Verify the setup command.
:param cmd: command string to be verified (string).
:return: pilot error code (int), diagnostics (string).
"""
if not cmd:
logger.debug('cmd is not used by this function')

ec = 0
diagnostics = ""
return 0, ""

return ec, diagnostics


def get_setup_command(job, prepareasetup):
def get_setup_command(job: Any, prepareasetup: bool) -> str:
"""
Return the path to asetup command, the asetup command itself and add the options (if desired).
If prepareasetup is False, the function will only return the path to the asetup script. It is then assumed
to be part of the job parameters.
Handle the case where environmental variables are set -
HARVESTER_CONTAINER_RELEASE_SETUP_FILE, HARVESTER_LD_LIBRARY_PATH, HARVESTER_PYTHONPATH
This will create the string need for the pilot to execute to setup the environment.
:param job: job object.
:param prepareasetup: not used.
:return: setup command (string).
:param job: job object (Any)
:param prepareasetup: not used (bool)
:return: setup command (str).
"""

if not prepareasetup:
logger.debug('prepareasetup is not used by this function')
cmd = ""

# return immediately if there is no release or if user containers are used
Expand Down

0 comments on commit 9d78972

Please sign in to comment.