diff --git a/flake.nix b/flake.nix index b787d708..10a327f7 100644 --- a/flake.nix +++ b/flake.nix @@ -240,6 +240,9 @@ ]; }; }; + templates = { + uv.description = "Python template flake that uses uv"; + }; outputs-builder = channels: { # Define default packages to use everywhere diff --git a/templates/uv/.envrc b/templates/uv/.envrc new file mode 100644 index 00000000..2f3e46ad --- /dev/null +++ b/templates/uv/.envrc @@ -0,0 +1,17 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi + +# uncomment all commented lines once uv venv has been set up + +# if test -n "$FISH_VERSION"; then +# source ./.venv/bin/activate.fish +# elif test -n "$BASH_VERSION"; then +# source ./.venv/bin/activate +# elif test -n "$NU_VERSION"; then +# source ./.venv/bin/activate.nu +# fi + +# export UV_PYTHON=${PWD}/.venv/bin/python3 + +use flake diff --git a/templates/uv/README.md b/templates/uv/README.md new file mode 100644 index 00000000..a9a2abf0 --- /dev/null +++ b/templates/uv/README.md @@ -0,0 +1 @@ +# dish's `uv` project template diff --git a/templates/uv/flake.nix b/templates/uv/flake.nix new file mode 100644 index 00000000..5c5eeb7d --- /dev/null +++ b/templates/uv/flake.nix @@ -0,0 +1,59 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + pre-commit-hooks.url = "github:cachix/git-hooks.nix"; + pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = + { + self, + nixpkgs, + pre-commit-hooks, + ... + }: + let + eachSystem = nixpkgs.lib.genAttrs [ "x86_64-linux" ]; + in + { + devShells = eachSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + buildInputs = + with pkgs; + [ + python3 + just + nixfmt-rfc-style + ruff + uv + ] + ++ self.checks.${system}.pre-commit-check.enabledPackages; + }; + } + ); + checks = eachSystem (system: { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + check-added-large-files.enable = true; + check-executables-have-shebangs.enable = true; + check-shebang-scripts-are-executable.enable = true; + check-symlinks.enable = true; + end-of-file-fixer.enable = true; + nixfmt-rfc-style.enable = true; + pyright.enable = true; + ruff-format.enable = true; + ruff.enable = true; + # Uncomment for django projects + # ruff-format.excludes = [ "^.*migrations/" ]; + # pyright.excludes = [ "^.*migrations/" ]; + }; + }; + }); + }; +} diff --git a/templates/uv/pyproject.toml b/templates/uv/pyproject.toml new file mode 100644 index 00000000..eaa32d71 --- /dev/null +++ b/templates/uv/pyproject.toml @@ -0,0 +1,86 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "uv-template" +version = "0.1.0" +description = "project description" +readme = "README.md" +requires-python = ">=3.12" +authors = [{ name = "Pyrox/dish", email = "pyrox@pyrox.dev" }] +maintainers = [{ name = "Pyrox/dish", email = "pyrox@pyrox.dev" }] +keywords = [] +classifiers = [] +dependencies = [] + +[project.urls] +Homepage = "https://git.pyrox.dev/pyrox/nix" +Documentation = "https://git.pyrox.dev/pyrox/nix" +Repository = "https://git.pyrox.dev/pyrox/nix" +Issues = "https://git.pyrox.dev/pyrox/nix/issues" + +[dependency-groups] +dev = [] + +# Uncomment for django +# [tool.djlint] +# ignore = "H006" +# indent = 2 +# profile = "django" +# use_gitignore = true + +[tool.pyright] +venvPath = "." +venv = ".venv" +# Uncomment for django +# exclude = ["**/migrations/*.py", "manage.py", "scripts/*.py"] + +[tool.ruff] +indent-width = 4 + +[tool.ruff.format] +# Uncomment for django +# exclude = ["**/migrations/*.py", "manage.py", "scripts/*.py"] +line-ending = "lf" +indent-style = "space" + +[tool.ruff.lint] +select = [ + "A", + "ANN", + "ARG", + "COM", + "DTZ", + "ERA", + "E4", + "E7", + "E9", + "F", + "FURB", + "FLY", + "INP", + "LOG", + "PERF", + "PIE", + "PTH", + "Q", + "RET", + "RUF", + "S", + "SIM", + "T20", + "TCH", + "TID", + "UP", +] +ignore = ["ANN003", "COM812"] + +[tool.setuptools] +packages = [""] + +[tool.uv] +compile-bytecode = true +package = false + +[tool.uv.sources]