templates/python-uv: init

This commit is contained in:
Lu Wang 2024-11-19 01:28:58 +08:00
parent 7e5f71e494
commit 461e999a08
Signed by: rebmit
SSH key fingerprint: SHA256:3px8QV1zEerIrEWHaqtH5rR9kjetyRST5EipOPrd+bU
8 changed files with 152 additions and 0 deletions

View file

@ -0,0 +1,4 @@
{ ... }:
{
flake.templates = import ../../templates;
}

6
templates/default.nix Normal file
View file

@ -0,0 +1,6 @@
{
"python-uv" = {
path = ./python-uv;
description = "a python project using uv";
};
}

View file

@ -0,0 +1,6 @@
files=(
"uv.lock"
"pyproject.toml"
)
watch_file "${files[@]}"
use flake

14
templates/python-uv/.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
result*
.direnv
.pre-commit-config.yaml
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv

View file

View file

@ -0,0 +1,108 @@
{
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];
imports = [
inputs.devshell.flakeModule
inputs.git-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
perSystem =
{
config,
pkgs,
lib,
...
}:
let
workspace = inputs.uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; };
pyprojectOverrides = _final: _prev: { };
pythonSet =
(pkgs.callPackage inputs.pyproject-nix.build.packages {
python = pkgs.python311;
}).overrideScope
(lib.composeExtensions overlay pyprojectOverrides);
in
{
devshells.default = {
packages = [
(pythonSet.mkVirtualEnv "python-uv-env" workspace.deps.all)
pkgs.python311Packages.uv
config.treefmt.build.wrapper
];
env = [
(lib.nameValuePair "UV_PYTHON" "${lib.getExe pkgs.python311}")
(lib.nameValuePair "DEVSHELL_NO_MOTD" 1)
{
name = "PYTHONPATH";
unset = true;
}
];
devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript;
};
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
ruff-check.enable = true;
ruff-format.enable = true;
};
};
pre-commit.settings.hooks.treefmt = {
enable = true;
name = "treefmt";
entry = lib.getExe config.treefmt.build.wrapper;
pass_filenames = false;
};
};
};
inputs = {
# flake-parts
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
# nixpkgs
nixpkgs.follows = "nixpkgs-unstable";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
# flake modules
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
git-hooks-nix = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# libraries
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:adisbladis/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
}

View file

@ -0,0 +1,7 @@
[project]
name = "python-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = []

View file

@ -0,0 +1,7 @@
version = 1
requires-python = ">=3.11"
[[package]]
name = "python-uv"
version = "0.1.0"
source = { editable = "." }