diff --git a/.gitignore b/.gitignore index c8fbde8..ceb8217 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ __pycache__/ artifacts/ benchmark/ +.pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 0000000..e6c5315 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/9fa9jgr29n0zfbap74ac8hkcil8fgw8z-pre-commit-config.json \ No newline at end of file diff --git a/flake.lock b/flake.lock index c921bbb..3c313e3 100644 --- a/flake.lock +++ b/flake.lock @@ -51,6 +51,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -84,6 +100,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nix-appimage": { "inputs": { "appimage-runtime": "appimage-runtime", @@ -137,6 +174,22 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1659526864, @@ -168,12 +221,50 @@ "type": "github" } }, + "nixpkgs_4": { + "locked": { + "lastModified": 1710765496, + "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_4", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1717664902, + "narHash": "sha256-7XfBuLULizXjXfBYy/VV+SpYMHreNRHk9nKMsm1bgb4=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "cc4d466cb1254af050ff7bdf47f6d404a7c646d1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "devshell": "devshell", "nix-appimage": "nix-appimage", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs_3", + "pre-commit-hooks": "pre-commit-hooks", "systems": "systems_2" } }, diff --git a/flake.nix b/flake.nix index 8e24355..72fd413 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,7 @@ systems.url = "github:nix-systems/x86_64-linux"; nix-filter.url = "github:numtide/nix-filter"; devshell.url = "github:numtide/devshell"; + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; nix-appimage = { url = "github:ralismark/nix-appimage"; }; @@ -12,9 +13,8 @@ self, nixpkgs, systems, - nix-filter, - nix-appimage, devshell, + ... } @ inputs: let eachSystem = nixpkgs.lib.genAttrs (import systems); pkgsFor = eachSystem (system: ((nixpkgs.legacyPackages.${system}.extend devshell.overlays.default).extend self.overlays.default)); @@ -31,6 +31,12 @@ lib = pkgs.lib; in { + pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + alejandra.enable = true; + }; + }; rs-tensor-encoder-test-runner-check = pkgs.runCommandNoCC "rs-encoder-test-runner-check" { nativeBuildInputs = [self.packages.${system}.rs-tensor-encoder-test-runner]; @@ -99,9 +105,11 @@ buildPackage = inputs.self.packages.${system}.default; in { default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; nativeBuildInputs = buildPackage.nativeBuildInputs; buildInputs = buildPackage.buildInputs + ++ self.checks.${system}.pre-commit-check.enabledPackages ++ (with pkgs; [ # glibc rustc diff --git a/integration_tests/test_python_integration.py b/integration_tests/test_python_integration.py index ec53802..7fe1b4d 100644 --- a/integration_tests/test_python_integration.py +++ b/integration_tests/test_python_integration.py @@ -79,7 +79,7 @@ def read_all_raster_bands(path): as a string and the value the array data """ with rasterio.open(path) as r: - return {str(i): r.read(i) for i in range(1, r.count + 1)} + return {f"B{i}": r.read(i) for i in range(1, r.count + 1)} def test_python_hyspecnet_integration(hyspecnet_root, encoded_hyspecnet_path): source_file_data = {file: read_all_raster_bands(file) for file in hyspecnet_root.glob("**/*SPECTRAL_IMAGE.TIF")}