]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor(c): convert setup.cfg to pyproject.toml
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 22 Dec 2024 01:43:43 +0000 (02:43 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 23 Dec 2024 12:44:13 +0000 (13:44 +0100)
Drop setup.py: move the build configuration to a build backend module.

psycopg_c/build_backend/psycopg_build_ext.py [moved from psycopg_c/setup.py with 56% similarity]
psycopg_c/pyproject.toml
psycopg_c/setup.cfg [deleted file]
tests/constraints.txt

similarity index 56%
rename from psycopg_c/setup.py
rename to psycopg_c/build_backend/psycopg_build_ext.py
index eeea1c94515be639916217b62b7687a3f185adec..f81d00d3be74944a56f481a1a693931b5bd46297 100644 (file)
@@ -1,24 +1,19 @@
-#!/usr/bin/env python3
 """
-PostgreSQL database adapter for Python - optimisation package
+Build backend module for psycopg Cython components.
+
+Convert Cython to C if required, compile the C modules adding build from the
+libpq and accounting for other platform differences.
 """
 
-# Copyright (C) 2020 The Psycopg Team
+# Copyright (C) 2024 The Psycopg Team
 
 import os
 import sys
 import subprocess as sp
 
-from setuptools import setup, Extension
 from distutils.command.build_ext import build_ext
 from distutils import log
 
-# Move to the directory of setup.py: executing this file from another location
-# (e.g. from the project root) will fail
-here = os.path.abspath(os.path.dirname(__file__))
-if os.path.abspath(os.getcwd()) != here:
-    os.chdir(here)
-
 
 def get_config(what: str) -> str:
     pg_config = "pg_config"
@@ -37,25 +32,25 @@ class psycopg_build_ext(build_ext):
         super().finalize_options()
 
     def _setup_ext_build(self) -> None:
-        cythonize = None
+        # Add include and lib dir for the libpq.
 
-        # In the sdist there are not .pyx, only c, so we don't need Cython.
-        # Otherwise Cython is a requirement and it is used to compile pyx to c.
-        if os.path.exists("psycopg_c/_psycopg.pyx"):
-            from Cython.Build import cythonize
+        # MSVC requires an explicit "libpq"
+        libpq = "pq" if sys.platform != "win32" else "libpq"
 
-        # Add include and lib dir for the libpq.
-        includedir = get_config("includedir")
-        libdir = get_config("libdir")
         for ext in self.distribution.ext_modules:
-            ext.include_dirs.append(includedir)
-            ext.library_dirs.append(libdir)
+            ext.libraries.append(libpq)
+            ext.include_dirs.append(get_config("includedir"))
+            ext.library_dirs.append(get_config("libdir"))
 
             if sys.platform == "win32":
                 # For __imp_htons and others
                 ext.libraries.append("ws2_32")
 
-        if cythonize is not None:
+        # In the sdist there are not .pyx, only c, so we don't need Cython.
+        # Otherwise Cython is a requirement and it is used to compile pyx to c.
+        if os.path.exists("psycopg_c/_psycopg.pyx"):
+            from Cython.Build import cythonize  # type: ignore[import-untyped]
+
             for ext in self.distribution.ext_modules:
                 for i in range(len(ext.sources)):
                     base, fext = os.path.splitext(ext.sources[i])
@@ -70,32 +65,3 @@ class psycopg_build_ext(build_ext):
                 },
                 annotate=False,  # enable to get an html view of the C module
             )
-        else:
-            self.distribution.ext_modules = [pgext, pqext]
-
-
-# MSVC requires an explicit "libpq"
-libpq = "pq" if sys.platform != "win32" else "libpq"
-
-# Some details missing, to be finished by psycopg_build_ext.finalize_options
-pgext = Extension(
-    "psycopg_c._psycopg",
-    [
-        "psycopg_c/_psycopg.c",
-        "psycopg_c/types/numutils.c",
-    ],
-    libraries=[libpq],
-    include_dirs=[],
-)
-
-pqext = Extension(
-    "psycopg_c.pq",
-    ["psycopg_c/pq.c"],
-    libraries=[libpq],
-    include_dirs=[],
-)
-
-setup(
-    ext_modules=[pgext, pqext],
-    cmdclass={"build_ext": psycopg_build_ext},
-)
index 55c0504d60cdb571710b0a85baaed7261347d58f..f7a2ddefa7775d2dc7747b6784f66e1834ef39f1 100644 (file)
@@ -1,6 +1,12 @@
 [build-system]
 requires = [
-    "setuptools >= 49.2.0",
+    # Note: pinning these versions strictly because of the setuptools warning:
+    #
+    #   `[tool.setuptools.ext-modules]` in `pyproject.toml` is still
+    #   *experimental* and likely to change in future releases
+    #
+    "setuptools == 75.6.0; python_version >= '3.9'",
+    "setuptools == 75.3.0; python_version < '3.9'",  # last supported version
     "wheel >= 0.37",
     "tomli >= 2.0.1; python_version < '3.11'",
 ]
@@ -15,3 +21,86 @@ backend-path = ["build_backend"]
 [cython-backend]
 # These packages are only installed if there are pyx files to compile.
 cython-requires = ["Cython >= 3.0.0"]
