From: Daniele Varrazzo Date: Sun, 22 Dec 2024 01:43:43 +0000 (+0100) Subject: refactor(c): convert setup.cfg to pyproject.toml X-Git-Tag: 3.3.0.dev1~141^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=662791dc08fa5b1c9b62226d9c296c6597b45dee;p=thirdparty%2Fpsycopg.git refactor(c): convert setup.cfg to pyproject.toml Drop setup.py: move the build configuration to a build backend module. --- diff --git a/psycopg_c/setup.py b/psycopg_c/build_backend/psycopg_build_ext.py similarity index 56% rename from psycopg_c/setup.py rename to psycopg_c/build_backend/psycopg_build_ext.py index eeea1c945..f81d00d3b 100644 --- a/psycopg_c/setup.py +++ b/psycopg_c/build_backend/psycopg_build_ext.py @@ -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}, -) diff --git a/psycopg_c/pyproject.toml b/psycopg_c/pyproject.toml index 55c0504d6..f7a2ddefa 100644 --- a/psycopg_c/pyproject.toml +++ b/psycopg_c/pyproject.toml @@ -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 index 4a0079d57..000000000 --- a/psycopg_c/setup.cfg +++ /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 diff --git a/tests/constraints.txt b/tests/constraints.txt index 6d32b3976..5341d2a75 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -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