mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
plugins/dap-python: migrate to mkNeovimPlugin
This commit is contained in:
parent
6ff7127291
commit
a70168e0fa
5 changed files with 151 additions and 109 deletions
103
plugins/by-name/dap-python/default.nix
Normal file
103
plugins/by-name/dap-python/default.nix
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
optionalString
|
||||||
|
types
|
||||||
|
;
|
||||||
|
inherit (lib.nixvim)
|
||||||
|
defaultNullOpts
|
||||||
|
mkNullOrOption
|
||||||
|
toLuaObject
|
||||||
|
;
|
||||||
|
|
||||||
|
dapHelpers = import ../dap/dapHelpers.nix { inherit lib; };
|
||||||
|
in
|
||||||
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
|
name = "dap-python";
|
||||||
|
package = "nvim-dap-python";
|
||||||
|
|
||||||
|
maintainers = [ lib.maintainers.khaneliman ];
|
||||||
|
|
||||||
|
extraOptions = {
|
||||||
|
adapterPythonPath = lib.mkOption {
|
||||||
|
default = lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ]));
|
||||||
|
defaultText = lib.literalExpression ''
|
||||||
|
lib.getExe (pkgs.python3.withPackages (ps: [ ps.debugpy ]))
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Path to the python interpreter.
|
||||||
|
Path must be absolute or in $PATH and needs to have the `debugpy` package installed.
|
||||||
|
'';
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
|
||||||
|
|
||||||
|
resolvePython = defaultNullOpts.mkLuaFn null ''
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
|
||||||
|
testRunner = defaultNullOpts.mkLuaFn' {
|
||||||
|
description = "The name of test runner to use by default.";
|
||||||
|
pluginDefault = lib.literalMD ''
|
||||||
|
The default value is dynamic and depends on `pytest.ini` or `manage.py` markers.
|
||||||
|
If neither are found, `"unittest"` is used.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
testRunners = mkNullOrOption (with lib.types; attrsOf strLuaFn) ''
|
||||||
|
Set to register test runners.
|
||||||
|
|
||||||
|
Built-in test runners include: `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|`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settingsOptions = {
|
||||||
|
console = defaultNullOpts.mkEnumFirstDefault [
|
||||||
|
"integratedTerminal"
|
||||||
|
"internalConsole"
|
||||||
|
"externalTerminal"
|
||||||
|
] "Debugpy console.";
|
||||||
|
|
||||||
|
includeConfigs = defaultNullOpts.mkBool true "Add default configurations.";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Manually supplied to nvim-dap config module
|
||||||
|
callSetup = false;
|
||||||
|
extraConfig = cfg: {
|
||||||
|
plugins.dap = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
extensionConfigLua =
|
||||||
|
''
|
||||||
|
require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject cfg.settings})
|
||||||
|
''
|
||||||
|
+ (optionalString (cfg.testRunners != null) ''
|
||||||
|
table.insert(require("dap-python").test_runners,
|
||||||
|
${toLuaObject (builtins.mapAttrs (_: lib.nixvim.mkRaw) cfg.testRunners)})
|
||||||
|
'')
|
||||||
|
+ (optionalString (cfg.customConfigurations != null) ''
|
||||||
|
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
|
||||||
|
'')
|
||||||
|
+ (optionalString (cfg.resolvePython != null) ''
|
||||||
|
require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
|
||||||
|
'')
|
||||||
|
+ (optionalString (cfg.testRunner != null) ''
|
||||||
|
require("dap-python").test_runner = ${toLuaObject cfg.testRunner};
|
||||||
|
'');
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# NOTE: Renames added in https://github.com/nix-community/nixvim/pull/2897 (2025-01-26)
|
||||||
|
imports = [ ./deprecations.nix ];
|
||||||
|
}
|
41
plugins/by-name/dap-python/deprecations.nix
Normal file
41
plugins/by-name/dap-python/deprecations.nix
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
oldPluginBasePath = [
|
||||||
|
"plugins"
|
||||||
|
"dap"
|
||||||
|
"extensions"
|
||||||
|
"dap-python"
|
||||||
|
];
|
||||||
|
newPluginBasePath = [
|
||||||
|
"plugins"
|
||||||
|
"dap-python"
|
||||||
|
];
|
||||||
|
|
||||||
|
settingsPath = newPluginBasePath ++ [ "settings" ];
|
||||||
|
|
||||||
|
renamedOptions = [
|
||||||
|
[ "enable" ]
|
||||||
|
[ "adapterPythonPath" ]
|
||||||
|
[ "customConfigurations" ]
|
||||||
|
[ "resolvePython" ]
|
||||||
|
[ "testRunner" ]
|
||||||
|
[ "testRunners" ]
|
||||||
|
];
|
||||||
|
|
||||||
|
renamedSettingsOptions = [
|
||||||
|
"console"
|
||||||
|
"includeConfigs"
|
||||||
|
];
|
||||||
|
|
||||||
|
renameWarnings =
|
||||||
|
lib.nixvim.mkSettingsRenamedOptionModules oldPluginBasePath settingsPath
|
||||||
|
renamedSettingsOptions;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports =
|
||||||
|
renameWarnings
|
||||||
|
++ (map (
|
||||||
|
optionPath:
|
||||||
|
lib.mkRenamedOptionModule (oldPluginBasePath ++ optionPath) (newPluginBasePath ++ optionPath)
|
||||||
|
) renamedOptions);
|
||||||
|
}
|
|
@ -1,103 +0,0 @@
|
||||||
{
|
|
||||||
lib,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (lib)
|
|
||||||
optionalString
|
|
||||||
types
|
|
||||||
;
|
|
||||||
inherit (lib.nixvim)
|
|
||||||
defaultNullOpts
|
|
||||||
mkNullOrOption
|
|
||||||
toLuaObject
|
|
||||||
;
|
|
||||||
|
|
||||||
cfg = config.plugins.dap.extensions.dap-python;
|
|
||||||
dapHelpers = import ./dapHelpers.nix { inherit lib; };
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.plugins.dap.extensions.dap-python = {
|
|
||||||
enable = lib.mkEnableOption "dap-python";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "dap-python" {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"nvim-dap-python"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
adapterPythonPath = lib.mkOption {
|
|
||||||
default = lib.getExe (pkgs.python3.withPackages (ps: with ps; [ debugpy ]));
|
|
||||||
defaultText = lib.literalExpression ''
|
|
||||||
lib.getExe (pkgs.python3.withPackages (ps: with ps; [ debugpy ]))
|
|
||||||
'';
|
|
||||||
description = "Path to the python interpreter. Path must be absolute or in $PATH and needs to have the debugpy package installed.";
|
|
||||||
type = types.str;
|
|
||||||
};
|
|
||||||
|
|
||||||
console = defaultNullOpts.mkEnumFirstDefault [
|
|
||||||
"integratedTerminal"
|
|
||||||
"internalConsole"
|
|
||||||
"externalTerminal"
|
|
||||||
] "Debugpy console.";
|
|
||||||
|
|
||||||
customConfigurations = mkNullOrOption (types.listOf dapHelpers.configurationOption) "Custom python configurations for dap.";
|
|
||||||
|
|
||||||
includeConfigs = defaultNullOpts.mkBool true "Add default configurations.";
|
|
||||||
|
|
||||||
resolvePython = defaultNullOpts.mkLuaFn null ''
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
|
|
||||||
testRunner = mkNullOrOption (types.either types.str types.rawLua) ''
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
|
|
||||||
testRunners = mkNullOrOption (with lib.types; attrsOf strLuaFn) ''
|
|
||||||
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|.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
config =
|
|
||||||
let
|
|
||||||
options = with cfg; {
|
|
||||||
inherit console;
|
|
||||||
include_configs = includeConfigs;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
lib.mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
plugins.dap = {
|
|
||||||
enable = true;
|
|
||||||
|
|
||||||
extensionConfigLua =
|
|
||||||
''
|
|
||||||
require("dap-python").setup("${cfg.adapterPythonPath}", ${toLuaObject options})
|
|
||||||
''
|
|
||||||
+ (optionalString (cfg.testRunners != null) ''
|
|
||||||
table.insert(require("dap-python").test_runners,
|
|
||||||
${toLuaObject (builtins.mapAttrs (_: lib.nixvim.mkRaw) cfg.testRunners)})
|
|
||||||
'')
|
|
||||||
+ (optionalString (cfg.customConfigurations != null) ''
|
|
||||||
table.insert(require("dap").configurations.python, ${toLuaObject cfg.customConfigurations})
|
|
||||||
'')
|
|
||||||
+ (optionalString (cfg.resolvePython != null) ''
|
|
||||||
require("dap-python").resolve_python = ${toLuaObject cfg.resolvePython}
|
|
||||||
'')
|
|
||||||
+ (optionalString (cfg.testRunner != null) ''
|
|
||||||
require("dap-python").test_runner = ${toLuaObject cfg.testRunner};
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -13,7 +13,6 @@ let
|
||||||
in
|
in
|
||||||
lib.nixvim.plugins.mkNeovimPlugin {
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
imports = [
|
imports = [
|
||||||
./dap-python.nix
|
|
||||||
./dap-ui.nix
|
./dap-ui.nix
|
||||||
./dap-virtual-text.nix
|
./dap-virtual-text.nix
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
empty = {
|
empty = {
|
||||||
plugins.dap.extensions.dap-python.enable = true;
|
plugins.dap-python.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
example = {
|
example = {
|
||||||
plugins.dap.extensions.dap-python = {
|
plugins.dap-python = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
customConfigurations = [
|
customConfigurations = [
|
||||||
|
@ -34,12 +34,14 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
default = {
|
default = {
|
||||||
plugins.dap.extensions.dap-python = {
|
plugins.dap-python = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
|
adapterPythonPath = "python3";
|
||||||
|
settings = {
|
||||||
console = "integratedTerminal";
|
console = "integratedTerminal";
|
||||||
includeConfigs = true;
|
includeConfigs = true;
|
||||||
adapterPythonPath = "python3";
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue