Skip to content

Commit

Permalink
Merge pull request #128 from andrewwhitehead/pre-release-0.3
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
swcurran authored Aug 9, 2019
2 parents 4476775 + 6933379 commit 8aeb552
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
name: Run Agent Tests
command: |
[ ! -d test-reports ] && mkdir test-reports
pytest
python -m pytest
- run:
name: Push to Codecov.io
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include aries_cloudagent/config/default_logging_config.ini
include requirements.txt
include requirements.dev.txt
include requirements.indy.txt
include README.md
51 changes: 42 additions & 9 deletions aries_cloudagent/config/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
"""Utilities related to logging."""

from logging import getLogger, FileHandler
import logging
from io import TextIOWrapper
from logging.config import fileConfig
from os import path
from typing import TextIO

import pkg_resources

from ..version import __version__


DEFAULT_LOGGING_CONFIG_PATH = "aries_cloudagent.config:default_logging_config.ini"


def load_resource(path: str, encoding: str = None) -> TextIO:
"""
Open a resource file located in a python package or the local filesystem.
Args:
path: The resource path in the form of `dir/file` or `package:dir/file`
Returns:
A file-like object representing the resource
"""
components = path.rsplit(":", 1)
try:
if len(components) == 1:
return open(components[0], encoding=encoding)
else:
bstream = pkg_resources.resource_stream(components[0], components[1])
if encoding:
return TextIOWrapper(bstream, encoding=encoding)
return bstream
except IOError:
pass


class LoggingConfigurator:
"""Utility class used to configure logging and print an informative start banner."""

Expand All @@ -28,19 +56,24 @@ def configure(
if logging_config_path is not None:
config_path = logging_config_path
else:
config_path = path.join(
path.dirname(path.abspath(__file__)), "default_logging_config.ini"
)
config_path = DEFAULT_LOGGING_CONFIG_PATH

fileConfig(config_path, disable_existing_loggers=False)
log_config = load_resource(config_path, "utf-8")
if log_config:
fileConfig(log_config, disable_existing_loggers=False)
else:
logging.basicConfig(level=logging.WARNING)
logging.root.warning(f"Logging config file not found: {config_path}")

if log_file:
getLogger().handlers.clear()
getLogger().handlers.append(FileHandler(log_file, encoding="utf-8"))
logging.root.handlers.clear()
logging.root.handlers.append(
logging.FileHandler(log_file, encoding="utf-8")
)

if log_level:
log_level = log_level.upper()
getLogger().setLevel(log_level)
logging.root.setLevel(log_level)

@classmethod
def print_banner(
Expand Down
20 changes: 13 additions & 7 deletions aries_cloudagent/config/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import contextlib
from io import StringIO
from unittest import mock
from asynctest import mock

from .. import logging as test_module

Expand All @@ -10,22 +10,28 @@ class TestLoggingConfigurator:
host_arg_value = "host"
port_arg_value = "port"

@mock.patch.object(test_module.path, "join")
@mock.patch.object(test_module, "load_resource", autospec=True)
@mock.patch.object(test_module, "fileConfig", autospec=True)
def test_configure_default(self, mock_file_config, mock_os_path_join):
def test_configure_default(self, mock_file_config, mock_load_resource):
test_module.LoggingConfigurator.configure()

mock_load_resource.assert_called_once_with(
test_module.DEFAULT_LOGGING_CONFIG_PATH, "utf-8"
)
mock_file_config.assert_called_once_with(
mock_os_path_join.return_value, disable_existing_loggers=False
mock_load_resource.return_value, disable_existing_loggers=False
)

@mock.patch.object(test_module.path, "join")
@mock.patch.object(test_module, "load_resource", autospec=True)
@mock.patch.object(test_module, "fileConfig", autospec=True)
def test_configure_path(self, mock_file_config, mock_os_path_join):
def test_configure_path(self, mock_file_config, mock_load_resource):
path = "a path"
test_module.LoggingConfigurator.configure(path)

mock_file_config.assert_called_once_with(path, disable_existing_loggers=False)
mock_load_resource.assert_called_once_with(path, "utf-8")
mock_file_config.assert_called_once_with(
mock_load_resource.return_value, disable_existing_loggers=False
)

def test_banner(self):
stdout = StringIO()
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Library version information."""

__version__ = "0.2.1"
__version__ = "0.3.0"
1 change: 1 addition & 0 deletions requirements.indy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3-indy>=1.11.0<2
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
version_meta = runpy.run_path("./{}/version.py".format(PACKAGE_NAME))
VERSION = version_meta["__version__"]


with open(os.path.abspath("./README.md"), "r") as fh:
long_description = fh.read()

Expand All @@ -28,6 +29,8 @@ def parse_requirements(filename):
include_package_data=True,
package_data={"aries_cloudagent": ["requirements.txt"]},
install_requires=parse_requirements("requirements.txt"),
tests_require=parse_requirements("requirements.dev.txt"),
extras_require={"indy": parse_requirements("requirements.indy.txt")},
python_requires=">=3.6.3",
scripts=["bin/aca-py"],
)

0 comments on commit 8aeb552

Please sign in to comment.