2021-06-28 23:13:55 +00:00
{ stdenv
, lib
, buildPythonPackage
, pythonOlder
, isPyPy
, fetchPypi
, postgresql
, openssl
2022-06-16 17:23:12 +00:00
, sphinxHook
, sphinx-better-theme
2023-11-16 04:20:00 +00:00
, buildPackages
2021-06-28 23:13:55 +00:00
} :
2020-04-24 23:36:52 +00:00
buildPythonPackage rec {
pname = " p s y c o p g 2 " ;
2024-01-13 08:15:51 +00:00
version = " 2 . 9 . 9 " ;
2022-11-02 22:02:43 +00:00
format = " s e t u p t o o l s " ;
2020-04-24 23:36:52 +00:00
2020-11-21 19:51:51 +00:00
# Extension modules don't work well with PyPy. Use psycopg2cffi instead.
# c.f. https://github.com/NixOS/nixpkgs/pull/104151#issuecomment-729750892
2021-06-28 23:13:55 +00:00
disabled = pythonOlder " 3 . 6 " || isPyPy ;
2020-04-24 23:36:52 +00:00
2023-11-16 04:20:00 +00:00
outputs = [ " o u t " " d o c " ] ;
2020-04-24 23:36:52 +00:00
src = fetchPypi {
inherit pname version ;
2024-01-13 08:15:51 +00:00
hash = " s h a 2 5 6 - 0 U V L 3 p P 7 H i J B Z o E W l N Y A 5 0 Z D D A B v u w M e o G 7 M L q Q b 8 V Y = " ;
2020-04-24 23:36:52 +00:00
} ;
2023-11-16 04:20:00 +00:00
postPatch = ''
# Preferably upstream would not depend on pg_config because config scripts are incompatible with cross-compilation, however postgresql's pc file is lacking information.
# some linker flags are added but the linker ignores them because they're incompatible
# https://github.com/psycopg/psycopg2/blob/89005ac5b849c6428c05660b23c5a266c96e677d/setup.py
substituteInPlace setup . py \
- - replace " s e l f . p g _ c o n f i g _ e x e = s e l f . b u i l d _ e x t . p g _ c o n f i g " ' self . pg_config_exe = " ${ lib . getExe' buildPackages . postgresql " p g _ c o n f i g " } " '
'' ;
2022-11-02 22:02:43 +00:00
2021-06-28 23:13:55 +00:00
nativeBuildInputs = [
2022-06-16 17:23:12 +00:00
sphinxHook
sphinx-better-theme
2021-06-28 23:13:55 +00:00
] ;
2020-04-24 23:36:52 +00:00
2023-11-16 04:20:00 +00:00
buildInputs = [
postgresql
] ++ lib . optionals stdenv . isDarwin [
2021-06-28 23:13:55 +00:00
openssl
] ;
2022-06-26 10:26:21 +00:00
sphinxRoot = " d o c / s r c " ;
2022-11-02 22:02:43 +00:00
# Requires setting up a PostgreSQL database
2020-04-24 23:36:52 +00:00
doCheck = false ;
2022-11-02 22:02:43 +00:00
pythonImportsCheck = [
" p s y c o p g 2 "
] ;
2022-06-16 17:23:12 +00:00
2023-11-16 04:20:00 +00:00
disallowedReferences = lib . optionals ( stdenv . buildPlatform != stdenv . hostPlatform ) [ buildPackages . postgresql ] ;
2020-04-24 23:36:52 +00:00
meta = with lib ; {
description = " P o s t g r e S Q L d a t a b a s e a d a p t e r f o r t h e P y t h o n p r o g r a m m i n g l a n g u a g e " ;
2021-06-28 23:13:55 +00:00
homepage = " h t t p s : / / w w w . p s y c o p g . o r g " ;
2022-11-02 22:02:43 +00:00
license = with licenses ; [ lgpl3Plus zpl20 ] ;
2022-06-26 10:26:21 +00:00
maintainers = with maintainers ; [ ] ;
2020-04-24 23:36:52 +00:00
} ;
}