Skip to content

Commit

Permalink
feat: Use logger instead of print(), closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 23, 2023
1 parent 809c1e1 commit c8a35a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

* Use Python's logging module instead of ``print()``.
* Add support for recent Python versions.
* Drop support for end-of-life Python versions.

Expand Down
7 changes: 5 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ Each analysis function must accept a ``data`` argument, which is a :class:`dict`
# Load the data
with open('example.csv') as f:
reader = csv.DictReader(f, fieldnames=['name', 'salary'])
reader.next()
next(reader)
data['table'] = list(reader)
def filter_rows(row):
return int(row['salary']) < 25000
def select_rows(data):
# Select relevant rows from the table
data['low_income'] = filter(lambda r: int(r['salary']) < 25000, data['table'])
data['low_income'] = list(filter(filter_rows, data['table']))
def calculate_average(data):
# The average of a value in the rows is taken
Expand Down
8 changes: 6 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ def load_data(data):
# Load the data
with open('example.csv') as f:
reader = csv.DictReader(f, fieldnames=['name', 'salary'])
reader.next()
next(reader)
data['table'] = list(reader)


def filter_rows(row):
return int(row['salary']) < 25000


def select_rows(data):
# Select relevant rows from the table
data['low_income'] = filter(lambda r: int(r['salary']) < 20000, data['table'])
data['low_income'] = list(filter(filter_rows, data['table']))


def calculate_average(data):
Expand Down
15 changes: 11 additions & 4 deletions proof/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
import bz2
import hashlib
import inspect
import logging
import pickle
import os
from copy import deepcopy
from glob import glob

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
logger.addHandler(ch)


class Cache:
"""
Expand Down Expand Up @@ -172,15 +179,15 @@ def run(self, refresh=False, _parent_cache=None):
do_not_cache = getattr(self._func, 'never_cache', False)

if refresh is True:
print('Refreshing: %s' % self._name)
logger.info('Refreshing: %s' % self._name)
elif do_not_cache:
refresh = True

print('Never cached: %s' % self._name)
logger.info('Never cached: %s' % self._name)
elif not self._cache.check():
refresh = True

print('Stale cache: %s' % self._name)
logger.info('Stale cache: %s' % self._name)

if refresh:
if _parent_cache:
Expand All @@ -193,7 +200,7 @@ def run(self, refresh=False, _parent_cache=None):
if not do_not_cache:
self._cache.set(local_data)
else:
print('Deferring to cache: %s' % self._name)
logger.info('Deferring to cache: %s' % self._name)

for analysis in self._child_analyses:
analysis.run(refresh=refresh, _parent_cache=self._cache)
Expand Down

0 comments on commit c8a35a3

Please sign in to comment.