diff --git a/.editorconfig b/.editorconfig index 086ea5c..32d69d6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: CC-BY-SA-4.0 + root = true [*] @@ -6,19 +8,6 @@ insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 -[{Makefile,*.mk}] -indent_style = tab -indent_size = 4 - -[*.md] -indent_style = space -indent_size = 2 - -[*.{yml,yaml}] -indent_style = space -indent_size = 2 - [*.nix] indent_style = tab indent_size = 2 - diff --git a/.envrc b/.envrc index 67024ff..8c19926 100644 --- a/.envrc +++ b/.envrc @@ -1,5 +1,11 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +# https://github.com/direnv/direnv/wiki + use flake +layout python3 + watch_file ./nix/shell.nix eval "$shellHook" diff --git a/.gitignore b/.gitignore index c97f873..fef328b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,32 @@ -.vscode -flow_backup.json -flows/.main.json.backup +# SPDX-License-Identifier: CC-BY-SA-4.0 + +# General +.reuse +*.dll *.log +*.so +*.swp export -tmp img -docs/_* -*.jpg -*.png -*.pyc -*__pycache__* +tmp + +# Nix .direnv -.reuse \ No newline at end of file +.pre-commit-config.yaml +result + +# Python +/*.py[cod] +/__pycache__ +/.benchmark +/.coverage* +/.pytest_cache + +# Node-Red +/.main.json.backup +/flow_backup.json + +# Mkdocs +dist +docs/_* +site diff --git a/.mdlrc b/.mdlrc deleted file mode 100644 index 18359c8..0000000 --- a/.mdlrc +++ /dev/null @@ -1 +0,0 @@ -rules "MD001","MD002","MD003","MD004","MD005","MD006","MD007","MD010","MD011","MD012","MD014","MD018","MD019","MD020","MD021","MD022","MD023","MD024","MD025","MD027","MD028","MD029","MD030","MD031","MD032","MD033","MD034","MD035","MD036","MD037","MD038","MD039","MD040","MD041","MD047" diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ee54629 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,20 @@ +{ + "recommendations": [ + "bungcip.better-toml", + "cab404.vscode-direnv", + "davidanson.vscode-markdownlint", + "editorconfig.editorconfig", + "esbenp.prettier-vscode", + "exiasr.hadolint", + "kamadorueda.alejandra", + "kamikillerto.vscode-colorize", + "mechatroner.rainbow-csv", + "ms-python.black-formatter", + "ms-python.python", + "oderwat.indent-rainbow", + "pinage404.nix-extension-pack", + "redhat.vscode-yaml", + "yatki.vscode-surround", + "yzhang.markdown-all-in-one", + ], +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0e390e9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "[nix]": { + "editor.defaultFormatter": "kamadorueda.alejandra", + "editor.formatOnSave": true, + }, + "[toml]": { + "editor.formatOnSave": true, + "editor.insertSpaces": true, + "editor.codeLens": true + }, + "python.formatting.provider": "black", + "python.globalModuleInstallation": false, + "python.languageServer": "Pylance", + "python.linting.enabled": true, + "python.linting.lintOnSave": true, + "python.linting.pycodestyleEnabled": true, + "python.linting.pydocstyleEnabled": true, + "python.linting.pylintEnabled": true, + "python.testing.autoTestDiscoverOnSaveEnabled": true, + "python.testing.pytestEnabled": true, + "python.defaultInterpreterPath": "${workspaceFolder}/.direnv/dev/bin/python3", +} diff --git a/Makefile b/Makefile deleted file mode 100644 index 6022519..0000000 --- a/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -##@ General - -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - -##@ Documentation - -docs-build: ## Build the MkDocs documentation - @mkdocs build - -docs-serve: ## Run mkdocs builtin development server - @mkdocs serve - -##@ Lint - -lint-markdown: ## Run markdown linter on all files - @mdl . - -lint-reuse: ## Run reuse linter on all files - @reuse lint - -%: - @true diff --git a/flake.lock b/flake.lock index 73ccfe6..080bfe3 100644 --- a/flake.lock +++ b/flake.lock @@ -31,57 +31,7 @@ "type": "github" } }, - "flake-utils_2": { - "locked": { - "lastModified": 1642700792, - "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "mach-nix": { - "inputs": { - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs", - "pypi-deps-db": "pypi-deps-db" - }, - "locked": { - "lastModified": 1654084003, - "narHash": "sha256-j/XrVVistvM+Ua+0tNFvO5z83isL+LBgmBi9XppxuKA=", - "owner": "DavHau", - "repo": "mach-nix", - "rev": "7e14360bde07dcae32e5e24f366c83272f52923f", - "type": "github" - }, - "original": { - "id": "mach-nix", - "ref": "3.5.0", - "type": "indirect" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1643805626, - "narHash": "sha256-AXLDVMG+UaAGsGSpOtQHPIKB+IZ0KSd9WS77aanGzgc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "554d2d8aa25b6e583575459c297ec23750adb6cb", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 1664281702, "narHash": "sha256-haixZ4TJLu1Dciow54wrHrHvlGDVr5sW6MTeAV/ZLuI=", @@ -120,28 +70,11 @@ "type": "github" } }, - "pypi-deps-db": { - "flake": false, - "locked": { - "lastModified": 1643877077, - "narHash": "sha256-jv8pIvRFTP919GybOxXE5TfOkrjTbdo9QiCO1TD3ZaY=", - "owner": "DavHau", - "repo": "pypi-deps-db", - "rev": "da53397f0b782b0b18deb72ef8e0fb5aa7c98aa3", - "type": "github" - }, - "original": { - "owner": "DavHau", - "repo": "pypi-deps-db", - "type": "github" - } - }, "root": { "inputs": { "flake-compat": "flake-compat", "flake-utils": "flake-utils", - "mach-nix": "mach-nix", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks" } } diff --git a/flake.nix b/flake.nix index ce4c8be..b30d2dc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: GPL-3.0-or-later { description = "Nix PlanktoScope"; inputs = { @@ -15,33 +16,20 @@ inputs.nixpkgs.follows = "nixpkgs"; inputs.flake-utils.follows = "flake-utils"; }; - - mach-nix.url = "mach-nix/3.5.0"; }; outputs = { - self, nixpkgs, flake-utils, - mach-nix, ... } @ inputs: - flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let + flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: { + devShells.default = import ./nix/shell.nix inputs system; + checks = import ./nix/checks.nix inputs system; pkgs = import nixpkgs { inherit system; + config.allowUnfree = true; + config.allowAliases = true; }; - machNix = mach-nix.lib."${system}"; - in rec { - packages = { - planktoscope = machNix.buildPythonPackage { - src = builtins.fetchGit { - url = "https://github.com/PlanktoScope/PlanktoScope"; - ref = "master"; - rev = "d52e194de0604e6fdd41ba2e13de9ab91e7789da"; - }; - extras = []; - }; - }; - devShell = import ./nix/shell.nix {inherit pkgs;}; }); } diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 0000000..4f3f084 --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,43 @@ +{ + self, + pre-commit-hooks, + ... +}: system: +with self.pkgs.${system}; { + pre-commit-check = + pre-commit-hooks.lib.${system}.run + { + src = lib.cleanSource ../.; + hooks = { + alejandra.enable = true; + nix-linter.enable = true; + yamllint.enable = true; + # isort.enable = true; + # black.enable = true; + # shellcheck.enable = true; + # markdownlint.enable = true; + }; + settings.nix-linter.checks = [ + "DIYInherit" + "EmptyInherit" + "EmptyLet" + "EtaReduce" + "LetInInheritRecset" + "ListLiteralConcat" + "NegateAtom" + "SequentialLet" + "SetLiteralUpdate" + "UnfortunateArgName" + "UnneededRec" + "UnusedArg" + "UnusedLetBind" + "UpdateEmptySet" + "BetaReduction" + "EmptyVariadicParamSet" + "UnneededAntiquote" + "no-FreeLetInFunc" + "no-AlphabeticalArgs" + "no-AlphabeticalBindings" + ]; + }; +} diff --git a/nix/shell.nix b/nix/shell.nix index 181e5a9..0b5e72d 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,22 +1,43 @@ -{pkgs ? import {}}: -with pkgs; +{self, ...}: system: +with self.pkgs.${system}; mkShell { - name = "planctoscope"; - nativeBuildInputs = with pkgs; [ - alejandra - docker - editorconfig-checker - git - gnumake - hadolint - mdl - nixpkgs-fmt - pre-commit - python310Packages.mkdocs - reuse - rnix-lsp - vscodium-fhs - yaml-language-server - yamllint - ]; + name = "planktoscope"; + nativeBuildInputs = + [ + # Development + editorconfig-checker + pre-commit + python-language-server + python37 + python38 + python39 + python310Full + python311 + yaml-language-server + ] + ++ lib.optionals (pkgs.hostPlatform.system == "x86_64-linux") [ + vscodium-fhs + ] + ++ [ + # Linter + git + yamllint + + # Nix + alejandra + nix + nix-linter + rnix-lsp + + # Service + mosquitto + + # Misc + reuse + ]; + shellHook = '' + ${self.checks.${system}.pre-commit-check.shellHook} + pip install --upgrade pip hatch + hatch env create dev + ''; }