Skip to content

Commit 3c8a274

Browse files
committed
Version 0.4.0: Allow installation (but not usage) with Python 2.7
1 parent 0323e5f commit 3c8a274

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Install using `pip`:
1515
python -m pip install pyoslog
1616
```
1717

18-
The module will install and import without error on earlier macOS versions.
19-
Use `pyoslog.is_supported()` if you need to support old macOS versions and want to know at runtime whether to use pyoslog.
18+
The module will install and import without error on earlier macOS versions (and on unsupported Operating Systems and Python versions).
19+
Use `pyoslog.is_supported()` if you need to support old macOS versions or other environments and want to know at runtime whether to use pyoslog.
2020
Please note that if `is_supported()` returns `False` then none of the module's other methods or constants will exist.
2121

2222

@@ -92,4 +92,4 @@ A `log.h` binding is on that project's [roadmap](https://github.com/ronaldoussor
9292

9393

9494
## License
95-
[Apache 2.0](LICENSE)
95+
[Apache 2.0](https://github.com/simonrob/pyoslog/blob/main/LICENSE)

pyoslog/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'pyoslog'
2-
__version__ = '0.3.0'
2+
__version__ = '0.4.0'
33
__description__ = 'Send messages to the macOS unified logging system'
44
__author__ = 'Simon Robinson'
55
__author_email__ = '[email protected]'

pyoslog/compatibility.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ def is_supported():
66
"""Unified logging is only present in macOS 10.12 and later, but it is nicer to not have to check OS type or version
77
strings when installing or importing the module - use this method at runtime to check whether it is supported. It is
88
important to note that if is_supported() is False then none of the module's other methods/constants will exist."""
9-
return sys.platform == 'darwin' and float('.'.join(platform.mac_ver()[0].split('.')[:2])) >= 10.12
9+
return sys.platform == 'darwin' and sys.version_info >= (3, 0,) and float(
10+
'.'.join(platform.mac_ver()[0].split('.')[:2])) >= 10.12

setup.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import importlib.util
21
import os
32

43
from setuptools import setup, Extension
@@ -13,12 +12,22 @@
1312
with open('README.md') as readme_file:
1413
readme = readme_file.read()
1514

16-
# see compatibility.py - allow installation on older versions but provide is_supported() at runtime
17-
spec = importlib.util.spec_from_file_location('compatibility', os.path.join(working_directory, 'compatibility.py'))
18-
compatibility = importlib.util.module_from_spec(spec)
19-
spec.loader.exec_module(compatibility)
15+
# see compatibility.py - allow installation on older versions (or other OSs) but provide is_supported() at runtime
16+
compatibility_module_name = 'compatibility'
17+
compatibility_module_path = os.path.join(working_directory, '%s.py' % compatibility_module_name)
18+
try:
19+
# noinspection PyUnresolvedReferences
20+
import importlib.util
21+
22+
spec = importlib.util.spec_from_file_location(compatibility_module_name, compatibility_module_path)
23+
compatibility = importlib.util.module_from_spec(spec)
24+
spec.loader.exec_module(compatibility)
25+
except ImportError:
26+
import imp
27+
28+
compatibility = imp.load_source(compatibility_module_name, compatibility_module_path)
29+
2030
ext_modules = []
21-
# noinspection PyUnresolvedReferences
2231
if compatibility.is_supported():
2332
ext_modules.append(Extension('_' + NAME, ['%s/_%s.c' % (NAME, NAME)]))
2433

0 commit comments

Comments
 (0)