Skip to content

Commit

Permalink
Pydocstyle updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Nilsson committed Nov 1, 2023
1 parent 7c0e9d0 commit 45f62b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
#
# Authors:
# - Paul Nilsson, [email protected], 2020-23

"""Default init."""
39 changes: 14 additions & 25 deletions pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# - Daniel Drizhuk, [email protected], 2017
# - Paul Nilsson, [email protected], 2017-23

"""This is the entry point for the PanDA Pilot, executed with 'python3 pilot.py <args>'."""

from __future__ import print_function # Python 2 (2to3 complains about this)
from __future__ import absolute_import

Expand Down Expand Up @@ -75,12 +77,10 @@

def main() -> int:
"""
Main function of PanDA Pilot 2.
Prepare for and execute the requested workflow.
:return: exit code (int).
"""

# get the logger
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -154,12 +154,11 @@ def main() -> int:

def str2bool(var: str) -> bool:
"""
Helper function to convert string to bool.
Convert string to bool.
:param var: string to be converted to bool (str)
:return: converted string (bool).
"""

if isinstance(var, bool): # does this ever happen?
return var

Expand All @@ -179,7 +178,6 @@ def get_args() -> Any:
:return: args (arg parser object - type <class 'argparse.Namespace'>).
"""

arg_parser = argparse.ArgumentParser()

# pilot log creation
Expand Down Expand Up @@ -468,12 +466,12 @@ def get_args() -> Any:
def create_main_work_dir() -> (int, str):
"""
Create and return the pilot's main work directory.
The function also sets args.mainworkdir and cd's into this directory.
Note: args, used in this function, is defined in outer scope.
:return: exit code (int), main work directory (string).
"""

exitcode = 0

if args.workdir != "":
Expand All @@ -494,13 +492,13 @@ def create_main_work_dir() -> (int, str):
return exitcode, _mainworkdir


def set_environment_variables() -> None:
def set_environment_variables():
"""
Set environment variables. To be replaced with singleton implementation.
Set relevant environment variables.
This function sets PILOT_WORK_DIR, PILOT_HOME, PILOT_SITENAME, PILOT_USER and PILOT_VERSION and others.
Note: args and mainworkdir, used in this function, are defined in outer scope.
"""

# working directory as set with a pilot option (e.g. ..)
environ['PILOT_WORK_DIR'] = args.workdir # TODO: replace with singleton

Expand Down Expand Up @@ -552,13 +550,11 @@ def set_environment_variables() -> None:
def wrap_up() -> int:
"""
Perform cleanup and terminate logging.
Note: args and mainworkdir, used in this function, are defined in outer scope.
:return: exit code (int).
"""

exitcode = 0

# cleanup pilot workdir if created
if args.sourcedir != mainworkdir and args.cleanup:
chdir(args.sourcedir)
Expand Down Expand Up @@ -614,7 +610,6 @@ def get_pilot_source_dir() -> str:
:return: full path to pilot source directory (string).
"""

cwd = getcwd()
if exists(join(join(cwd, 'pilot3'), 'pilot.py')): # in case wrapper has untarred src as pilot3 in init dir
cwd = join(cwd, 'pilot3')
Expand All @@ -624,6 +619,7 @@ def get_pilot_source_dir() -> str:
def send_worker_status(status: str, queue: str, url: str, port: str, logger: Any, internet_protocol_version: str) -> None:
"""
Send worker info to the server to let it know that the worker has started.
Note: the function can fail, but if it does, it will be ignored.
:param status: 'started' or 'finished' (string).
Expand All @@ -633,7 +629,6 @@ def send_worker_status(status: str, queue: str, url: str, port: str, logger: Any
:param logger: logging object.
:param internet_protocol_version: internet protocol version, IPv4 or IPv6 (string).
"""

# worker node structure to be sent to the server
data = {}
data['workerID'] = os.environ.get('HARVESTER_WORKER_ID', None)
Expand All @@ -648,11 +643,8 @@ def send_worker_status(status: str, queue: str, url: str, port: str, logger: Any
logger.warning('workerID/harvesterID not known, will not send worker status to server')


def set_lifetime() -> None:
"""
Update the pilot lifetime if set by an environment variable (PANDAPILOT_LIFETIME) (in seconds).
"""

def set_lifetime():
"""Update the pilot lifetime if set by an environment variable (PANDAPILOT_LIFETIME) (in seconds)."""
lifetime = os.environ.get('PANDAPILOT_LIFETIME', None)
if lifetime:
try:
Expand All @@ -663,12 +655,12 @@ def set_lifetime() -> None:
args.lifetime = _lifetime


def set_redirectall() -> None:
def set_redirectall():
"""
Set args redirectall field.
Currently not used.
"""

redirectall = os.environ.get('PANDAPILOT_REDIRECTALL', False)
if not redirectall:
try:
Expand All @@ -679,13 +671,12 @@ def set_redirectall() -> None:
args.redirectall = redirectall


def list_zombies() -> None:
def list_zombies():
"""
Make sure there are no remaining defunct processes still lingering.
Note: can be used to find zombies, but zombies can't be killed..
"""

found = find_defunct_subprocesses(os.getpid())
if found:
logging.info(f'found these defunct processes: {found}')
Expand All @@ -694,8 +685,6 @@ def list_zombies() -> None:


if __name__ == '__main__':
# Main function of pilot module.

# get the args from the arg parser
args = get_args()
args.last_heartbeat = time.time()
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# - Fernando Barreiro Megino, [email protected], 2019
# - Paul Nilsson, [email protected], 2019-23

"""Setup module for pip installation."""

import sys

from setuptools import setup, find_packages
Expand Down

0 comments on commit 45f62b8

Please sign in to comment.