Switch to uv from poetry
This commit is contained in:
212
flake.nix
212
flake.nix
@@ -1,11 +1,24 @@
|
||||
{
|
||||
description = "Nix PR status checker";
|
||||
description = "Nixpkgs PR request status checker";
|
||||
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
poetry2nix = {
|
||||
url = "github:nix-community/poetry2nix";
|
||||
|
||||
pyproject-nix = {
|
||||
url = "github:pyproject-nix/pyproject.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
uv2nix = {
|
||||
url = "github:pyproject-nix/uv2nix";
|
||||
inputs.pyproject-nix.follows = "pyproject-nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
pyproject-build-systems = {
|
||||
url = "github:pyproject-nix/build-system-pkgs";
|
||||
inputs.pyproject-nix.follows = "pyproject-nix";
|
||||
inputs.uv2nix.follows = "uv2nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
@@ -14,49 +27,168 @@
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
poetry2nix,
|
||||
uv2nix,
|
||||
pyproject-nix,
|
||||
pyproject-build-systems,
|
||||
...
|
||||
}:
|
||||
{
|
||||
overlays.default = final: prev: {
|
||||
nixprstatus = self.packages.${prev.system}.default;
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
|
||||
|
||||
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
|
||||
|
||||
overlay = workspace.mkPyprojectOverlay {
|
||||
sourcePreference = "wheel";
|
||||
};
|
||||
}
|
||||
// flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication defaultPoetryOverrides;
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
nixprstatus = mkPoetryApplication {
|
||||
projectDir = pkgs.lib.sourceFilesBySuffices ./. [
|
||||
"pyproject.toml"
|
||||
"poetry.lock"
|
||||
"README.md"
|
||||
".py"
|
||||
];
|
||||
|
||||
editableOverlay = workspace.mkEditablePyprojectOverlay {
|
||||
root = "$REPO_ROOT";
|
||||
};
|
||||
|
||||
# Python sets grouped per system
|
||||
pythonSets = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (pkgs) stdenv;
|
||||
|
||||
# Base Python package set from pyproject.nix
|
||||
baseSet = pkgs.callPackage pyproject-nix.build.packages {
|
||||
python = pkgs.python312;
|
||||
};
|
||||
|
||||
# An overlay of build fixups & test additions
|
||||
pyprojectOverrides = final: prev: {
|
||||
nixprstatus = prev.nixprstatus.overrideAttrs (old: {
|
||||
# Add tests to passthru.tests
|
||||
#
|
||||
# These attribute are used in Flake checks.
|
||||
passthru = old.passthru // {
|
||||
tests = (old.tests or { }) // {
|
||||
# Run mypy checks
|
||||
mypy =
|
||||
let
|
||||
venv = final.mkVirtualEnv "nixprstatus-typing-env" {
|
||||
nixprstatus = [ "typing" ];
|
||||
};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "${final.nixprstatus.name}-mypy";
|
||||
inherit (final.nixprstatus) src;
|
||||
nativeBuildInputs = [
|
||||
venv
|
||||
];
|
||||
dontConfigure = true;
|
||||
dontInstall = true;
|
||||
buildPhase = ''
|
||||
mkdir $out
|
||||
mypy --strict nixprstatus --junit-xml $out/junit.xml
|
||||
'';
|
||||
};
|
||||
|
||||
# Run unittest with coverage reports installed into build output
|
||||
unittest =
|
||||
let
|
||||
venv = final.mkVirtualEnv "nixprstatus-test-env" {
|
||||
nixprstatus = [ ];
|
||||
};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "${final.nixprstatus.name}-test";
|
||||
inherit (final.nixprstatus) src;
|
||||
nativeBuildInputs = [
|
||||
venv
|
||||
];
|
||||
|
||||
dontConfigure = true;
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
mkdir -p $out
|
||||
python -m unittest discover tests -v > $out/unittest.txt
|
||||
runHook postBuild
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
in
|
||||
baseSet.overrideScope (
|
||||
lib.composeManyExtensions [
|
||||
pyproject-build-systems.overlays.default
|
||||
overlay
|
||||
pyprojectOverrides
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
in
|
||||
# Django static roots grouped per system
|
||||
{
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pythonSet = pythonSets.${system};
|
||||
in
|
||||
# Inherit tests from passthru.tests into flake checks
|
||||
pythonSet.nixprstatus.passthru.tests
|
||||
);
|
||||
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
pythonSet = pythonSets.${system};
|
||||
venv = pythonSet.mkVirtualEnv "nixprstatus-env" workspace.deps.default;
|
||||
in
|
||||
{
|
||||
default = pkgs.stdenv.mkDerivation {
|
||||
pname = "nixprstatus";
|
||||
version = pythonSet.nixprstatus.version;
|
||||
dontConfigure = true;
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
buildInputs = [ venv ];
|
||||
nativeBuildInputs = [ pkgs.installShellFiles ];
|
||||
postInstall = ''
|
||||
mkdir -p $out/bin
|
||||
ln -s ${venv}/bin/nixprstatus $out/bin/nixprstatus
|
||||
installShellCompletion --cmd nixprstatus \
|
||||
--bash <($out/bin/nixprstatus --show-completion bash) \
|
||||
--zsh <($out/bin/nixprstatus --show-completion zsh) \
|
||||
--fish <($out/bin/nixprstatus --show-completion fish)
|
||||
--bash <($out/bin/nixprstatus --show-completion bash) \
|
||||
--zsh <($out/bin/nixprstatus --show-completion zsh) \
|
||||
--fish <($out/bin/nixprstatus --show-completion fish)
|
||||
'';
|
||||
};
|
||||
default = self.packages.${system}.nixprstatus;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = [ self.packages.${system}.nixprstatus ];
|
||||
packages = [
|
||||
pkgs.poetry
|
||||
pkgs.ruff
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
# Use an editable Python set for development.
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
editablePythonSet = pythonSets.${system}.overrideScope editableOverlay;
|
||||
venv = editablePythonSet.mkVirtualEnv "nixprstatus-dev-env" {
|
||||
nixprstatus = [ "dev" ];
|
||||
};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
packages = [
|
||||
venv
|
||||
pkgs.uv
|
||||
];
|
||||
shellHook = ''
|
||||
unset PYTHONPATH
|
||||
export REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||
export UV_NO_SYNC=1
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user