1{ stdenv 2, lib 3, buildPythonPackage 4, pythonOlder 5, isPyPy 6, fetchPypi 7, postgresql 8, openssl 9, sphinxHook 10, sphinx-better-theme 11, buildPackages 12}: 13 14buildPythonPackage rec { 15 pname = "psycopg2"; 16 version = "2.9.7"; 17 format = "setuptools"; 18 19 # Extension modules don't work well with PyPy. Use psycopg2cffi instead. 20 # c.f. https://github.com/NixOS/nixpkgs/pull/104151#issuecomment-729750892 21 disabled = pythonOlder "3.6" || isPyPy; 22 23 outputs = [ "out" "doc" ]; 24 25 src = fetchPypi { 26 inherit pname version; 27 hash = "sha256-8AzDW9cRnx/tF7hb0QB4VRlN3iy9jeAauOuxdIdECtg="; 28 }; 29 30 postPatch = '' 31 # Preferably upstream would not depend on pg_config because config scripts are incompatible with cross-compilation, however postgresql's pc file is lacking information. 32 # some linker flags are added but the linker ignores them because they're incompatible 33 # https://github.com/psycopg/psycopg2/blob/89005ac5b849c6428c05660b23c5a266c96e677d/setup.py 34 substituteInPlace setup.py \ 35 --replace "self.pg_config_exe = self.build_ext.pg_config" 'self.pg_config_exe = "${lib.getExe' buildPackages.postgresql "pg_config"}"' 36 ''; 37 38 nativeBuildInputs = [ 39 sphinxHook 40 sphinx-better-theme 41 ]; 42 43 buildInputs = [ 44 postgresql 45 ] ++ lib.optionals stdenv.isDarwin [ 46 openssl 47 ]; 48 49 sphinxRoot = "doc/src"; 50 51 # Requires setting up a PostgreSQL database 52 doCheck = false; 53 54 pythonImportsCheck = [ 55 "psycopg2" 56 ]; 57 58 disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ buildPackages.postgresql ]; 59 60 meta = with lib; { 61 description = "PostgreSQL database adapter for the Python programming language"; 62 homepage = "https://www.psycopg.org"; 63 license = with licenses; [ lgpl3Plus zpl20 ]; 64 maintainers = with maintainers; [ ]; 65 }; 66}