Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psycopg-pool extra is silently ignored #72

Open
genevieve-me opened this issue Mar 21, 2024 · 1 comment
Open

psycopg-pool extra is silently ignored #72

genevieve-me opened this issue Mar 21, 2024 · 1 comment

Comments

@genevieve-me
Copy link

genevieve-me commented Mar 21, 2024

I just tried packaging a python tool with pyproject.nix, and am running into some issues with psycopg-pool. It's a standalone package on pypi, but I pull it in as an extra: "psycopg[pool]~=3.1" under [dependencies] in pyproject.toml.

In nixpkgs, this package is under pkgs.python3Packages.psycopg.optional-dependencies.pool. When I was previously building this tool with pkgs.python3Packages.buildPythonApplication, I had something like:

    propagatedBuildInputs = with pkgs.python3Packages; [
      psycopg
      psycopg.optional-dependencies.pool
    ];

However, the following flake produces a python environment without psycopg-pool via nix develop, or a package that fails with ModuleNotFoundError for psycopg_pool when run after nix build:

{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  inputs.pyproject-nix.url = "github:nix-community/pyproject.nix";
  inputs.pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";

  outputs =
    { nixpkgs, pyproject-nix, ... }:
    let
      project = pyproject-nix.lib.project.loadPyproject { projectRoot = ./.; };
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      python = pkgs.python3;
    in
    {
      devShells.x86_64-linux.default =
        let
          arg = project.renderers.withPackages {
            inherit python;
          };
          pythonEnv = python.withPackages arg;
        in
        pkgs.mkShell { packages = [ pythonEnv ]; };

      packages.x86_64-linux.default =
        let
          attrs = project.renderers.buildPythonPackage { inherit python; extras = [ "dev" ]; };
        in
        python.pkgs.buildPythonPackage (attrs);
    };
}

What's odd is that if I add a pypi package that's not in nixpkgs to my pyproject.toml dependencies, the build fails with (for example) error: attribute 'ural' missing, which makes complete sense. I didn't see any code in pyproject.nix that would translate psycopg-pool into psycopg.optional-dependencies.pool, so I'm not sure why this is failing silently instead of loudly. (If I add psycopg-pool to my dependencies in pyproject.toml, it does fail in this way).

(PS: This tool is a lifesaver, thanks for your work on it!)

@genevieve-me
Copy link
Author

This one might be user error, but I also have a followup question: in order to work around this, I changed my pyproject.toml to include "psycopg-pool>=3.1",, and changed the above flake.nix
to include

      # removed: python = pkgs.python3;
      python = pkgs.python3.override {
        packageOverrides = self: super: {
          psycopg-pool = pkgs.python3Packages.psycopg.optional-dependencies.pool;
        };
      };

Now my build fails during pythonRuntimeDepsCheck with psycopg-pool>=3.1 not satisfied by version 3.1.10.dev1. I'm confused by this, since nixos-unstable is on version 3.1.17 (and as far as I could tell in the commit history, 3.1.10.dev1 was never in nixpkgs) - would appreciate if someone could shed some light on what's happening there.

(Plus, potentially relevant side note to the original issue - in my testing it seems the [pool] extra for psycopg gets totally ignored no matter what I do, which is surprising).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant