nix-init icon indicating copy to clipboard operation
nix-init copied to clipboard

Update python derivation template

Open mweinelt opened this issue 1 year ago • 2 comments

  • setuptools builds don't actually require specifying wheel, which can be seen in the example¹ in the setuptools documentation.
  • migrate from
    • nativeBuildInputs to build-system
    • propagatedBuildInputs to dependencies
    • passthru.optional-dependencies to optional-dependencies
  • Expand pythonImportsCheck, so the item is on a new line.

[1] https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

The primary motivation is to save me many review remarks. I don't generally write rust, so feel free to improve the code.

The new pyproject lingo for the inputs has been introduced on master and will be part of NixOS 24.05.

old

{ lib
, buildPythonPackage
, fetchFromGitHub
, setuptools
, wheel
, cryptography
, pycryptodome
}:

buildPythonPackage rec {
  pname = "joserfc";
  version = "0.9.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "authlib";
    repo = "joserfc";
    rev = version;
    hash = "sha256-+NFCveMPzE0hSs2Qe20/MDHApXVtU3cR/GPFKPqfVV4=";
  };

  nativeBuildInputs = [
    setuptools
    wheel
  ];

  propagatedBuildInputs = [
    cryptography
  ];

  passthru.optional-dependencies = {
    drafts = [
      pycryptodome
    ];
  };

  pythonImportsCheck = [ "joserfc" ];

  meta = with lib; {
    description = "Implementations of JOSE RFCs in Python";
    homepage = "https://github.com/authlib/joserfc";
    license = licenses.bsd3;
    maintainers = with maintainers; [ ];
  };
}

new

{ lib
, buildPythonPackage
, fetchFromGitHub
, setuptools
, cryptography
, pycryptodome
}:

buildPythonPackage rec {
  pname = "joserfc";
  version = "0.9.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "authlib";
    repo = "joserfc";
    rev = version;
    hash = "sha256-+NFCveMPzE0hSs2Qe20/MDHApXVtU3cR/GPFKPqfVV4=";
  };

  build-system = [
    setuptools
  ];

  dependencies = [
    cryptography
  ];

  optional-dependencies = {
    drafts = [
      pycryptodome
    ];
  };

  pythonImportsCheck = [
    "joserfc"
  ];

  meta = with lib; {
    description = "Implementations of JOSE RFCs in Python";
    homepage = "https://github.com/authlib/joserfc";
    license = licenses.bsd3;
    maintainers = with maintainers; [ ];
  };
}

mweinelt avatar Mar 11 '24 02:03 mweinelt

Friendly ping, two months in.

mweinelt avatar May 06 '24 16:05 mweinelt

@figsoda ^^

drupol avatar May 10 '24 06:05 drupol

Now with the lambda input style used by nixfmt:

{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  setuptools,
  cryptography,
  pycryptodome,
}:

buildPythonPackage rec {
  pname = "joserfc";
  version = "0.9.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "authlib";
    repo = "joserfc";
    rev = version;
    hash = "sha256-+NFCveMPzE0hSs2Qe20/MDHApXVtU3cR/GPFKPqfVV4=";
  };

  build-system = [
    setuptools
  ];

  dependencies = [
    cryptography
  ];

  optional-dependencies = {
    drafts = [
      pycryptodome
    ];
  };

  pythonImportsCheck = [
    "joserfc"
  ];

  meta = with lib; {
    description = "Implementations of JOSE RFCs in Python";
    homepage = "https://github.com/authlib/joserfc";
    license = licenses.bsd3;
    maintainers = with maintainers; [ ];
  };
}

mweinelt avatar Jul 08 '24 04:07 mweinelt

What is lambda input style ?

drupol avatar Jul 08 '24 04:07 drupol

What is lambda input style ?

  • lambda is another word for a function
  • input is another way of saying parameters (arguments).

They're saying that nixfmt (RFC 166) renders the function parameters like this:

{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  setuptools,
  cryptography,
  pycryptodome,
}:

Whereas the old formatting was this:

{ lib
, buildPythonPackage
, fetchFromGitHub
, setuptools
, cryptography
, pycryptodome
}:

MattSturgeon avatar Jul 08 '24 05:07 MattSturgeon

Interesting, thank you! TIL !

drupol avatar Jul 08 '24 05:07 drupol