Skip to content

Optional dependencies in setup.py installed when not requested #571

@skeet70

Description

@skeet70

I've pasted a minimal reproduction flake.nix below. Running nix develop with this flake installs the optional tf dependencies even though they weren't requested.

This was noticed in our case when a developer on an M1 Mac tried to load the flake and it failed, because tensorflow-text isn't available pre-compiled on Mac.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:DavHau/mach-nix/3.5.0";
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        pytrec-eval = mach-nix.lib.${system}.buildPythonPackage {
          src = pkgs.fetchFromGitHub {
            owner = "cvangysel";
            repo = "pytrec_eval";
            rev = "0d8571efc2dea5a792358410d5affbe0ad383602";
            sha256 = "sha256-t76D3C5QMJgQMhAg8TGxdtjwaLQhlB8SufAdM3pAZg4=";
            fetchSubmodules = true;
          };
          pname = "pytrec_eval";
          version = "0.5";
          requirements = ''
            numpy>=1.15.1
            scipy>=1.1.0
          '';
        };
        pythonEnv = mach-nix.lib.${system}.mkPython
          {
            requirements = ''
              beir
            '';
            packagesExtra = [ pytrec-eval ];
            providers.torch = "nixpkgs";
            overridesPost = [
              (curr: prev: {
                torch = prev.torch.override {
                  cudaSupport = true;
                };
              })
            ];
          };
      in
      {
        devShell = pkgs.mkShell {
          nativeBuildInputs = [ ];
          buildInputs = [
            pythonEnv
          ];
        };
      });
}
pipdeptree
beir==0.2.2
  - elasticsearch [required: Any, installed: 7.17.0]
  - faiss-cpu [required: Any, installed: 1.7.2]
  - pytrec-eval [required: Any, installed: 0.5]
  - sentence-transformers [required: Any, installed: 2.1.0]
  - tensorflow [required: >=2.2.0, installed: 2.7.1]
  - tensorflow-hub [required: Any, installed: 0.12.0]
  - tensorflow-text [required: Any, installed: 2.7.3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions