1{ lib
2, buildPythonPackage
3, pythonOlder
4, fetchFromGitHub
5, fetchpatch
6, poetry-core
7, pymongo
8, pytestCheckHook
9}:
10
11buildPythonPackage rec {
12 pname = "pymongo-inmemory";
13 version = "0.4.0";
14 format = "pyproject";
15
16 disabled = pythonOlder "3.7";
17
18 src = fetchFromGitHub {
19 owner = "kaizendorks";
20 repo = "pymongo_inmemory";
21 rev = "refs/tags/v${version}";
22 hash = "sha256-h6/yKvAHqvw0L3Z1+PUQi36Ja6yvFiaX7Cn5Ypcg1Zs=";
23 };
24
25 postPatch = ''
26 # move cache location from nix store to home
27 substituteInPlace pymongo_inmemory/context.py \
28 --replace \
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 \
35 'os.mkdir(current_path)' \
36 'os.makedirs(current_path)'
37 '';
38
39 nativeBuildInputs = [
40 poetry-core
41 ];
42
43 propagatedBuildInputs = [
44 pymongo
45 ];
46
47 nativeCheckInputs = [
48 pytestCheckHook
49 ];
50
51 disabledTestPaths = [
52 # new test with insufficient monkey patching, try to remove on next bump
53 "tests/unit/test_mongod.py"
54 ];
55
56 preCheck = ''
57 export HOME="$(mktemp -d)"
58 '';
59
60 pythonImportsCheck = [
61 "pymongo_inmemory"
62 ];
63
64 meta = {
65 homepage = "https://github.com/kaizendorks/pymongo_inmemory";
66 description = "A mongo mocking library with an ephemeral MongoDB running in memory";
67 maintainers = with lib.maintainers; [ pbsds ];
68 license = lib.licenses.mit;
69 };
70}