From 67a114945abf8dfeeeb0c6a0c128f3349a09d8d5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 4 Jan 2025 16:31:15 +0100 Subject: [PATCH] chore: drop Postgres version parsing in setup.py The macro is in the include files, no idea why parsing it from pg_config was needed. --- psycopg/psycopg.h | 1 + setup.py | 31 ++----------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/psycopg/psycopg.h b/psycopg/psycopg.h index afda00f47..cdb1c9ae1 100644 --- a/psycopg/psycopg.h +++ b/psycopg/psycopg.h @@ -27,6 +27,7 @@ #ifndef PSYCOPG_H #define PSYCOPG_H 1 +#include #if PG_VERSION_NUM < 90100 #error "Psycopg requires PostgreSQL client library (libpq) >= 9.1" #endif diff --git a/setup.py b/setup.py index 687c37c8f..36aef58e9 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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