Skip to content

Commit 16ec914

Browse files
authored
Merge pull request #598 from totoroot/uv-hooks
feat: add uv hooks
2 parents fae816c + b8c7eb0 commit 16ec914

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ use nix
370370
- [ruff-format](https://github.com/charliermarsh/ruff)
371371
- [single-quoted-strings](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/string_fixer.py)
372372
- [sort-requirements-txt](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/requirements_txt_fixer.py)
373+
- [uv](https://github.com/astral-sh/uv)
373374

374375
### Rust
375376

modules/hooks.nix

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,37 @@ in
19111911
};
19121912
};
19131913
};
1914+
uv-export = mkOption {
1915+
description = "uv export hook";
1916+
type = types.submodule {
1917+
imports = [ hookModule ];
1918+
options.settings = {
1919+
format =
1920+
mkOption {
1921+
type = types.enum [ "requirements.txt" "pylock.toml" ];
1922+
description = "Output format of the project's lockfile.";
1923+
# Most useful for compliance with PEP 751
1924+
default = "pylock.toml";
1925+
example = "requirements.txt";
1926+
};
1927+
locked =
1928+
mkOption {
1929+
type = types.bool;
1930+
description = ''
1931+
Assert that the `uv.lock` will remain unchanged.
1932+
Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.
1933+
'';
1934+
default = true;
1935+
};
1936+
flags =
1937+
mkOption {
1938+
type = types.str;
1939+
description = "Flags passed to `uv export`";
1940+
default = "";
1941+
};
1942+
};
1943+
};
1944+
};
19141945
vale = mkOption {
19151946
description = "vale hook";
19161947
type = types.submodule {
@@ -4032,6 +4063,39 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
40324063
"${hooks.typstyle.package}/bin/typstyle -i";
40334064
files = "\\.typ$";
40344065
};
4066+
uv-check = {
4067+
name = "uv check";
4068+
description = "Check if uv's lockfile is up-to-date.";
4069+
package = tools.uv;
4070+
entry = "${hooks.uv-check.package}/bin/uv lock --check";
4071+
files = "^(uv\\.lock$|pyproject\\.toml)$";
4072+
pass_filenames = false;
4073+
};
4074+
uv-lock = {
4075+
name = "uv lock";
4076+
description = "Update uv's lockfile.";
4077+
package = tools.uv;
4078+
entry = "${hooks.uv-lock.package}/bin/uv lock";
4079+
files = "^(uv\\.lock$|pyproject\\.toml)$";
4080+
pass_filenames = false;
4081+
};
4082+
uv-export = {
4083+
name = "uv export";
4084+
description = "Export uv's lockfile.";
4085+
package = tools.uv;
4086+
files = "^(uv\\.lock$|pyproject\\.toml)$";
4087+
pass_filenames = false;
4088+
entry =
4089+
let
4090+
cmdArgs =
4091+
mkCmdArgs
4092+
(with hooks.uv-export.settings; [
4093+
[ (format != "requirements") " --format ${format} --output-file ${format}" ]
4094+
[ locked " --locked" ]
4095+
]);
4096+
in
4097+
"${hooks.uv-export.package}/bin/uv export${cmdArgs} ${hooks.uv-export.settings.flags}";
4098+
};
40354099
vale = {
40364100
name = "vale";
40374101
description = "A markup-aware linter for prose built with speed and extensibility in mind.";

nix/tools.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
, golangci-lint
9494
, golines
9595
, revive ? null
96+
, uv
9697
, vale
9798
}:
9899

@@ -172,6 +173,7 @@ in
172173
typos
173174
typstfmt
174175
typstyle
176+
uv
175177
vale
176178
yamlfmt
177179
yamllint

0 commit comments

Comments
 (0)