summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/pymongo-inmemory/default.nix
blob: 7235560bfff028d7ba4cbf2ef323323480e76340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  poetry-core,
  pymongo,
  pytestCheckHook,
}:

buildPythonPackage rec {
  pname = "pymongo-inmemory";
  version = "0.5.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "kaizendorks";
    repo = "pymongo_inmemory";
    tag = "v${version}";
    hash = "sha256-iYUU2XoTEfgUm+816wHveu6dPEo6nzhlZNXyuRw42T0=";
  };

  postPatch = ''
    # move cache location from nix store to home
    substituteInPlace pymongo_inmemory/context.py \
      --replace-fail \
        'CACHE_FOLDER = path.join(path.dirname(__file__), "..", ".cache")' \
        'CACHE_FOLDER = os.environ.get("XDG_CACHE_HOME", os.environ["HOME"] + "/.cache") + "/pymongo-inmemory"'

    # fix a broken assumption arising from the above fix
    substituteInPlace pymongo_inmemory/_utils.py \
      --replace-fail \
        'os.mkdir(current_path)' \
        'os.makedirs(current_path)'
  '';

  nativeBuildInputs = [ poetry-core ];

  dependencies = [ pymongo ];

  nativeCheckInputs = [ pytestCheckHook ];

  disabledTestPaths = [
    # new test with insufficient monkey patching, try to remove on next bump
    "tests/unit/test_mongod.py"
  ];

  preCheck = ''
    export HOME="$(mktemp -d)"
  '';

  pythonImportsCheck = [ "pymongo_inmemory" ];

  meta = {
    homepage = "https://github.com/kaizendorks/pymongo_inmemory";
    description = "Mongo mocking library with an ephemeral MongoDB running in memory";
    maintainers = with lib.maintainers; [ pbsds ];
    license = lib.licenses.mit;
  };
}