Skip to content

Commit

Permalink
move configure_logger to cythoninstallhelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxBo committed Dec 30, 2020
1 parent b780cfd commit 1488a47
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cythonarrays/src/cythonarrays/_version.py
@@ -1 +1 @@
__version__ = '1.3.9'
__version__ = '1.4.0'
3 changes: 0 additions & 3 deletions cythonarrays/src/cythonarrays/array_properties.py
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import xarray as xr
from cythonarrays.array_descriptors import ArrayDescriptor
from cythonarrays.configure_logger import get_logger


class _ArrayProperties:
Expand All @@ -22,8 +21,6 @@ def __init__(self, *args, **kwargs):
for descr in self.dtypes.values():
prop = self._create_prop(descr)
setattr(self.__class__, descr.name, prop)
# create Class logger
self.logger = get_logger(self)

def _create_prop(self, descr: ArrayDescriptor):
"""
Expand Down
5 changes: 0 additions & 5 deletions cythonarrays/src/cythonarrays/array_shapes.pyx
Expand Up @@ -13,8 +13,6 @@ from .numpy_types import typedict
from .numpy_types cimport np_floating, np_numeric
from .array_descriptors import ArrayDescriptor

from .configure_logger import get_logger

cimport cython
cdef extern from "numpy/npy_math.h":
bint npy_isnan(double x) nogil
Expand Down Expand Up @@ -50,9 +48,6 @@ cdef class ArrayShapes(object):
self.INF_d = np.float64(1) / np.float64(0)
self.NINF_d = np.float64(-1) / np.float64(0)

# create Class logger
self.logger = get_logger(self)

cdef char _isnan(self, np_floating x) nogil:
"""
check for nan
Expand Down
2 changes: 2 additions & 0 deletions cythonarrays/src/cythonarrays/tests/example_python.py
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict
import numpy as np

from cythoninstallhelpers.configure_logger import get_logger
from cythonarrays.array_properties import _ArrayProperties
import pyximport; pyximport.install()
from .example_cython import (_Example, DestinationChoiceError)
Expand Down Expand Up @@ -50,6 +51,7 @@ def __init__(self,
self.define_arrays()
if init_arrays:
self.init_arrays()
self.logger = get_logger(self)

def set_n_threads(self, threading=True):
"""Set the number of threads"""
Expand Down
2 changes: 1 addition & 1 deletion cythoninstallhelpers/src/cythoninstallhelpers/_version.py
@@ -1 +1 @@
__version__ = '1.1.5'
__version__ = '1.2.0'
@@ -1,4 +1,4 @@
from cythonarrays.configure_logger import get_logger
from cythoninstallhelpers.configure_logger import get_logger


def function_with_logging(msg: str):
Expand Down
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-

from cythonarrays.configure_logger import (SimLogger,
get_module_logger,
get_logger)
from cythoninstallhelpers.configure_logger import (SimLogger,
get_module_logger,
get_logger)
import os
import glob
from .module_with_logging import function_with_logging
from .example_python import _Example

from ..get_version import get_version

class Test01_Logger:
"""Test the the SimLogger"""
Expand All @@ -17,23 +16,30 @@ def test_01_log_something(self, tmpdir: str):
scenario = 'TestScenario_without_Packages'
sim_logger = SimLogger()
sim_logger.configure(LOG_FOLDER=tmpdir, scenario=scenario)
print(sim_logger.packages)

# assert that there are no packages registred with the logger
assert not sim_logger.packages

function_with_logging('Log something in function_with_logging without package')

# assert that cythonarrays is registred now
assert __package__.split('.')[0] in sim_logger.packages

logger = get_logger(self)
logger.info('Info in test_01')
logger.debug('Debug in test_01')
logger.warning('Warn in test_01')

logger = get_logger(_Example)
logger.warn('Logging for the cython module')
logger = get_logger(get_version)
logger.warn('Logging for a get_version function')

instance = 'A String'
logger = get_logger(instance)
logger.info('Logging for an str-instance form builtins without module')

print(sim_logger.packages)
# assert that cythonarrays is still registred
assert __package__.split('.')[0] in sim_logger.packages

logfiles = glob.glob(os.path.join(tmpdir, f'{scenario}*.log'))
assert logfiles
Expand Down

0 comments on commit 1488a47

Please sign in to comment.