Skip to content

Commit a70168e

Browse files
committed
plugins/dap-python: migrate to mkNeovimPlugin
1 parent 6ff7127 commit a70168e

File tree

5 files changed

+151
-109
lines changed

5 files changed

+151
-109
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
lib,
3+
pkgs,
4+
...
5+
}:
6+
let
7+
inherit (lib)
8+
optionalString
9+
types
10+
;
11+
inherit (lib.nixvim)
12+
defaultNullOpts
13+
mkNullOrOption
14+
toLuaObject
15+
;
16+
17+
dapHelpers = import ../dap/dapHelpers.nix { inherit lib; };
18+
in
19+
lib.nixvim.plugins.mkNeovimPlugin {
20+
name = "dap-python";
21+
package = "nvim-dap-python";
22+
23+
maintainers = [ lib.maintainers.khaneliman ];
24+
25+
extraOptions = {
26+
adapterPythonPath = lib.mkOption {
27+
default = lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ]));
28+
defaultText = lib.literalExpression ''
29+
lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ]))
30+
'';
31+
description = ''
32+
Path to the python interpreter.
33+
Path must be absolute or in $PATH and needs to have the `debugpy` package installed.
34+
'';
35+
type = types.str;
36+
};
37+
38+
customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
39+
40+
resolvePython = defaultNullOpts.mkLuaFn null ''
41+
Function to resolve path to python to use for program or test execution.
42+
By default the `VIRTUAL_ENV` and `CONDA_PREFIX` environment variables are used if present.
43+
'';
44+
45+
testRunner = defaultNullOpts.mkLuaFn' {
46+
description = "The name of test runner to use by default.";
47+
pluginDefault = lib.literalMD ''
48+
The default value is dynamic and depends on `pytest.ini` or `manage.py` markers.
49+
If neither are found, `"unittest"` is used.
50+
'';
51+
};
52+
53+
testRunners = mkNullOrOption (with lib.types; attrsOf strLuaFn) ''
54+
Set to register test runners.
55+
56+
Built-in test runners include: `unittest`, `pytest` and `django`.
57+
58+
The key is the test runner name, the value a function to generate the
59+
module name to run and its arguments.
60+
61+
See `|dap-python.TestRunner|`.
62+
'';
63+
};
64+
65+
settingsOptions = {
66+
console = defaultNullOpts.mkEnumFirstDefault [
67+
"integratedTerminal"
68+
"internalConsole"
69+
"externalTerminal"
70+
] "Debugpy console.";
71+
72+
includeConfigs = defaultNullOpts.mkBool true "Add default configurations.";
73+
};
74+
75+
# Manually supplied to nvim-dap config module
76+
callSetup = false;
77+
extraConfig = cfg: {
78+
plugins.dap = {
79+
enable = true;
80+
81+
extensionConfigLua =
82+
''
83+
require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject cfg.settings})
84+
''
85+
+ (optionalString (cfg.testRunners != null) ''
86+
table.insert(require("dap-python").test_runners,
87+
${toLuaObject (builtins.mapAttrs (_: lib.nixvim.mkRaw) cfg.testRunners)})
88+
'')
89+
+ (optionalString (cfg.customConfigurations != null) ''
90+
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
91+
'')
92+
+ (optionalString (cfg.resolvePython != null) ''
93+
require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
94+
'')
95+
+ (optionalString (cfg.testRunner != null) ''
96+
require("dap-python").test_runner = ${toLuaObject cfg.testRunner};
97+
'');
98+
};
99+
};
100+
101+
# NOTE: Renames added in https://github.com/nix-community/nixvim/pull/2897 (2025-01-26)
102+
imports = [ ./deprecations.nix ];
103+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ lib, ... }:
2+
let
3+
oldPluginBasePath = [
4+
"plugins"
5+
"dap"
6+
"extensions"
7+
"dap-python"
8+
];
9+
newPluginBasePath = [
10+
"plugins"
11+
"dap-python"
12+
];
13+
14+
settingsPath = newPluginBasePath ++ [ "settings" ];
15+
16+
renamedOptions = [
17+
[ "enable" ]
18+
[ "adapterPythonPath" ]
19+
[ "customConfigurations" ]
20+
[ "resolvePython" ]
21+
[ "testRunner" ]
22+
[ "testRunners" ]
23+
];
24+
25+
renamedSettingsOptions = [
26+
"console"
27+
"includeConfigs"
28+
];
29+
30+
renameWarnings =
31+
lib.nixvim.mkSettingsRenamedOptionModules oldPluginBasePath settingsPath
32+
renamedSettingsOptions;
33+
in
34+
{
35+
imports =
36+
renameWarnings
37+
++ (map (
38+
optionPath:
39+
lib.mkRenamedOptionModule (oldPluginBasePath ++ optionPath) (newPluginBasePath ++ optionPath)
40+
) renamedOptions);
41+
}

plugins/by-name/dap/dap-python.nix

Lines changed: 0 additions & 103 deletions
This file was deleted.

plugins/by-name/dap/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let
1313
in
1414
lib.nixvim.plugins.mkNeovimPlugin {
1515
imports = [
16-
./dap-python.nix
1716
./dap-ui.nix
1817
./dap-virtual-text.nix
1918
];

tests/test-sources/plugins/by-name/dap/dap-python.nix renamed to tests/test-sources/plugins/by-name/dap-python/default.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
empty = {
3-
plugins.dap.extensions.dap-python.enable = true;
3+
plugins.dap-python.enable = true;
44
};
55

66
example = {
7-
plugins.dap.extensions.dap-python = {
7+
plugins.dap-python = {
88
enable = true;
99

1010
customConfigurations = [
@@ -34,12 +34,14 @@
3434
};
3535

3636
default = {
37-
plugins.dap.extensions.dap-python = {
37+
plugins.dap-python = {
3838
enable = true;
3939

40-
console = "integratedTerminal";
41-
includeConfigs = true;
4240
adapterPythonPath = "python3";
41+
settings = {
42+
console = "integratedTerminal";
43+
includeConfigs = true;
44+
};
4345
};
4446
};
4547
}

0 commit comments

Comments
 (0)