From 6c1c615c60d18b18ebad655a25d6b8b14d89096a Mon Sep 17 00:00:00 2001 From: DavHau Date: Sat, 3 Aug 2024 22:10:11 +0700 Subject: [PATCH] devshell: remove dependency on clan-cli This stops the devshell from being re-built constantly, when the source code changes. Based on a new feature in treefmt-nix: https://github.com/numtide/treefmt-nix/pull/208 --- checks/devshell/flake-module.nix | 22 ++++++++++++++++++++++ checks/flake-module.nix | 5 +++-- devShell.nix | 1 + flake.lock | 6 +++--- formatter.nix | 7 +++---- pkgs/clan-app/clan_app/api/file.py | 12 ++++++++---- pkgs/clan-app/shell.nix | 1 - 7 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 checks/devshell/flake-module.nix diff --git a/checks/devshell/flake-module.nix b/checks/devshell/flake-module.nix new file mode 100644 index 000000000..2e9ea7641 --- /dev/null +++ b/checks/devshell/flake-module.nix @@ -0,0 +1,22 @@ +{ ... }: +{ + perSystem = + { self', pkgs, ... }: + { + checks.devshell = + pkgs.runCommand "check-devshell-not-depends-on-clan-cli" + { + exportReferencesGraph = [ + "graph" + self'.devShells.default + ]; + } + '' + if grep -q "${self'.packages.clan-cli}" ./graph; then + echo "devshell depends on clan-cli, which is not allowed"; + exit 1; + fi + mkdir $out + ''; + }; +} diff --git a/checks/flake-module.nix b/checks/flake-module.nix index 652b96423..a6de83757 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -1,10 +1,11 @@ { self, ... }: { imports = [ - ./impure/flake-module.nix ./backups/flake-module.nix - ./installation/flake-module.nix + ./devshell/flake-module.nix ./flash/flake-module.nix + ./impure/flake-module.nix + ./installation/flake-module.nix ]; perSystem = { diff --git a/devShell.nix b/devShell.nix index 206b29cff..d615ff71c 100644 --- a/devShell.nix +++ b/devShell.nix @@ -38,6 +38,7 @@ ]; shellHook = '' echo -e "${ansiEscapes.green}switch to another dev-shell using: select-shell${ansiEscapes.reset}" + export PROJECT_ROOT=$(git rev-parse --show-toplevel) ''; }; }; diff --git a/flake.lock b/flake.lock index e72901e57..104df3d1f 100644 --- a/flake.lock +++ b/flake.lock @@ -115,11 +115,11 @@ ] }, "locked": { - "lastModified": 1721458737, - "narHash": "sha256-wNXLQ/ATs1S4Opg1PmuNoJ+Wamqj93rgZYV3Di7kxkg=", + "lastModified": 1722699361, + "narHash": "sha256-3GDJCoNj7PEwQaOqmNgcwoHM+Xy/fkgqeXC1y7UzV2U=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "888bfb10a9b091d9ed2f5f8064de8d488f7b7c97", + "rev": "07741a9babd0754bf73fb47a6340d6289eabd1d6", "type": "github" }, "original": { diff --git a/formatter.nix b/formatter.nix index ed8acb71a..c594cc73b 100644 --- a/formatter.nix +++ b/formatter.nix @@ -44,7 +44,6 @@ "*.yml" ]; }; - treefmt.programs.mypy.directories = { "pkgs/clan-cli" = { @@ -53,8 +52,8 @@ }; "pkgs/clan-app" = { extraPythonPackages = - # clan-app currently only exists on linux (self'.packages.clan-app.externalTestDeps or [ ]) ++ self'.packages.clan-cli.testDependencies; + extraPythonPaths = [ "$PROJECT_ROOT/pkgs/clan-cli" ]; modules = [ "clan_app" ]; }; } @@ -63,8 +62,8 @@ { "pkgs/clan-vm-manager" = { extraPythonPackages = - # # clan-app currently only exists on linux - self'.packages.clan-vm-manager.testDependencies; + self'.packages.clan-vm-manager.externalTestDeps ++ self'.packages.clan-cli.testDependencies; + extraPythonPaths = [ "$PROJECT_ROOT/pkgs/clan-cli" ]; modules = [ "clan_vm_manager" ]; }; } diff --git a/pkgs/clan-app/clan_app/api/file.py b/pkgs/clan-app/clan_app/api/file.py index b6e2b22d8..785e52eaa 100644 --- a/pkgs/clan-app/clan_app/api/file.py +++ b/pkgs/clan-app/clan_app/api/file.py @@ -16,6 +16,10 @@ from clan_app.api import ImplFunc log = logging.getLogger(__name__) +def remove_none(_list: list) -> list: + return [i for i in _list if i is not None] + + # This implements the abstract function open_file with one argument, file_request, # which is a FileRequest object and returns a string or None. class open_file( @@ -29,7 +33,7 @@ class open_file( try: gfile = file_dialog.open_finish(task) if gfile: - selected_path = [gfile.get_path()] + selected_path = remove_none([gfile.get_path()]) self.returns( SuccessDataClass( op_key=op_key, data=selected_path, status="success" @@ -44,7 +48,7 @@ class open_file( try: gfiles: Any = file_dialog.open_multiple_finish(task) if gfiles: - selected_paths = [gfile.get_path() for gfile in gfiles] + selected_paths = remove_none([gfile.get_path() for gfile in gfiles]) self.returns( SuccessDataClass( op_key=op_key, data=selected_paths, status="success" @@ -57,7 +61,7 @@ class open_file( try: gfile = file_dialog.select_folder_finish(task) if gfile: - selected_path = [gfile.get_path()] + selected_path = remove_none([gfile.get_path()]) self.returns( SuccessDataClass( op_key=op_key, data=selected_path, status="success" @@ -70,7 +74,7 @@ class open_file( try: gfile = file_dialog.save_finish(task) if gfile: - selected_path = [gfile.get_path()] + selected_path = remove_none([gfile.get_path()]) self.returns( SuccessDataClass( op_key=op_key, data=selected_path, status="success" diff --git a/pkgs/clan-app/shell.nix b/pkgs/clan-app/shell.nix index 36d0da3bc..74878aac6 100644 --- a/pkgs/clan-app/shell.nix +++ b/pkgs/clan-app/shell.nix @@ -65,6 +65,5 @@ mkShell { export XDG_DATA_DIRS=${gtk4}/share/gsettings-schemas/gtk4-4.14.4:$XDG_DATA_DIRS export XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/gsettings-desktop-schemas-46.0:$XDG_DATA_DIRS - ''; }