Skip to content

Commit

Permalink
flexibly handle addition of direct use of logging CLI by pipeline aut…
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Jul 2, 2019
1 parent 6da4292 commit 1503fef
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
7 changes: 3 additions & 4 deletions docs/changelog.md
Expand Up @@ -3,22 +3,22 @@
## [0.12.0] -- unreleased
### Added
- Use profile to determine total elapsed time
- `logging` functions directly on `PipelineManager`
- Re-export `add_logging_options` from `logmuse`, for direct use by a pipeline author.
- `logger_via_cli` that defaults to the `strict=False` behavior of the same-named function from `logmuse`

## [0.11.3] -- 2019-06-17
### Fixed
- Fixed a bug that caused an OSError removing lock files for some filesystems.


## [0.11.2] -- 2019-06-06
### Fixed
- Elevate `attmap` depdendency bound to require inclusion of improved path expansion behavior.


## [0.11.1] -- 2019-05-30
### Fixed
- Elevate `attmap` dependency bound to require inclusion of a bugfix there.


## [0.11.0] -- 2019-05-13
- Improve python3 handling of integers and strings
- Fixed a bug with cleanup scripts in `dirty` mode
Expand All @@ -29,7 +29,6 @@
- Some performance improvements for ngstk functions
- Allow `ngstk.input_to_fastq` to yield gzipped fastq files


## [0.10.0] -- 2019-03-22
- Fixed a bug that raised exception with empty commands
- Fixed the pipeline profiling issues
Expand Down
3 changes: 3 additions & 0 deletions pypiper/__init__.py
Expand Up @@ -5,3 +5,6 @@
from .pipeline import *
from .exceptions import *
from .stage import *

# Implicitly re-export so logmuse usage by pipeline author routes through here.
from logmuse import add_logging_options
21 changes: 13 additions & 8 deletions pypiper/manager.py
Expand Up @@ -31,8 +31,8 @@
from .flags import *
from .utils import \
check_shell, checkpoint_filepath, clear_flags, default_pipeline_config, \
flag_name, get_proc_name, is_multi_target, make_lock_name, parse_cmd, \
pipeline_filepath, CHECKPOINT_SPECIFICATIONS
flag_name, get_proc_name, is_multi_target, logger_via_cli, make_lock_name, \
parse_cmd, pipeline_filepath, CHECKPOINT_SPECIFICATIONS
from .const import PROFILE_COLNAMES
from ._version import __version__
import __main__
Expand Down Expand Up @@ -321,13 +321,18 @@ def __init__(
self.config = None

logger_kwargs = logger_kwargs or {}
try:
name = logger_kwargs.pop("name")
except KeyError:
pass
default_logname = ".".join([__name__, self.__class__.__name__, self.name])
if not args:
# strict is only for logger_via_cli.
kwds = {k: v for k, v in logger_kwargs.items() if k != "strict"}
try:
name = kwds.pop("name")
except KeyError:
name = default_logname
self._logger = init_logger(name, **kwds)
else:
name = ".".join([__name__, self.__class__.__name__, self.name])
self._logger = init_logger(name, **logger_kwargs)
logger_kwargs.setdefault("name", default_logname)
self._logger = logger_via_cli(args, **logger_kwargs)

@property
def _completed(self):
Expand Down
18 changes: 17 additions & 1 deletion pypiper/utils.py
Expand Up @@ -30,7 +30,7 @@
# Conceptually, reserve this for functions expected to be used in other
# packages, and import from utils within pypiper for other functions.
__all__ = ["add_pypiper_args", "build_command", "check_all_commands",
"determine_uncallable", "get_first_value", "head"]
"determine_uncallable", "get_first_value", "head", "logger_via_cli"]


CHECKPOINT_SPECIFICATIONS = ["start_point", "stop_before", "stop_after"]
Expand Down Expand Up @@ -588,6 +588,22 @@ def is_sam_or_bam(file_name):
return ext in [".bam", ".sam"]


def logger_via_cli(opts, **kwargs):
"""
Build and initialize logger from CLI specification.
:param argparse.Namespace opts: parse of command-line interface
:param kwargs: keyword arguments to pass along to underlying logmuse function
:return logging.Logger: newly created and configured logger
"""
from copy import deepcopy
import logmuse
kwds = deepcopy(kwargs)
# By default, don't require the logging options to have been added to the parser.
kwds.setdefault("strict", False)
return logmuse.logger_via_cli(opts, **kwds)


def make_lock_name(original_path, path_base_folder):
"""
Create name for lock file from an absolute path.
Expand Down
2 changes: 1 addition & 1 deletion requirements/reqs-pypiper.txt
@@ -1,5 +1,5 @@
attmap>=0.12.5
logmuse>=0.2.0
logmuse>=0.2.1
psutil
pandas
ubiquerg>=0.4.5
Expand Down
3 changes: 2 additions & 1 deletion tests/test_packaging.py
Expand Up @@ -8,7 +8,8 @@


@pytest.mark.parametrize(["obj_name", "typecheck"], [
("check_all_commands", isfunction), ("determine_uncallable", isfunction)])
("add_logging_options", isfunction), ("check_all_commands", isfunction),
("determine_uncallable", isfunction), ("logger_via_cli", isfunction)])
def test_top_level_exports(obj_name, typecheck):
""" At package level, validate object availability and type. """
import pypiper
Expand Down

0 comments on commit 1503fef

Please sign in to comment.