@@ -105,24 +105,23 @@ def __init__(self, build_ext):
105
105
""" )
106
106
sys .exit (1 )
107
107
108
- def query (self , attr_name ):
108
+ def query (self , attr_name , * , empty_ok = False ):
109
109
"""Spawn the pg_config executable, querying for the given config
110
110
name, and return the printed value, sanitized. """
111
111
try :
112
- pg_config_process = subprocess .Popen (
112
+ pg_config_process = subprocess .run (
113
113
[self .pg_config_exe , "--" + attr_name ],
114
- stdin = subprocess .PIPE ,
115
114
stdout = subprocess .PIPE ,
116
115
stderr = subprocess .PIPE )
117
116
except OSError :
118
117
raise Warning (
119
118
f"Unable to find 'pg_config' file in '{ self .pg_config_exe } '" )
120
- pg_config_process .stdin . close ()
121
- result = pg_config_process .stdout . readline (). strip ( )
122
- if not result :
123
- raise Warning ( pg_config_process .stderr . readline () )
124
- if not isinstance ( result , str ) :
125
- result = result . decode ( 'ascii' )
119
+ if pg_config_process .returncode :
120
+ err = pg_config_process .stderr . decode ( errors = 'backslashreplace' )
121
+ raise Warning ( f"pg_config -- { attr_name } failed: { err } " )
122
+ result = pg_config_process .stdout . decode (). strip ( )
123
+ if not result and not empty_ok :
124
+ raise Warning ( f"pg_config -- { attr_name } is empty" )
126
125
return result
127
126
128
127
def find_on_path (self , exename , path_directories = None ):
@@ -378,12 +377,14 @@ def finalize_options(self):
378
377
self .include_dirs .append (pg_config_helper .query ("includedir" ))
379
378
self .include_dirs .append (pg_config_helper .query ("includedir-server" ))
380
379
381
- # add includedirs from cppflags, libdirs from ldflags
382
- for token in pg_config_helper .query ("ldflags" ).split ():
380
+ # if present, add includedirs from cppflags, libdirs from ldflags
381
+ tokens = pg_config_helper .query ("ldflags" , empty_ok = True ).split ()
382
+ for token in tokens :
383
383
if token .startswith ("-L" ):
384
384
self .library_dirs .append (token [2 :])
385
385
386
- for token in pg_config_helper .query ("cppflags" ).split ():
386
+ tokens = pg_config_helper .query ("cppflags" , empty_ok = True ).split ()
387
+ for token in tokens :
387
388
if token .startswith ("-I" ):
388
389
self .include_dirs .append (token [2 :])
389
390
0 commit comments