+
+[project]
+name = "psycopg-c"
+description = "PostgreSQL database adapter for Python -- C optimisation distribution"
+version = "3.2.4.dev1"
+classifiers = [
+    "Development Status :: 5 - Production/Stable",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
+    "Operating System :: MacOS :: MacOS X",
+    "Operating System :: Microsoft :: Windows",
+    "Operating System :: POSIX",
+    "Programming Language :: Cython",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3.8",
+    "Programming Language :: Python :: 3.9",
+    "Programming Language :: Python :: 3.10",
+    "Programming Language :: Python :: 3.11",
+    "Programming Language :: Python :: 3.12",
+    "Programming Language :: Python :: 3.13",
+    "Programming Language :: Python :: Implementation :: CPython",
+    "Topic :: Database",
+    "Topic :: Database :: Front-Ends",
+    "Topic :: Software Development",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+]
+requires-python = ">= 3.8"
+
+[[project.authors]]
+name = "Daniele Varrazzo"
+email = "daniele.varrazzo@gmail.com"
+
+[project.license]
+text = "GNU Lesser General Public License v3 (LGPLv3)"
+
+[project.urls]
+Homepage = "https://psycopg.org/"
+Documentation = "https://psycopg.org/psycopg3/docs/"
+Changes = "https://psycopg.org/psycopg3/docs/news.html"
+Code = "https://github.com/psycopg/psycopg"
+"Issue Tracker" = "https://github.com/psycopg/psycopg/issues"
+Download = "https://pypi.org/project/psycopg-c/"
+
+[project.readme]
+file = "README.rst"
+content-type = "text/x-rst"
+
+[tool.setuptools]
+packages = [
+    "psycopg_c",
+    "psycopg_c.pq",
+    "psycopg_c._psycopg",
+    "psycopg_c.types",
+]
+zip-safe = false
+license-files = ["LICENSE.txt"]
+include-package-data = true
+
+[tool.setuptools.package-data]
+psycopg_c = [
+    "py.typed",
+    "*.pyi",
+    "*.pxd",
+    "_psycopg/*.pxd",
+    "pq/*.pxd",
+]
+psycopg_binary = [
+    "py.typed",
+    "*.pyi",
+]
+
+# Note: these ext modules lack details such as libraries and directories.
+# They are added by the psycopg_build_ext build module.
+[[tool.setuptools.ext-modules]]
+name = "psycopg_c._psycopg"
+sources = ["psycopg_c/_psycopg.c", "psycopg_c/types/numutils.c"]
+
+[[tool.setuptools.ext-modules]]
+name = "psycopg_c.pq"
+sources = ["psycopg_c/pq.c"]
+
+[tool.setuptools.cmdclass]
+build_ext = "psycopg_build_ext.psycopg_build_ext"
diff --git a/psycopg_c/setup.cfg b/psycopg_c/setup.cfg
deleted file mode 100644 (file)
index 4a0079d..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-[metadata]
-name = psycopg-c
-description = PostgreSQL database adapter for Python -- C optimisation distribution
-url = https://psycopg.org/psycopg3/
-author = Daniele Varrazzo
-author_email = daniele.varrazzo@gmail.com
-license = GNU Lesser General Public License v3 (LGPLv3)
-version = 3.2.4.dev1
-
-project_urls =
-    Homepage = https://psycopg.org/
-    Documentation = https://psycopg.org/psycopg3/docs/
-    Changes = https://psycopg.org/psycopg3/docs/news.html
-    Code = https://github.com/psycopg/psycopg
-    Issue Tracker = https://github.com/psycopg/psycopg/issues
-    Download = https://pypi.org/project/psycopg-c/
-
-classifiers =
-    Development Status :: 5 - Production/Stable
-    Intended Audience :: Developers
-    License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
-    Operating System :: MacOS :: MacOS X
-    Operating System :: Microsoft :: Windows
-    Operating System :: POSIX
-    Programming Language :: Cython
-    Programming Language :: Python :: 3
-    Programming Language :: Python :: 3.8
-    Programming Language :: Python :: 3.9
-    Programming Language :: Python :: 3.10
-    Programming Language :: Python :: 3.11
-    Programming Language :: Python :: 3.12
-    Programming Language :: Python :: 3.13
-    Programming Language :: Python :: Implementation :: CPython
-    Topic :: Database
-    Topic :: Database :: Front-Ends
-    Topic :: Software Development
-    Topic :: Software Development :: Libraries :: Python Modules
-
-long_description = file: README.rst
-long_description_content_type = text/x-rst
-license_files = LICENSE.txt
-
-[options]
-python_requires = >= 3.8
-packages = find:
-zip_safe = False
-
-[options.package_data]
-# NOTE: do not include .pyx files: they shouldn't be in the sdist
-# package, so that build is only performed from the .c files (which are
-# distributed instead).
-psycopg_c =
-    py.typed
-    *.pyi
-    *.pxd
-    _psycopg/*.pxd
-    pq/*.pxd
-
-# In the psycopg-binary distribution don't include cython-related files.
-psycopg_binary =
-    py.typed
-    *.pyi
index 6d32b397640787fd8ceb6f05c3fc86ac39e6c056..5341d2a75a2cdc3c01250982fc69e36872cee0db 100644 (file)
@@ -30,7 +30,6 @@ sphinx-autobuild == 2021.3.14
 sphinx-autodoc-typehints == 1.12.0
 
 # Build tools
-setuptools == 49.2.0
 wheel == 0.37
 Cython == 3.0.0
 tomli == 2.0.1