From 8d98a55df165f722654f5f3421a6944091fcb17d Mon Sep 17 00:00:00 2001 From: Marcus Cobden Date: Mon, 11 Nov 2013 13:37:46 +0000 Subject: [PATCH] Fix setup.py to work with 'pip install -e .' --- lib/ansible/constants.py | 14 +++++++------- setup.py | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 8007b36915d..d5c0b7df39d 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -82,13 +82,13 @@ p = load_config_file() active_user = pwd.getpwuid(os.geteuid())[0] -# Needed so the RPM can call setup.py and have modules land in the -# correct location. See #1277 for discussion -if getattr(sys, "real_prefix", None): - # in a virtualenv - DIST_MODULE_PATH = os.path.join(sys.prefix, 'share/ansible/') -else: - DIST_MODULE_PATH = '/usr/share/ansible/' +DIST_MODULE_PATH = os.path.join(sys.prefix, 'share/ansible/') +EDITABLE_MODULE_PATH = os.path.normpath( + os.path.join(os.path.dirname(__file__), '../../library')) + +if not os.path.exists(DIST_MODULE_PATH) \ + and os.path.exists(EDITABLE_MODULE_PATH): + DIST_MODULE_PATH = EDITABLE_MODULE_PATH # sections in config file DEFAULTS='defaults' diff --git a/setup.py b/setup.py index c802eca6fd4..90124983053 100644 --- a/setup.py +++ b/setup.py @@ -4,15 +4,27 @@ import os import sys from glob import glob -sys.path.insert(0, os.path.abspath('lib')) +def rel(f): + return os.path.join(os.path.dirname(__file__), f) + +sys.path.insert(0, rel('lib')) from ansible import __version__, __author__ from distutils.core import setup -# find library modules -from ansible.constants import DEFAULT_MODULE_PATH -dirs=os.listdir("./library/") +# Needed so the RPM can call setup.py and have modules land in the +# correct location. See #1277 for discussion +if getattr(sys, "real_prefix", None): + # in a virtualenv + DEFAULT_MODULE_PATH = os.path.join(sys.prefix, 'share/ansible/library') +else: + DEFAULT_MODULE_PATH = '/usr/share/ansible/library' + +module_path = DEFAULT_MODULE_PATH +if not os.path.exists(DEFAULT_MODULE_PATH): + module_path = rel('library') + data_files = [] -for i in dirs: +for i in os.listdir(module_path): data_files.append((os.path.join(DEFAULT_MODULE_PATH, i), glob('./library/' + i + '/*'))) setup(name='ansible', @@ -23,7 +35,7 @@ setup(name='ansible', url='http://ansibleworks.com/', license='GPLv3', install_requires=['paramiko', 'jinja2', "PyYAML"], - package_dir={ 'ansible': 'lib/ansible' }, + package_dir={ '': 'lib' }, packages=[ 'ansible', 'ansible.utils',