Skip to content

Commit fb77bdc

Browse files
committed
Merge branch 'dev/fix-meson-build'
2 parents 0c5b5f4 + ef7053c commit fb77bdc

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Current release
44
What's new in psycopg 2.9.7 (unreleased)
55
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7+
- Fix building when pg_config returns an empty string (:ticket:`#1599`).
78
- Wheel package compiled against OpenSSL 1.1.1v.
89

910

setup.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,23 @@ def __init__(self, build_ext):
105105
""")
106106
sys.exit(1)
107107

108-
def query(self, attr_name):
108+
def query(self, attr_name, *, empty_ok=False):
109109
"""Spawn the pg_config executable, querying for the given config
110110
name, and return the printed value, sanitized. """
111111
try:
112-
pg_config_process = subprocess.Popen(
112+
pg_config_process = subprocess.run(
113113
[self.pg_config_exe, "--" + attr_name],
114-
stdin=subprocess.PIPE,
115114
stdout=subprocess.PIPE,
116115
stderr=subprocess.PIPE)
117116
except OSError:
118117
raise Warning(
119118
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")
126125
return result
127126

128127
def find_on_path(self, exename, path_directories=None):
@@ -378,12 +377,14 @@ def finalize_options(self):
378377
self.include_dirs.append(pg_config_helper.query("includedir"))
379378
self.include_dirs.append(pg_config_helper.query("includedir-server"))
380379

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:
383383
if token.startswith("-L"):
384384
self.library_dirs.append(token[2:])
385385

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:
387388
if token.startswith("-I"):
388389
self.include_dirs.append(token[2:])
389390

0 commit comments

Comments
 (0)