2022-07-17 19:02:53 +00:00
|
|
|
{ lib
|
2022-08-13 21:31:32 +00:00
|
|
|
, stdenv
|
2022-07-17 19:02:53 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchurl
|
|
|
|
, pythonOlder
|
|
|
|
, substituteAll
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
# build
|
2022-07-17 19:02:53 +00:00
|
|
|
, postgresql
|
2022-08-14 11:09:07 +00:00
|
|
|
, setuptools
|
2022-07-17 19:02:53 +00:00
|
|
|
|
|
|
|
# propagates
|
|
|
|
, backports-zoneinfo
|
|
|
|
, typing-extensions
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
# psycopg-c
|
|
|
|
, cython_3
|
|
|
|
|
2022-07-17 19:02:53 +00:00
|
|
|
# docs
|
|
|
|
, furo
|
|
|
|
, shapely
|
|
|
|
, sphinxHook
|
|
|
|
, sphinx-autodoc-typehints
|
|
|
|
|
|
|
|
# tests
|
|
|
|
, pproxy
|
|
|
|
, pytest-asyncio
|
|
|
|
, pytest-randomly
|
|
|
|
, pytestCheckHook
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
pname = "psycopg";
|
2022-10-05 12:45:56 +00:00
|
|
|
version = "3.1.3";
|
2022-07-17 19:02:53 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "psycopg";
|
|
|
|
repo = pname;
|
2022-08-30 12:25:36 +00:00
|
|
|
rev = "refs/tags/${version}";
|
2022-10-05 12:45:56 +00:00
|
|
|
hash = "sha256-cAfFxUDgfI3KTlBU9wV/vQkPun4cR3se8eSIHHcEr4g=";
|
2022-07-17 19:02:53 +00:00
|
|
|
};
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
patches = [
|
|
|
|
(substituteAll {
|
2022-09-06 00:56:33 +00:00
|
|
|
src = ./ctypes.patch;
|
2022-08-14 11:09:07 +00:00
|
|
|
libpq = "${postgresql.lib}/lib/libpq${stdenv.hostPlatform.extensions.sharedLibrary}";
|
2022-09-06 00:56:33 +00:00
|
|
|
libc = "${stdenv.cc.libc}/lib/libc.so.6";
|
2022-08-14 11:09:07 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2022-07-17 19:02:53 +00:00
|
|
|
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=";
|
|
|
|
};
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
inherit patches;
|
2022-07-17 19:02:53 +00:00
|
|
|
|
|
|
|
# only move to sourceRoot after patching, makes patching easier
|
|
|
|
postPatch = ''
|
2022-08-14 11:09:07 +00:00
|
|
|
cd psycopg
|
2022-07-17 19:02:53 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
furo
|
2022-08-14 11:09:07 +00:00
|
|
|
setuptools
|
2022-07-17 19:02:53 +00:00
|
|
|
shapely
|
|
|
|
sphinx-autodoc-typehints
|
2022-08-14 11:09:07 +00:00
|
|
|
sphinxHook
|
2022-07-17 19:02:53 +00:00
|
|
|
];
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
psycopg-c
|
|
|
|
] ++ lib.optionals (pythonOlder "3.11") [
|
2022-07-17 19:02:53 +00:00
|
|
|
typing-extensions
|
|
|
|
] ++ lib.optionals (pythonOlder "3.9") [
|
|
|
|
backports-zoneinfo
|
|
|
|
];
|
|
|
|
|
|
|
|
pythonImportsCheck = [
|
|
|
|
"psycopg"
|
2022-08-14 11:09:07 +00:00
|
|
|
"psycopg_c"
|
|
|
|
"psycopg_pool"
|
2022-07-17 19:02:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
passthru.optional-dependencies = {
|
2022-08-14 11:09:07 +00:00
|
|
|
c = [ psycopg-c ];
|
|
|
|
pool = [ psycopg-pool ];
|
2022-07-17 19:02:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
preCheck = ''
|
|
|
|
cd ..
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkInputs = [
|
|
|
|
pproxy
|
|
|
|
pytest-asyncio
|
|
|
|
pytest-randomly
|
|
|
|
pytestCheckHook
|
|
|
|
postgresql
|
2022-08-14 11:09:07 +00:00
|
|
|
]
|
|
|
|
++ passthru.optional-dependencies.c
|
|
|
|
++ passthru.optional-dependencies.pool;
|
2022-07-17 19:02:53 +00:00
|
|
|
|
|
|
|
disabledTests = [
|
2022-08-14 11:09:07 +00:00
|
|
|
# don't depend on mypy for tests
|
2022-07-17 19:02:53 +00:00
|
|
|
"test_version"
|
2022-08-14 11:09:07 +00:00
|
|
|
"test_package_version"
|
python3Packages.psycopg: disable test_sched{,_error} on darwin
They are prone to race conditions.
```
_______________________________ test_sched_error _______________________________
caplog = <_pytest.logging.LogCaptureFixture object at 0x197218a90>
@pytest.mark.slow
def test_sched_error(caplog):
caplog.set_level(logging.WARNING, logger="psycopg")
s = Scheduler()
t = Thread(target=s.run, daemon=True)
t.start()
results = []
def worker(i):
results.append((i, time()))
def error():
1 / 0
t0 = time()
s.enter(0.1, partial(worker, 1))
s.enter(0.4, None)
s.enter(0.3, partial(worker, 2))
s.enter(0.2, error)
t.join()
t1 = time()
assert t1 - t0 == pytest.approx(0.4, 0.1)
assert len(results) == 2
assert results[0][0] == 1
> assert results[0][1] - t0 == pytest.approx(0.1, 0.1)
E assert 0.11003494262695312 == 0.1 ± 1.0e-02
E comparison failed
E Obtained: 0.11003494262695312
E Expected: 0.1 ± 1.0e-02
tests/pool/test_sched.py:93: AssertionError
```
2022-08-14 18:35:47 +00:00
|
|
|
] ++ lib.optionals (stdenv.isDarwin) [
|
|
|
|
# racy test
|
|
|
|
"test_sched"
|
|
|
|
"test_sched_error"
|
2022-07-17 19:02:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
disabledTestPaths = [
|
|
|
|
# Network access
|
|
|
|
"tests/test_dns.py"
|
|
|
|
"tests/test_dns_srv.py"
|
|
|
|
# Mypy typing test
|
|
|
|
"tests/test_typing.py"
|
2022-08-30 12:25:36 +00:00
|
|
|
"tests/crdb/test_typing.py"
|
2022-07-17 19:02:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
pytestFlagsArray = [
|
|
|
|
"-o cache_dir=$TMPDIR"
|
|
|
|
];
|
|
|
|
|
|
|
|
postCheck = ''
|
|
|
|
cd ${pname}
|
|
|
|
'';
|
|
|
|
|
2022-08-14 11:09:07 +00:00
|
|
|
passthru = {
|
|
|
|
c = psycopg-c;
|
|
|
|
pool = psycopg-pool;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = baseMeta // {
|
2022-07-17 19:02:53 +00:00
|
|
|
description = "PostgreSQL database adapter for Python";
|
|
|
|
};
|
|
|
|
}
|