Skip to content

Commit

Permalink
Logging improvements (#1617)
Browse files Browse the repository at this point in the history
1. Reduce the susceptibility for circular imports.  Right now, there is an arc from logging -> types -> SpotFindingResults -> logging.
2. Add a method to decode an encoded log back into a Log object.
3. Expose Log as a top-level starfish construct. (i.e., in the `starfish` namespace)

Test plan: travvvvvvis.
  • Loading branch information
Tony Tung authored Oct 18, 2019
1 parent d2df275 commit 6c02128
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
entry_points={
'console_scripts': [
"starfish=starfish:starfish",
"starfish=starfish.core.starfish:starfish",
]
},
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion starfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from .core.intensity_table.decoded_intensity_table import DecodedIntensityTable
from .core.intensity_table.intensity_table import IntensityTable
from .core.segmentation_mask import SegmentationMaskCollection
from .core.starfish import starfish
from .core.util.logging import Log
20 changes: 14 additions & 6 deletions starfish/core/util/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import platform
from functools import lru_cache
from json import JSONEncoder
from typing import List, Mapping

import pkg_resources

# these are import statements and not from xxx import yyy to break a circular dependency.
import starfish.core
from starfish.core.types import CORE_DEPENDENCIES, LOG
import starfish.core.types


class Log:
Expand Down Expand Up @@ -35,7 +36,14 @@ def update_log(self, class_instance) -> None:
self._log.append(entry)

def encode(self):
return LogEncoder().encode({LOG: self.data})
return LogEncoder().encode({starfish.core.types.LOG: self._log})

@classmethod
def decode(cls, encoded_log: str):
log = json.loads(encoded_log)
log_object = Log()
log_object._log = log
return log_object

@property
def data(self):
Expand All @@ -45,7 +53,7 @@ def data(self):
@lru_cache(maxsize=1)
def get_core_dependency_info() -> Mapping[str, str]:
dependency_info = dict()
for dependency in CORE_DEPENDENCIES:
for dependency in starfish.core.types.CORE_DEPENDENCIES:
version = get_dependency_version(dependency)
dependency_info[dependency] = version
return dependency_info
Expand All @@ -69,7 +77,7 @@ def get_os_info() -> Mapping[str, str]:
"Python Version": platform.python_version()}


class LogEncoder(JSONEncoder):
class LogEncoder(json.JSONEncoder):
"""
JSON encodes the List[Dict] pipeline provence log. For simple
objects use default JSON encoding. For more complex objects
Expand All @@ -79,4 +87,4 @@ def default(self, o):
try:
return super(LogEncoder, self).default(o)
except TypeError:
return JSONEncoder().encode(repr(o))
return json.JSONEncoder().encode(repr(o))

0 comments on commit 6c02128

Please sign in to comment.