Skip to content

Commit

Permalink
Use importlib to import user calibration module
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed May 21, 2018
1 parent ac9c014 commit c66000a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.5.0'
_release = '1531'
_commit = '0ed083c'
_release = '1532'
_commit = 'ac9c014'
10 changes: 7 additions & 3 deletions src/pywws/calib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-14 Jim Easterbrook jim@jim-easterbrook.me.uk
# Copyright (C) 2008-18 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -83,12 +83,14 @@ def calib(self, raw):

__docformat__ = "restructuredtext en"

import importlib
import logging
import os
import sys

logger = logging.getLogger(__name__)


class DefaultCalib(object):
"""Default calibration class.
Expand All @@ -106,8 +108,10 @@ def calib(self, raw):
result['rel_pressure'] = result['abs_pressure'] + self.pressure_offset
return result


usercalib = None


class Calib(object):
"""Calibration class that implements default or user calibration.
Expand All @@ -129,8 +133,8 @@ def __init__(self, params, stored_data):
path, module = os.path.split(user_module)
sys.path.insert(0, path)
module = os.path.splitext(module)[0]
usercalib = __import__(
module, globals(), locals(), ['Calib'])
usercalib = importlib.import_module(module)
del sys.path[0]
Calib.calibrator = usercalib.Calib(params, stored_data)
else:
logger.info('Using default calibration')
Expand Down

0 comments on commit c66000a

Please sign in to comment.