Why "poetry lock" doesn't use the poetry2nix environment

Why poetry lock tries to resolve dependencies for python3.12 instead of python3.10?

$ nix flake update
$ nix develop
$ python3 --version
Python 3.10.15
$ poetry env list
chesscog-qlTStFyU-py3.10 (Activated)
$ poetry lock
Updating dependencies
Resolving dependencies... (6.2s)/nix/store/m778xmxzmbpmbp8qbjc88zp1sm6i5m1l-python3.12-pkginfo-1.11.1/lib/python3.12/site-packages/pkginfo/distribution.py:175: NewMetadataVersion: New metadata version (2.4) higher than latest supported version: parsing as 2.3
warnings.warn(NewMetadataVersion(self.metadata_version))

Unknown metadata version: 2.4
  • flake.nix
{
  description = "Application packaged using poetry2nix";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs?rev=75e28c029ef2605f9841e0baa335d70065fe7ae2";
    poetry2nix = {
      url = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            poetry2nix.overlays.default
          ];
        };

        poetryEnv = pkgs.poetry2nix.mkPoetryEnv {
          python = pkgs.python310;
          pyproject = ./pyproject.toml;
          poetrylock = ./poetry.lock;
          projectDir = ./.;
        };
      in
      {
        packages.default = poetryEnv;

        devShells = {
          default = pkgs.mkShell {
            packages = [ pkgs.poetry pkgs.python310 ];
            shellHook = ''
              export PYTHON=$(which python3.10)
              poetry env use $PYTHON
            '';
          };
        };

        legacyPackages = pkgs;
      }
    );
}
  • pyproject.toml
[build-system]
requires = [ "poetry>=0.12",]
build-backend = "poetry.masonry.api"

[tool.poetry]
...
include = [ "config/*.yaml", "config/**/_*.yaml",]
[[tool.poetry.packages]]
include = "chesscog"

[tool.poetry.dependencies]
python = ">=3.9,<3.11"
sphinx = { version = "^4.1.2", optional = true }
sphinx-rtd-theme = { version = "^0.5.2", optional = true }
m2r2 = { version = "^0.3.1", optional = true }
opencv-python = "^4.5.3"
numpy = "^1.21.2"
Pillow = "^8.3.1"
matplotlib = "^3.4.3"
torch = "^1.9.1"
torchvision = "^0.10.0"
tensorboard = "^2.6.0"
pandas = "^1.3.2"
scikit-learn = "^0.24.2"
tqdm = "^4.62.2"
googledrivedownloader = "^0.4"
recap = "^0.1.6"
chess = "^1.6.1"
osfclient = "^0.0.5"
setuptools = "59.5.0"

[tool.poetry.dev-dependencies]
jupyterlab = "^2.2.8"
autopep8 = "^1.5.4"
pylint = "^2.6.0"
pytest = "^6.1.1"
toml = "^0.10.2"
pdoc3 = "^0.9.2"

[tool.poetry.extras]
docs = ["sphinx", "sphinx-rtd-theme", "m2r2"]

It turned out chess dependency is the root cause of the problem.

$ poetry init 
..

Generated file

[tool.poetry]
name = "x"
version = "0.1.0"
..
[tool.poetry.dependencies]
python = "^3.12"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
$ poetry lock 
Updating dependencies
Resolving dependencies... (0.1s)
$ poetry add chess
Using version ^1.11.2 for chess

Updating dependencies
Resolving dependencies... (8.0s)/nix/store/m778xmxzmbpmbp8qbjc88zp1sm6i5m1l-python3.12-pkginfo-1.11.1/lib/python3.12/site-packages/pkginfo/distribution.py:175: NewMetadataVersion: New metadata version (2.4) higher than latest supported version: parsing as 2.3
  warnings.warn(NewMetadataVersion(self.metadata_version))

Unknown metadata version: 2.4

Have you stumbled across poetry 1.8.3 fails to install python wheel package with metadata 2.4 · Issue #9885 · python-poetry/poetry · GitHub yet?

Your pinned version of nixpkgs includes Poetry 1.8.4, that results in this particular error:

The above issue from GitHub tells us that the next release of Poetry 1.8.5 loosens the handling of the metadata versions and your module should be “addable” again.

You could either bump your nixpkgs to at least 8c9fd3e564728e90829ee7dbac6edc972971cd0f or use a newer poetry.

Hope it helps!

1 Like