anchor.diff:      pytest-randomly
       pytestCheckHook
       postgresql
  -  ];
  +  ]
  +  ++ passthru.optional-dependencies.c
  +  ++ passthru.optional-dependencies.pool;
   
     disabledTests = [
  -    # linters shouldn't be run in checks
  +    # don't depend on mypy for tests
       "test_version"
  +    "test_package_version"
     ];
   
     disabledTestPaths = [
  -    # TODO: requires the pooled variant
  -    "tests/pool/"
       # Network access
       "tests/test_dns.py"
       "tests/test_dns_srv.py"
  
positive.code:     hash = "sha256-jKhpmCcDi7FyMSpn51eSukFvmu3yacNovmRYG9jnu3g=";
    };
  
    outputs = [
      "out"
      "doc"
    ];
  
    sphinxRoot = "../docs";
  
    # Introduce this file necessary for the docs build via environment var
    LIBPQ_DOCS_FILE = fetchurl {
      url = "https://raw.githubusercontent.com/postgres/postgres/REL_14_STABLE/doc/src/sgml/libpq.sgml";
      hash = "sha256-yn09fR9+7zQni8SvTG7BUmYRD7MK7u2arVAznWz2oAw=";
    };
  
    patches = [
      (substituteAll {
        src = ./libpq.patch;
  
negative.code:     })
    ];
  
    baseMeta = {
      changelog = "https://github.com/psycopg/psycopg/blob/master/docs/news.rst";
      homepage = "https://github.com/psycopg/psycopg";
      license = lib.licenses.lgpl3Plus;
      maintainers = with lib.maintainers; [ hexa ];
    };
  
    psycopg-c = buildPythonPackage {
      pname = "${pname}-c";
      inherit version src;
      format = "pyproject";
  
      # apply patches to base repo
      inherit patches;
  
      # move into source root after patching
      postPatch = ''
        cd psycopg_c
      '';
  
      nativeBuildInputs = [
        setuptools
        cython_3
        postgresql
      ];
  
      # tested in psycopg
      doCheck = false;
  
      meta = baseMeta // {
        description = "C optimisation distribution for Psycopg";
      };
    };
  
    psycopg-pool = buildPythonPackage {
      pname = "${pname}-pool";
      inherit version src;
      format = "setuptools";
  
      # apply patches to base repo
      inherit patches;
  
      # move into source root after patching
      postPatch = ''
        cd psycopg_pool
      '';
  
      propagatedBuildInputs = lib.optionals (pythonOlder "3.10") [
        typing-extensions
      ];
  
      # tested in psycopg
      doCheck = false;
  
      meta = baseMeta // {
        description = "Connection Pool for Psycopg";
      };
    };
  
  in
  
  buildPythonPackage rec {
    inherit pname version src;
    format = "pyproject";
  
    disabled = pythonOlder "3.7";
  
    outputs = [
      "out"
      "doc"
    ];
  
    sphinxRoot = "../docs";
  
    # Introduce this file necessary for the docs build via environment var
    LIBPQ_DOCS_FILE = fetchurl {
      url = "https://raw.githubusercontent.com/postgres/postgres/REL_14_STABLE/doc/src/sgml/libpq.sgml";
      hash = "sha256-yn09fR9+7zQni8SvTG7BUmYRD7MK7u2arVAznWz2oAw=";
    };
  
    inherit patches;
  
    # only move to sourceRoot after patching, makes patching easier
    postPatch = ''
      cd psycopg
    '';
  
    nativeBuildInputs = [
      furo
      setuptools
      shapely
      sphinx-autodoc-typehints
      sphinxHook
    ];
  
    propagatedBuildInputs = [
      psycopg-c
    ] ++ lib.optionals (pythonOlder "3.11") [
      typing-extensions
    ] ++ lib.optionals (pythonOlder "3.9") [
      backports-zoneinfo
  