Properly detect pg_config.exe on Windows.

I'm fairly certain this is correct, submitting so I can pull on my Windows
box and do some testing there.
This commit is contained in:
Steve Lacy 2011-06-07 11:25:59 -07:00 committed by Daniele Varrazzo
parent 46dc7e66f8
commit 575afa2e0e

View File

@ -133,37 +133,22 @@ or with the pg_config option in 'setup.cfg'.
if PLATFORM_IS_WINDOWS: if PLATFORM_IS_WINDOWS:
return self.autodetect_pg_config_path_windows() return self.autodetect_pg_config_path_windows()
else: else:
return self.autodetect_pg_config_path_posix()
def autodetect_pg_config_path_posix(self):
"""Return pg_config from the current PATH"""
return self.find_on_path('pg_config') return self.find_on_path('pg_config')
def autodetect_pg_config_path_windows(self): def autodetect_pg_config_path_windows(self):
"""Attempt several different ways of finding the pg_config """Attempt several different ways of finding the pg_config
executable on Windows, and return its full path, if found.""" executable on Windows, and return its full path, if found."""
# Find the first PostgreSQL installation listed in the registry and
# return the full path to its pg_config utility.
#
# This autodetection is performed *only* if the following conditions
# hold:
#
# 1) The pg_config utility is not already available on the PATH:
if os.popen('pg_config').close() is None: # .close()->None == success
return None
# 2) The user has not specified any of the following settings in # This code only runs if they have not specified a pg_config option
# setup.cfg: # in the config file or via the commandline.
# - pg_config
# - include_dirs
# - library_dirs
if (self.build_ext.pg_config # First, check for pg_config.exe on the PATH, and use that if found.
or self.build_ext.include_dirs pg_config_exe = self.find_on_path('pg_config.exe')
or self.build_ext.library_dirs): if pg_config_exe:
return None return pg_config_exe
# end of guard conditions
# Now, try looking in the Windows Registry to find a PostgreSQL
# installation, and infer the path from that.
try: try:
import winreg import winreg
except ImportError: except ImportError:
@ -180,7 +165,11 @@ or with the pg_config option in 'setup.cfg'.
except EnvironmentError: except EnvironmentError:
pg_inst_list_key = None pg_inst_list_key = None
if pg_inst_list_key is not None: if not pg_inst_list_key:
# No PostgreSQL installation, as best as we can tell.
return None
try: try:
# Determine the name of the first subkey, if any: # Determine the name of the first subkey, if any:
try: try:
@ -203,9 +192,8 @@ or with the pg_config option in 'setup.cfg'.
winreg.CloseKey(pg_inst_list_key) winreg.CloseKey(pg_inst_list_key)
if pg_inst_base_dir and os.path.exists(pg_inst_base_dir): if pg_inst_base_dir and os.path.exists(pg_inst_base_dir):
pg_config_path = os.path.join(pg_inst_base_dir, 'bin', pg_config_path = os.path.join(
'pg_config.exe' pg_inst_base_dir, 'bin', 'pg_config.exe')
)
# Support unicode paths, if this version of Python provides the # Support unicode paths, if this version of Python provides the
# necessary infrastructure: # necessary infrastructure:
if sys.version_info[0] < 3 \ if sys.version_info[0] < 3 \