Skip to content

Commit

Permalink
chore: drop Postgres version parsing in setup.py
Browse files Browse the repository at this point in the history
The macro is in the include files, no idea why parsing it from pg_config
was needed.
  • Loading branch information
dvarrazzo committed Jan 4, 2025
1 parent e199336 commit 67a1149
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
1 change: 1 addition & 0 deletions psycopg/psycopg.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef PSYCOPG_H
#define PSYCOPG_H 1

#include <pg_config.h>
#if PG_VERSION_NUM < 90100
#error "Psycopg requires PostgreSQL client library (libpq) >= 9.1"
#endif
Expand Down
31 changes: 2 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import os
import sys
import re
import subprocess
from setuptools import setup, Extension
from distutils.command.build_ext import build_ext
Expand Down Expand Up @@ -382,34 +381,8 @@ def finalize_options(self):
if token.startswith("-I"):
self.include_dirs.append(token[2:])

pgversion = pg_config_helper.query("version").split()[1]

verre = re.compile(
r"(\d+)(?:\.(\d+))?(?:(?:\.(\d+))|(devel|(?:alpha|beta|rc)\d+))?")
m = verre.match(pgversion)
if m:
pgmajor, pgminor, pgpatch = m.group(1, 2, 3)
# Postgres >= 10 doesn't have pgminor anymore.
pgmajor = int(pgmajor)
if pgmajor >= 10:
pgminor, pgpatch = None, pgminor
if pgminor is None or not pgminor.isdigit():
pgminor = 0
if pgpatch is None or not pgpatch.isdigit():
pgpatch = 0
pgminor = int(pgminor)
pgpatch = int(pgpatch)
else:
sys.stderr.write(
f"Error: could not determine PostgreSQL version from "
f"'{pgversion}'")
sys.exit(1)

define_macros.append(("PG_VERSION_NUM", "%d%02d%02d" %
(pgmajor, pgminor, pgpatch)))

# enable lo64 if libpq >= 9.3 and Python 64 bits
if (pgmajor, pgminor) >= (9, 3) and is_py_64():
# enable lo64 if Python 64 bits
if is_py_64():
define_macros.append(("HAVE_LO64", "1"))

# Inject the flag in the version string already packed up
Expand Down

0 comments on commit 67a1149

Please sign in to comment.