2023-07-03 22:34:46 +03:30
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
config,
|
|
|
|
pkgs,
|
2023-07-03 22:34:46 +03:30
|
|
|
...
|
|
|
|
}:
|
2024-05-05 19:39:35 +02:00
|
|
|
let
|
2025-01-23 20:11:11 -06:00
|
|
|
inherit (lib)
|
|
|
|
optionalString
|
|
|
|
types
|
|
|
|
;
|
|
|
|
inherit (lib.nixvim)
|
|
|
|
defaultNullOpts
|
|
|
|
mkNullOrOption
|
|
|
|
toLuaObject
|
|
|
|
;
|
2025-01-23 20:02:06 -06:00
|
|
|
|
2023-07-03 22:34:46 +03:30
|
|
|
cfg = config.plugins.dap.extensions.dap-python;
|
2025-01-23 20:11:11 -06:00
|
|
|
dapHelpers = import ./dapHelpers.nix { inherit lib; };
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
|
|
|
{
|
2023-07-03 22:34:46 +03:30
|
|
|
options.plugins.dap.extensions.dap-python = {
|
2025-01-23 20:02:06 -06:00
|
|
|
enable = lib.mkEnableOption "dap-python";
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2024-09-04 21:55:25 +01:00
|
|
|
package = lib.mkPackageOption pkgs "dap-python" {
|
|
|
|
default = [
|
|
|
|
"vimPlugins"
|
|
|
|
"nvim-dap-python"
|
|
|
|
];
|
|
|
|
};
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2025-01-23 20:02:06 -06:00
|
|
|
adapterPythonPath = lib.mkOption {
|
2025-01-24 23:18:47 +00:00
|
|
|
default = lib.getExe (pkgs.python3.withPackages (ps: with ps; [ debugpy ]));
|
|
|
|
defaultText = lib.literalExpression ''
|
|
|
|
lib.getExe (pkgs.python3.withPackages (ps: with ps; [ debugpy ]))
|
|
|
|
'';
|
2023-07-03 22:34:46 +03:30
|
|
|
description = "Path to the python interpreter. Path must be absolute or in $PATH and needs to have the debugpy package installed.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
console = defaultNullOpts.mkEnumFirstDefault [
|
2024-05-05 19:39:35 +02:00
|
|
|
"integratedTerminal"
|
|
|
|
"internalConsole"
|
|
|
|
"externalTerminal"
|
|
|
|
] "Debugpy console.";
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
includeConfigs = defaultNullOpts.mkBool true "Add default configurations.";
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
resolvePython = defaultNullOpts.mkLuaFn null ''
|
2023-07-03 22:34:46 +03:30
|
|
|
Function to resolve path to python to use for program or test execution.
|
|
|
|
By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present.
|
|
|
|
'';
|
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
testRunner = mkNullOrOption (types.either types.str types.rawLua) ''
|
2023-07-03 22:34:46 +03:30
|
|
|
The name of test runner to use by default.
|
|
|
|
The default value is dynamic and depends on `pytest.ini` or `manage.py` markers.
|
|
|
|
If neither is found "unittest" is used.
|
|
|
|
'';
|
|
|
|
|
2025-01-23 20:11:11 -06:00
|
|
|
testRunners = mkNullOrOption (with lib.types; attrsOf strLuaFn) ''
|
2023-07-03 22:34:46 +03:30
|
|
|
Set to register test runners.
|
|
|
|
Built-in are test runners for unittest, pytest and django.
|
|
|
|
The key is the test runner name, the value a function to generate the
|
|
|
|
module name to run and its arguments.
|
|
|
|
See |dap-python.TestRunner|.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
options = with cfg; {
|
|
|
|
inherit console;
|
|
|
|
include_configs = includeConfigs;
|
|
|
|
};
|
|
|
|
in
|
2025-01-23 20:02:06 -06:00
|
|
|
lib.mkIf cfg.enable {
|
2024-05-05 19:39:35 +02:00
|
|
|
extraPlugins = [ cfg.package ];
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2023-08-17 19:03:21 +03:30
|
|
|
plugins.dap = {
|
|
|
|
enable = true;
|
2023-07-03 22:34:46 +03:30
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
extensionConfigLua =
|
2023-08-17 19:03:21 +03:30
|
|
|
''
|
|
|
|
require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject options})
|
|
|
|
''
|
|
|
|
+ (optionalString (cfg.testRunners != null) ''
|
|
|
|
table.insert(require("dap-python").test_runners,
|
2025-01-23 20:11:11 -06:00
|
|
|
${toLuaObject (builtins.mapAttrs (_: lib.nixvim.mkRaw) cfg.testRunners)})
|
2023-08-17 19:03:21 +03:30
|
|
|
'')
|
|
|
|
+ (optionalString (cfg.customConfigurations != null) ''
|
|
|
|
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
|
|
|
|
'')
|
|
|
|
+ (optionalString (cfg.resolvePython != null) ''
|
2023-12-29 15:24:42 +01:00
|
|
|
require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
|
2023-08-17 19:03:21 +03:30
|
|
|
'')
|
|
|
|
+ (optionalString (cfg.testRunner != null) ''
|
|
|
|
require("dap-python").test_runner = ${toLuaObject cfg.testRunner};
|
|
|
|
'');
|
|
|
|
};
|
2023-07-03 22:34:46 +03:30
|
|
|
};
|
|
|
|
}
|