Skip to content

Commit

Permalink
Merge branch 'dev/fix-meson-build'
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Aug 4, 2023
2 parents 0c5b5f4 + ef7053c commit fb77bdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Current release
What's new in psycopg 2.9.7 (unreleased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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


Expand Down
25 changes: 13 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,23 @@ def __init__(self, build_ext):
""")
sys.exit(1)

def query(self, attr_name):
def query(self, attr_name, *, empty_ok=False):
"""Spawn the pg_config executable, querying for the given config
name, and return the printed value, sanitized. """
try:
pg_config_process = subprocess.Popen(
pg_config_process = subprocess.run(
[self.pg_config_exe, "--" + attr_name],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except OSError:
raise Warning(
f"Unable to find 'pg_config' file in '{self.pg_config_exe}'")
pg_config_process.stdin.close()
result = pg_config_process.stdout.readline().strip()
if not result:
raise Warning(pg_config_process.stderr.readline())
if not isinstance(result, str):
result = result.decode('ascii')
if pg_config_process.returncode:
err = pg_config_process.stderr.decode(errors='backslashreplace')
raise Warning(f"pg_config --{attr_name} failed: {err}")
result = pg_config_process.stdout.decode().strip()
if not result and not empty_ok:
raise Warning(f"pg_config --{attr_name} is empty")
return result

def find_on_path(self, exename, path_directories=None):
Expand Down Expand Up @@ -378,12 +377,14 @@ def finalize_options(self):
self.include_dirs.append(pg_config_helper.query("includedir"))
self.include_dirs.append(pg_config_helper.query("includedir-server"))

# add includedirs from cppflags, libdirs from ldflags
for token in pg_config_helper.query("ldflags").split():
# if present, add includedirs from cppflags, libdirs from ldflags
tokens = pg_config_helper.query("ldflags", empty_ok=True).split()
for token in tokens:
if token.startswith("-L"):
self.library_dirs.append(token[2:])

for token in pg_config_helper.query("cppflags").split():
tokens = pg_config_helper.query("cppflags", empty_ok=True).split()
for token in tokens:
if token.startswith("-I"):
self.include_dirs.append(token[2:])

Expand Down

0 comments on commit fb77bdc

Please sign in to comment.