Skip to content

Commit

Permalink
template/python: use uv2nix infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
42LoCo42 committed Dec 12, 2024
1 parent e2a8369 commit 46ba48d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/ncps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pkgs: pkgs.buildGoModule rec {
pipe ./db-helper.sh [
(x: pkgs.writeShellApplication {
name = "${pname}-db-helper";
runtimeInputs = with pkgs; [ dbmate ];
runtimeInputs = with pkgs; [ coreutils dbmate ];
text = builtins.readFile x;
})
(x: ''
Expand Down
6 changes: 4 additions & 2 deletions templates/python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.direnv
/result
*.egg-info
.direnv
__pycache__
result
Empty file added templates/python/README.md
Empty file.
58 changes: 40 additions & 18 deletions templates/python/flake.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
{
outputs = { flake-utils, nixpkgs, ... }:
inputs = {
pyproject.url = "pyproject-nix/build-system-pkgs";
pyproject.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { flake-utils, nixpkgs, pyproject, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
python = pkgs.python3;
pyenv = python.withPackages (p: with p; [
]);
in
rec {
packages.default = python.pkgs.buildPythonApplication {
pname = "example";
version = "1";
src = ./.;
buildInputs = [
pyenv

inherit (pkgs.lib) composeManyExtensions;
inherit (pkgs.lib.fileset) toSource unions;
inherit (pyproject.inputs) pyproject-nix uv2nix;

pname = "example";

src = toSource {
root = ./.;
fileset = unions [
./main.py
./pyproject.toml
./uv.lock
];
};

workspace = uv2nix.lib.workspace.loadWorkspace {
workspaceRoot = "${src}";
};

overlay = workspace.mkPyprojectOverlay {
sourcePreference = "wheel";
};

pythonSet = (pkgs.callPackage pyproject-nix.build.packages {
python = pkgs.python312;
}).overrideScope (composeManyExtensions [
pyproject.overlays.default
overlay
]);

venv = pythonSet.mkVirtualEnv pname workspace.deps.default;
in
{
packages.default = pythonSet.${pname};

devShells.default = pkgs.mkShell {
inputsFrom = [ packages.default ];
packages = with pkgs; with python.pkgs; [
black
ipython
python-lsp-server
];
packages = with pkgs; [ venv uv ];
};
});
}
6 changes: 6 additions & 0 deletions templates/python/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from python!")


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions templates/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "example"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
7 changes: 7 additions & 0 deletions templates/python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46ba48d

Please sign in to comment.