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 " ;
2023-11-16 04:20:00 +00:00
version = " 2 . 9 . 7 " ;
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 ;
2023-11-16 04:20:00 +00:00
hash = " s h a 2 5 6 - 8 A z D W 9 c R n x / t F 7 h b 0 Q B 4 V R l N 3 i y 9 j e A a u O u x d I d E C t g = " ;
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
} ;
}