Skip to content

Commit

Permalink
Merge pull request #33 from pepkit/dev
Browse files Browse the repository at this point in the history
0.3.3
  • Loading branch information
nsheff authored Jun 14, 2019
2 parents 56b436b + 3c72816 commit 3813a40
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 375 deletions.
96 changes: 0 additions & 96 deletions divvy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"""

import logging
import os
from sys import stdout

from ._version import __version__
from .compute import ComputingConfiguration
from .const import *
Expand All @@ -19,101 +16,8 @@
__classes__ = ["ComputingConfiguration"]
__all__ = __classes__ + [write_submit_script.__name__]

LOGGING_LEVEL = "INFO"
LOGGING_LOCATIONS = (stdout, )

# Default user logging format is simple
DEFAULT_LOGGING_FMT = "%(message)s"
# Developer logger format is more information-rich
DEV_LOGGING_FMT = "%(module)s:%(lineno)d (%(funcName)s) [%(levelname)s] > %(message)s "


# Ensure that we have a handler and don't get a logging exception.
# Note that this was originally with looper.models.
_LOGGER = logging.getLogger(__name__)
if not logging.getLogger().handlers:
_LOGGER.addHandler(logging.NullHandler())


def setup_divvy_logger(level, additional_locations=None, devmode=False):
"""
Establish project logger..
:param int | str level: logging level
:param tuple(str | FileIO[str]) additional_locations: supplementary
destination(s) to which to ship logs
:param bool devmode: whether to use developer logging config
:return logging.Logger: project-root logger
"""

logging.addLevelName(5, "VERY_FINE")

fmt = DEV_LOGGING_FMT if devmode else DEFAULT_LOGGING_FMT

# Establish the logger.
logger = logging.getLogger("divvy")
# First remove any previously-added handlers
logger.handlers = []
logger.propagate = False

# Handle int- or text-specific logging level.
try:
level = int(level)
except ValueError:
level = level.upper()

try:
logger.setLevel(level)
except Exception:
logging.error("Can't set logging level to %s; instead using: '%s'",
str(level), str(LOGGING_LEVEL))
level = LOGGING_LEVEL
logger.setLevel(level)

# Process any additional locations.
locations_exception = None
where = LOGGING_LOCATIONS
if additional_locations:
if isinstance(additional_locations, str):
additional_locations = (additional_locations, )
try:
where = LOGGING_LOCATIONS + tuple(additional_locations)
except TypeError as e:
locations_exception = e
if locations_exception:
logging.warn("Could not interpret {} as supplementary root logger "
"target destinations; using {} as root logger location(s)".
format(additional_locations, LOGGING_LOCATIONS))

# Add the handlers.
formatter = logging.Formatter(fmt=(fmt or DEFAULT_LOGGING_FMT))
for loc in where:
if isinstance(loc, str):
# File destination
dirpath = os.path.abspath(os.path.dirname(loc))
if not os.path.exists(dirpath):
os.makedirs(dirpath)
handler_type = logging.FileHandler
elif hasattr(loc, "write"):
# Stream destination
handler_type = logging.StreamHandler
else:
# Strange supplementary destination
logging.info("{} as logs destination appears to be neither "
"a filepath nor a stream.".format(loc))
continue

if handler_type is logging.FileHandler:
handler = handler_type(loc, mode='w')
else:
handler = handler_type(loc)

handler.setLevel(level)
handler.setFormatter(formatter)
logger.addHandler(handler)

return logger


# Default
setup_divvy_logger("INFO")
3 changes: 1 addition & 2 deletions divvy/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = "0.3.2"

__version__ = "0.3.3"
14 changes: 4 additions & 10 deletions divvy/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,12 @@ def main():

subparsers = parser.add_subparsers(dest="command")


def add_subparser(cmd):
# Individual subcommands
msg_by_cmd = {
"list": "List available compute packages",
"write": "Write a submit script"
}
def add_subparser(cmd, description):
return subparsers.add_parser(
cmd, description=msg_by_cmd[cmd], help=msg_by_cmd[cmd])
cmd, description=description, help=description)

write_subparser = add_subparser("write")
list_subparser = add_subparser("list")
write_subparser = add_subparser("write", "Write a submit script")
list_subparser = add_subparser("list", "List available compute packages")

write_subparser.add_argument(
"-S", "--settings",
Expand Down
Loading

0 comments on commit 3813a40

Please sign in to comment.