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.3.1";
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-1v36cI6JjDZA/uJE85NSMNnoyKI1VCgDrymfnCkpVqU=";
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 preCheck = ''
52 export HOME="$(mktemp -d)"
53 '';
54
55 pythonImportsCheck = [
56 "pymongo_inmemory"
57 ];
58
59 meta = {
60 homepage = "https://github.com/kaizendorks/pymongo_inmemory";
61 description = "A mongo mocking library with an ephemeral MongoDB running in memory";
62 maintainers = with lib.maintainers; [ pbsds ];
63 license = lib.licenses.mit;
64 };
65}