summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/django-postgres-extra/default.nix
blob: 9a4538d4d444aa201e542731777b6365d6a13baa (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  setuptools,
  django,
  python-dateutil,
  # test dependencies
  dj-database-url,
  freezegun,
  postgresql,
  psycopg2,
  pytest-django,
  pytest-freezegun,
  pytest-lazy-fixture,
  pytestCheckHook,
}:
buildPythonPackage rec {
  pname = "django-postgres-extra";
  version = "2.0.9";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "SectorLabs";
    repo = "django-postgres-extra";
    rev = "v${version}";
    hash = "sha256-/2qoXZ2f3un2cgJFAGMnQWBraJ7urkb0kHtcKKJsh6w=";
  };

  build-system = [ setuptools ];

  dependencies = [
    django
    python-dateutil
  ];

  nativeCheckInputs = [
    dj-database-url
    freezegun
    postgresql
    psycopg2
    pytest-django
    pytest-freezegun
    pytest-lazy-fixture
    pytestCheckHook
  ];

  preCheck = ''
    # Start Postgres.
    export PGDATA="$NIX_BUILD_TOP/.postgres"
    export PGHOST="$PGDATA/run"
    export DATABASE_URL=postgresql://''${PGHOST//\//%2F}/psqlextra
    initdb -E UTF8
    mkdir -p "$PGDATA/run"
    cat <<EOF >> "$PGDATA/postgresql.conf"
    unix_socket_directories = '$PGDATA/run'
    EOF
    echo "CREATE DATABASE psqlextra" | postgres --single -E postgres
    echo "Starting Postgres at $PGDATA" >&2
    pg_ctl start -w
  '';

  postCheck = ''
    echo "Stopping Postgres at $PGDATA" >&2
    pg_ctl stop -w
  '';

  disabledTests = [
    "test_management_command_partition_auto_confirm"
    "test_management_command_partition_confirm_no"
    "test_management_command_partition_confirm_yes"
    "test_management_command_partition_dry_run"
  ]
  # tests incompatible with django>=5
  ++ lib.optionals (lib.versionAtLeast django.version "5") [
    "test_schema_editor_clone_model_to_schema"
    "test_schema_editor_clone_model_to_schema_custom_constraint_names"
  ]
  # tests incompatible with django>=5.2
  ++ lib.optionals (lib.versionAtLeast django.version "5.2") [
    "test_query_annotate_rename_chain"
  ];

  pythonImportsCheck = [ "psqlextra" ];

  meta = {
    description = "Bringing all of PostgreSQL's awesomeness to Django";
    homepage = "https://github.com/SectorLabs/django-postgres-extra";
    changelog = "https://github.com/SectorLabs/django-postgres-extra/releases/tag/v${version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ b4dm4n ];
  };
}