Refuse to build if pg_config is not found.

I think half of the problems in OS X setup are due to setup going ahead
even when the pg_config is not found. We are now only building with PG
version that make the tool available.
This commit is contained in:
Daniele Varrazzo 2011-01-02 01:47:08 +01:00
parent 45c6dfb69d
commit d08bfcbee5
2 changed files with 32 additions and 17 deletions

View File

@ -1,10 +1,11 @@
What's new in psycopg 2.3.3 What's new in psycopg 2.3.3
--------------------------- ---------------------------
* New features: * New features and changes:
- Added `register_composite()` function to cast PostgreSQL composite types - Added `register_composite()` function to cast PostgreSQL composite types
into Python tuples/namedtuples. into Python tuples/namedtuples.
- The build script refuses to guess values if pg_config is not found.
* Bug fixes: * Bug fixes:

View File

@ -62,14 +62,14 @@ version_flags = ['dt', 'dec']
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win') PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
def get_pg_config(kind, pg_config="pg_config"): def get_pg_config(kind, pg_config):
try: try:
p = subprocess.Popen([pg_config, "--" + kind], p = subprocess.Popen([pg_config, "--" + kind],
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
except OSError: except OSError:
raise Warning("Unable to find 'pg_config' file") raise Warning("Unable to find 'pg_config' file in '%s'" % pg_config)
p.stdin.close() p.stdin.close()
r = p.stdout.readline().strip() r = p.stdout.readline().strip()
if not r: if not r:
@ -101,8 +101,6 @@ class psycopg_build_ext(build_ext):
boolean_options = build_ext.boolean_options[:] boolean_options = build_ext.boolean_options[:]
boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq')) boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq'))
DEFAULT_PG_CONFIG = "pg_config"
def initialize_options(self): def initialize_options(self):
build_ext.initialize_options(self) build_ext.initialize_options(self)
self.use_pg_dll = 1 self.use_pg_dll = 1
@ -110,8 +108,7 @@ class psycopg_build_ext(build_ext):
self.mx_include_dir = None self.mx_include_dir = None
self.use_pydatetime = 1 self.use_pydatetime = 1
self.have_ssl = have_ssl self.have_ssl = have_ssl
self.pg_config = None
self.pg_config = self.autodetect_pg_config_path()
def get_compiler(self): def get_compiler(self):
"""Return the name of the C compiler used to compile extensions. """Return the name of the C compiler used to compile extensions.
@ -209,6 +206,20 @@ class psycopg_build_ext(build_ext):
def finalize_options(self): def finalize_options(self):
"""Complete the build system configuation.""" """Complete the build system configuation."""
build_ext.finalize_options(self) build_ext.finalize_options(self)
if self.pg_config is None:
self.pg_config = self.autodetect_pg_config_path()
if self.pg_config is None:
sys.stderr.write("""\
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
""")
sys.exit(1)
self.include_dirs.append(".") self.include_dirs.append(".")
if static_libpq: if static_libpq:
@ -244,23 +255,26 @@ class psycopg_build_ext(build_ext):
define_macros.append(("PG_VERSION_HEX", "0x%02X%02X%02X" % define_macros.append(("PG_VERSION_HEX", "0x%02X%02X%02X" %
(int(pgmajor), int(pgminor), int(pgpatch)))) (int(pgmajor), int(pgminor), int(pgpatch))))
except Warning, w: except Warning:
if self.pg_config == self.DEFAULT_PG_CONFIG: w = sys.exc_info()[1] # work around py 2/3 different syntax
sys.stderr.write("Warning: %s" % str(w)) sys.stderr.write("Error: %s\n" % w)
else:
sys.stderr.write("Error: %s" % str(w))
sys.exit(1) sys.exit(1)
if hasattr(self, "finalize_" + sys.platform): if hasattr(self, "finalize_" + sys.platform):
getattr(self, "finalize_" + sys.platform)() getattr(self, "finalize_" + sys.platform)()
def autodetect_pg_config_path(self): def autodetect_pg_config_path(self):
res = None
if PLATFORM_IS_WINDOWS: if PLATFORM_IS_WINDOWS:
res = self.autodetect_pg_config_path_windows() return self.autodetect_pg_config_path_windows()
else:
return self.autodetect_pg_config_path_posix()
return res or self.DEFAULT_PG_CONFIG def autodetect_pg_config_path_posix(self):
exename = 'pg_config'
for dir in os.environ['PATH'].split(os.pathsep):
fn = os.path.join(dir, exename)
if os.path.isfile(fn):
return fn
def autodetect_pg_config_path_windows(self): def autodetect_pg_config_path_windows(self):
# Find the first PostgreSQL installation listed in the registry and # Find the first PostgreSQL installation listed in the registry and