From dd7895b59b358069c933c5b09534fbc9da25b5b0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 15 Nov 2017 15:42:03 -0200 Subject: [PATCH 1/2] Fix py.log import error on Windows due to syslog Fix #169, #170 --- CHANGELOG | 5 +++++ py/_log/log.py | 20 +++++++++++++------- testing/log/test_log.py | 4 +--- testing/root/test_py_imports.py | 4 ---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c4ed92f6..a3e4bf1b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +1.5.2 +===== + +- fix #169, #170: error importing py.log on Windows: no module named ``syslog``. + 1.5.1 ===== diff --git a/py/_log/log.py b/py/_log/log.py index 689d597e..56969bcb 100644 --- a/py/_log/log.py +++ b/py/_log/log.py @@ -16,7 +16,6 @@ """ import py import sys -import syslog class Message(object): @@ -190,11 +189,18 @@ def __init__(self, priority=None): def __call__(self, msg): """ write a message to the log """ + import syslog syslog.syslog(self.priority, str(msg)) -for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split(): - _prio = "LOG_" + _prio - try: - setattr(Syslog, _prio, getattr(syslog, _prio)) - except AttributeError: - pass + +try: + import syslog +except ImportError: + pass +else: + for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split(): + _prio = "LOG_" + _prio + try: + setattr(Syslog, _prio, getattr(syslog, _prio)) + except AttributeError: + pass diff --git a/testing/log/test_log.py b/testing/log/test_log.py index 2e1f8f46..5c706d9b 100644 --- a/testing/log/test_log.py +++ b/testing/log/test_log.py @@ -1,11 +1,9 @@ import py -import sys -import pytest +from py._log.log import default_keywordmapper callcapture = py.io.StdCapture.call -default_keywordmapper = pytest.importorskip('py._log.log.default_keywordmapper') def setup_module(mod): mod._oldstate = default_keywordmapper.getstate() diff --git a/testing/root/test_py_imports.py b/testing/root/test_py_imports.py index 2c45c075..31fe6ead 100644 --- a/testing/root/test_py_imports.py +++ b/testing/root/test_py_imports.py @@ -4,8 +4,6 @@ @py.test.mark.parametrize('name', [x for x in dir(py) if x[0] != '_']) def test_dir(name): - if name == 'log' and sys.platform.startswith('win'): - py.test.skip('syslog is not available on Windows') obj = getattr(py, name) if hasattr(obj, '__map__'): # isinstance(obj, Module): keys = dir(obj) @@ -54,8 +52,6 @@ def recurse(p): def check_import(modpath): - if modpath == 'py._log.log' and sys.platform.startswith('win'): - py.test.skip('syslog is not available on Windows') py.builtin.print_("checking import", modpath) assert __import__(modpath) From 84888f75de0502aece3c1306802b26848e84c5b1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 15 Nov 2017 15:42:12 -0200 Subject: [PATCH 2/2] Bump version to 1.5.2 --- py/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/__init__.py b/py/__init__.py index aa08a687..b5e0c163 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -8,7 +8,7 @@ (c) Holger Krekel and others, 2004-2014 """ -__version__ = '1.5.1' +__version__ = '1.5.2' try: from py._vendored_packages import apipkg