Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.2.1 #371

Merged
merged 7 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-02-05 Release 5.2.1
- make logup log level configurable via environment variable

2024-01-10 Release 5.2
- update URLs for test files on GitHub
- fixed bug in aggregators that excluded tag patterns ending in "!"
Expand Down
2 changes: 1 addition & 1 deletion hxl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
if sys.version_info < (3,):
raise RuntimeError("libhxl requires Python 3 or higher")

__version__="5.2"
__version__="5.2.1"
"""Module version number
see https://www.python.org/dev/peps/pep-0396/
"""
Expand Down
22 changes: 11 additions & 11 deletions hxl/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def evaluate_row(self, row):
# Numbers only for sum and average
datatype = hxl.datatypes.typeof(value, self.pattern)
if self.type in ['sum', 'average'] and datatype != 'number':
logup("Cannot use as a numeric value for aggregation; skipping.", {"value": value}, level='info')
logup("Cannot use as a numeric value for aggregation; skipping.", {"value": value})
logger.warning("Cannot use %s as a numeric value for aggregation; skipping.", value)
return

Expand Down Expand Up @@ -1181,7 +1181,7 @@ def _clean_value(self, value, column):
if self.date_format is not None:
value = dateutil.parser.parse(value).strftime(self.date_format)
except ValueError:
logup("Cannot use as a date", {"value": value}, level='info')
logup("Cannot use as a date", {"value": value})
logger.warning('Cannot parse %s as a date', str(value))
if self.purge:
value = ''
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def try_number(s):
if n is not None:
value = n
else:
logup('Cannot parse as a number', {"value": value}, level='info')
logup('Cannot parse as a number', {"value": value})
logger.warning('Cannot parse %s as a number', str(value))
if self.purge:
value = ''
Expand All @@ -1222,7 +1222,7 @@ def try_number(s):
if lat is not None:
value = format(lat, '0.4f')
else:
logup('Cannot parse as a latitude', {"value": value}, level='info')
logup('Cannot parse as a latitude', {"value": value})
logger.warning('Cannot parse %s as a latitude', str(value))
if self.purge:
value = ''
Expand All @@ -1231,7 +1231,7 @@ def try_number(s):
if lon is not None:
value = format(lon, '0.4f')
else:
logup('Cannot parse as a longitude', {"value": value}, level='info')
logup('Cannot parse as a longitude', {"value": value})
logger.warning('Cannot parse %s as a longitude', str(value))
if self.purge:
value = ''
Expand All @@ -1240,7 +1240,7 @@ def try_number(s):
if coord is not None:
value = '{:.4f},{:.4f}'.format(coord[0], coord[1])
else:
logup('Cannot parse as geographical coordinates', {"value": value}, level='info')
logup('Cannot parse as geographical coordinates', {"value": value})
logger.warning('Cannot parse %s as geographical coordinates', str(value))
if self.purge:
value = ''
Expand Down Expand Up @@ -1882,7 +1882,7 @@ def process(self):
"pattern": self.label_pattern,
"tag": self.source.columns[self.label_index].display_tag,
"header": self.source.columns[self.label_index].header
}, level='info')
})
logger.warning(
"[Implode filter] multiple columns match label pattern %s; using first match %s (%s)",
self.label_pattern,
Expand All @@ -1895,7 +1895,7 @@ def process(self):
else:
logup('[Implode filter] multiple columns match value pattern; using first match', {
"pattern": self.label_pattern
}, level='info')
})
logger.warning(
"[Implode filter] multiple columns match value pattern %s; using first match",
self.value_pattern
Expand Down Expand Up @@ -1934,7 +1934,7 @@ def process(self):
if key not in self.rows:
self.rows[key] = {}
if label in self.rows[key]:
logup('Multiple values in implode filter; using first match', {"value": label, "value_used": self.rows[key][label]}, level='info')
logup('Multiple values in implode filter; using first match', {"value": label, "value_used": self.rows[key][label]})
logger.error("Multiple values for %s in implode filter; using %s", label, self.rows[key][label])
else:
self.rows[key][label] = value
Expand Down Expand Up @@ -2256,7 +2256,7 @@ def filter_row(self, row):
else:
values[i] = hxl.datatypes.flatten(results, self.use_json)
except (ValueError, TypeError,) as e:
logup('Skipping invalid JSON expression', {"expression": str(values[i])}, level='info')
logup('Skipping invalid JSON expression', {"expression": str(values[i])})
logger.warning("Skipping invalid JSON expression '%s'", values[i])

return values
Expand Down Expand Up @@ -2420,7 +2420,7 @@ def sub(self, value):
@param value: the cell value
@returns: the new value if changed; False otherwise
"""

if self.is_regex:
result = re.subn(self.original, self.replacement, str(value))
if result[1] > 0:
Expand Down
5 changes: 4 additions & 1 deletion hxl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"""

import logging
import os
import sys
import structlog

def logup(msg, props={}, level="info"):
def logup(msg, props={}, level="notset"):
"""
Adds the function name on the fly for the log

Expand All @@ -14,6 +15,8 @@ def logup(msg, props={}, level="info"):
props: additional properties for the log

"""
if level == 'notset':
level = os.getenv('LOGGING_LEVEL', 'INFO').lower()
input_logger = structlog.wrap_logger(logging.getLogger('hxl.REMOTE_ACCESS'))
props['function'] = sys._getframe(1).f_code.co_name
levels = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='libhxl',
version="5.2",
version="5.2.1",
description='Python support library for the Humanitarian Exchange Language (HXL). See http://hxlstandard.org and https://github.com/HXLStandard/libhxl-python',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down