2
#-----------------------------------------------------------------------------
3
# Copyright (C) 2011 Brian Granger, Min Ragan-Kelley
5
# This file is part of pyzmq, copied and adapted from h5py.
6
# h5py source used under the New BSD license
8
# h5py: <http://code.google.com/p/h5py/>
10
# Distributed under the terms of the New BSD License. The full license is in
11
# the file COPYING.BSD, distributed as part of this software.
12
#-----------------------------------------------------------------------------
19
from configparser import ConfigParser
21
from ConfigParser import ConfigParser
24
from .msg import debug, fatal, warn
26
#-----------------------------------------------------------------------------
27
# Utility functions (adapted from h5py: http://h5py.googlecode.com)
28
#-----------------------------------------------------------------------------
31
def load_config(name):
32
"""Load config dict from JSON"""
33
fname = pjoin('conf', name+'.json')
34
if not os.path.exists(fname):
37
with open(fname) as f:
39
except Exception as e:
40
warn("Couldn't load %s: %s" % (fname, e))
45
def save_config(name, data):
46
"""Save config dict to JSON"""
47
if not os.path.exists('conf'):
49
fname = pjoin('conf', name+'.json')
50
with open(fname, 'w') as f:
51
json.dump(data, f, indent=2)
55
"""turn (2,0,1) into '2.0.1'."""
56
return ".".join(str(x) for x in v_tuple)
59
""" Look for options in environment vars """
63
zmq = os.environ.get("ZMQ_DIR", '')
65
debug("Found environ var ZMQ_DIR=%s" % zmq)
71
""" Look for options in setup.cfg """
75
if not os.path.exists('setup.cfg'):
79
if 'build_ext' in cfg.sections() and \
80
cfg.has_option('build_ext', 'include_dirs'):
81
includes = cfg.get('build_ext', 'include_dirs')
82
include = includes.split(os.pathsep)[0]
83
if include.endswith('include') and os.path.isdir(include):
86
debug("Found ZMQ=%s in setup.cfg" % zmq)
92
""" Look for global options in the command line """
93
settings = load_config('buildconf')
94
if settings is None: settings = {}
95
for arg in sys.argv[:]:
96
if arg.find('--zmq=') == 0:
97
zmq = arg.split('=')[-1]
98
if zmq.lower() in ('default', 'auto', ''):
99
settings.pop('zmq', None)
101
settings['zmq'] = zmq
103
save_config('buildconf', settings)
106
def discover_settings():
107
""" Discover custom settings for ZMQ path"""
108
settings = get_cfg_args() # lowest priority
109
settings.update(get_eargs())
110
settings.update(get_cargs()) # highest priority
111
return settings.get('zmq')