Skip to content

Commit

Permalink
Use binary or c variant of psycopg depending on system
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin committed Nov 11, 2024
1 parent 7eddaeb commit 9c48a44
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
devShells = forAllSystems (system:
let
pkgs = pkgsFor.${system};
extras = if pkgs.stdenv.isDarwin then [ "psycopg-c" ] else [ "psycopg-binary" ];
in
rec {
evap = pkgs.callPackage ./nix/shell.nix {
inherit (self.packages.${system}) python3;
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
inherit extras;
};
evap-dev = evap.override { poetry-groups = [ "dev" ]; };
default = evap-dev;
Expand Down
15 changes: 13 additions & 2 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, python3, poetry2nix, pyproject, poetrylock, poetry-groups ? [ ], extraPackages ? [ ], extraPythonPackages ? (ps: [ ]), ... }:
{ pkgs, lib ? pkgs.lib, python3, poetry2nix, pyproject, poetrylock, extras ? [ ], poetry-groups ? [ ], extraPackages ? [ ], extraPythonPackages ? (ps: [ ]), ... }:

let
# When running a nix shell, XDG_DATA_DIRS will be populated so that bash_completion can (lazily) find this completion script
Expand All @@ -17,11 +17,22 @@ let
poetry-env = poetry2nix.mkPoetryEnv {
python = python3;
# We pass these instead of `projectDir` to avoid adding the dependency on other files.
inherit pyproject poetrylock;
inherit pyproject poetrylock extras;
preferWheels = true;
overrides = poetry2nix.overrides.withDefaults (final: prev: {
# https://github.com/nix-community/poetry2nix/issues/1499
django-stubs-ext = prev.django-stubs-ext.override { preferWheel = false; };

psycopg = prev.psycopg.overridePythonAttrs (old: {
buildInputs = old.buildInputs or [ ]
++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.openssl ];
propagatedBuildInputs = old.propagatedBuildInputs or [ ] ++ [ pkgs.postgresql ];
});

psycopg-c = prev.psycopg-c.overridePythonAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ pkgs.postgresql ];
propagatedBuildInputs = old.propagatedBuildInputs or [ ] ++ [ final.setuptools ];
});
});
groups = poetry-groups;
checkGroups = [ ]; # would otherwise always install dev-dependencies
Expand Down
19 changes: 16 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ django-fsm = "~2.8.2"
Django = "~5.1.0"
mozilla-django-oidc = "~4.0.1"
openpyxl = "~3.1.5"
psycopg = { version = "~3.2.3", extras = ["binary"] }
psycopg = { version = "~3.2.3", extras = [] }
psycopg-c = { version = "~3.2.3", optional = true }
psycopg-binary = { version = "~3.2.3", optional = true }
redis = "~5.2.0"
typing-extensions = "~4.12.2"
xlwt = "~1.3.0"
Expand All @@ -34,6 +36,10 @@ tblib = "~3.0.0"
xlrd = "~2.0.1"
typeguard = "~4.4.0"

[tool.poetry.extras]
psycopg-c = ["psycopg-c"]
psycopg-binary = ["psycopg-binary"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit 9c48a44

Please sign in to comment.