1{
2 lib,
3 buildPythonPackage,
4 pythonOlder,
5 fetchFromGitHub,
6 poetry-core,
7 pymongo,
8 pytestCheckHook,
9}:
10
11buildPythonPackage rec {
12 pname = "pymongo-inmemory";
13 version = "0.5.0";
14 format = "pyproject";
15
16 disabled = pythonOlder "3.7";
17
18 src = fetchFromGitHub {
19 owner = "kaizendorks";
20 repo = "pymongo_inmemory";
21 tag = "v${version}";
22 hash = "sha256-iYUU2XoTEfgUm+816wHveu6dPEo6nzhlZNXyuRw42T0=";
23 };
24
25 postPatch = ''
26 # move cache location from nix store to home
27 substituteInPlace pymongo_inmemory/context.py \
28 --replace-fail \
29 'CACHE_FOLDER = path.join(path.dirname(__file__), "..", ".cache")' \
30 'CACHE_FOLDER = os.environ.get("XDG_CACHE_HOME", os.environ["HOME"] + "/.cache") + "/pymongo-inmemory"'
31
32 # fix a broken assumption arising from the above fix
33 substituteInPlace pymongo_inmemory/_utils.py \
34 --replace-fail \
35 'os.mkdir(current_path)' \
36 'os.makedirs(current_path)'
37 '';
38
39 nativeBuildInputs = [ poetry-core ];
40
41 dependencies = [ pymongo ];
42
43 nativeCheckInputs = [ pytestCheckHook ];
44
45 disabledTestPaths = [
46 # new test with insufficient monkey patching, try to remove on next bump
47 "tests/unit/test_mongod.py"
48 ];
49
50 preCheck = ''
51 export HOME="$(mktemp -d)"
52 '';
53
54 pythonImportsCheck = [ "pymongo_inmemory" ];
55
56 meta = {
57 homepage = "https://github.com/kaizendorks/pymongo_inmemory";
58 description = "Mongo mocking library with an ephemeral MongoDB running in memory";
59 maintainers = with lib.maintainers; [ pbsds ];
60 license = lib.licenses.mit;
61 };
62}