Packaging/Python: Difference between revisions

Add a section to explain how to locally test a packaged Python library
Improve flake.nix in "Testing out a module in a Python shell" (remove need to manually spell out python deps)
Line 24: Line 24:


   inputs = {
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
     flake-utils.url = "github:numtide/flake-utils";
     flake-utils.url = "github:numtide/flake-utils";
   };
   };
Line 32: Line 32:
       let
       let
         pkgs = import nixpkgs { inherit system; };
         pkgs = import nixpkgs { inherit system; };
         python = pkgs.python3;
         xacro = pkgs.python3Packages.callPackage ./derivation.nix {
        # replace ./default.nix with the path to your derivation, relative to this file
        mypackage = pkgs.callPackage ./default.nix {
          inherit (python.pkgs) buildPythonPackage package names of dependencies here;
           lib = pkgs.lib;
           lib = pkgs.lib;
         };
         };
       in {
       in {
         devShells.default = pkgs.mkShell {
         devShells.default = pkgs.mkShell {
           buildInputs = [ python mypackage ];
           buildInputs = [ pkgs.python3 xacro ];
         };
         };
       });
       });
}
}
</syntaxhighlight>Replace "mypackage" with your package name, and "package names of dependencies here" with a (space-separated) list of the dependencies you listed in your buildPythonPackage call.
</syntaxhighlight>Replace "mypackage" with your package name. Then, enter the devShell and launch a Python REPL:<syntaxhighlight lang="shell-session">
 
Next, enter the devShell and launch a Python REPL:<syntaxhighlight lang="shell-session">
$ nix develop
$ nix develop
$ python
$ python