From 8112480beed08de4ac4e0e3d99db0e64f1587b88 Mon Sep 17 00:00:00 2001 From: David Decotigny Date: Tue, 5 Mar 2013 17:56:14 -0800 Subject: [PATCH] Make pkg_resources an optional module dependency --- README.rst | 2 ++ pybootd/__init__.py | 13 ++++++++++--- setup.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 142033f..5ed5897 100644 --- a/README.rst +++ b/README.rst @@ -23,9 +23,11 @@ Python - Python_ 2.6 or above is required. Python_ 3.x is not yet supported. - Netifaces_ Python module +- Optional: python-pkg-resources_ Python module .. _Python: http://python.org/ .. _Netifaces: http://alastairs-place.net/netifaces/ +.. _python-pkg-resources: http://pythonhosted.org/distribute/pkg_resources.html Permissions ----------- diff --git a/pybootd/__init__.py b/pybootd/__init__.py index 54494f2..efc1fd8 100644 --- a/pybootd/__init__.py +++ b/pybootd/__init__.py @@ -21,8 +21,12 @@ import os import sys def _get_package_name(default='', version='1.5.0'): - from pkg_resources import WorkingSet - ws = WorkingSet() + try: + from pkg_resources import WorkingSet + except ImportError: + ws = [] + else: + ws = WorkingSet() _path, _ = os.path.split(os.path.dirname( \ sys.modules['pybootd'].__file__)) _path = os.path.normpath(_path) @@ -48,9 +52,12 @@ def pybootd_path(path): else: try: from pkg_resources import Requirement, resource_filename + from pkg_resources import get_distribution + except ImportError: + raise IOError('pkg_resources module not available') + try: newpath = resource_filename(Requirement.parse(PRODUCT_NAME), path) if not newpath: - from pkg_resources import get_distribution localpath = get_distribution(PRODUCT_NAME).location newpath = os.path.join(localpath, path) except KeyError: diff --git a/setup.py b/setup.py index 39d30bc..adfe812 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ setup( url='http://github.com/eblot/pybootd', download_url='https://github.com/eblot/pybootd/tarball/master', packages=['pybootd'], - requires=['netifaces (>= 0.5)'], + # requires=['netifaces (>= 0.5)'], classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: No Input/Output (Daemon)',