WIP
This commit is contained in:
parent
2735859028
commit
c2ceb239a3
4 changed files with 65 additions and 30 deletions
31
.lazy.lua
Normal file
31
.lazy.lua
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
local function find_table_with_value(tables, search_value)
|
||||||
|
for _, tbl in ipairs(tables) do
|
||||||
|
for _, value in pairs(tbl) do
|
||||||
|
if value == search_value then
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
"mfussenegger/nvim-dap",
|
||||||
|
optional = true,
|
||||||
|
config = function()
|
||||||
|
local root = vim.lsp.get_clients()[1].root_dir
|
||||||
|
table.insert(require("dap").configurations.python, {
|
||||||
|
type = "python",
|
||||||
|
request = "launch",
|
||||||
|
name = "custom",
|
||||||
|
program = root .. "/modules/compose.py",
|
||||||
|
console = "integratedTerminal",
|
||||||
|
pythonPath = os.getenv("VIRTUAL_ENV") .. "/bin/python",
|
||||||
|
args = { root .. "/test.json" },
|
||||||
|
justMyCode = false,
|
||||||
|
})
|
||||||
|
find_table_with_value(require("lazyvim.plugins.extras.dap.core"), "mfussenegger/nvim-dap").config()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
|
@ -22,13 +22,18 @@ def recursive_update(
|
||||||
default = copy.deepcopy(default)
|
default = copy.deepcopy(default)
|
||||||
|
|
||||||
for key in update: # noqa: PLC0206
|
for key in update: # noqa: PLC0206
|
||||||
if isinstance(update[key], dict) and isinstance(default.get(key), dict):
|
if isinstance(update[key], dict) and (
|
||||||
default[key] = recursive_update(default[key], update[key])
|
isinstance(default.get(key), dict) or default.get(key) is None
|
||||||
|
):
|
||||||
|
default[key] = recursive_update(default.get(key, {}), update[key])
|
||||||
|
|
||||||
elif isinstance(update[key], list) and isinstance(default.get(key), list):
|
elif isinstance(update[key], list) and (
|
||||||
default_set = set(default[key])
|
isinstance(default.get(key), list) or default.get(key) is None
|
||||||
custom_set = set(update[key])
|
):
|
||||||
default[key] = list(default_set.union(custom_set))
|
# default_set = set(default.get(key, []))
|
||||||
|
# custom_set = set(update[key])
|
||||||
|
# default[key] = list(default_set.union(custom_set))
|
||||||
|
default[key] = default.get(key, []).extend(update[key])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
default[key] = update[key]
|
default[key] = update[key]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
||||||
# MIT License (see LICENSE)
|
# MIT License (see LICENSE)
|
||||||
|
|
||||||
|
# FIX: This entire library is broken and needs to be fixed
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
@ -46,16 +48,13 @@ def apply_base(state: State, params: dict[str, Any]) -> State:
|
||||||
|
|
||||||
|
|
||||||
def apply_definition(state: State, params: dict[str, Any], definition: dict[str, Any]) -> State:
|
def apply_definition(state: State, params: dict[str, Any], definition: dict[str, Any]) -> State:
|
||||||
service_name: str = params["name"]
|
|
||||||
project = copy.deepcopy(state.after)
|
project = copy.deepcopy(state.after)
|
||||||
services: dict[str, Any] = project["services"]
|
services: dict[str, Any] = project["services"]
|
||||||
service: dict[str, Any] = services[service_name]
|
service: dict[str, Any] = services[params["name"]]
|
||||||
|
|
||||||
_ = recursive_update(service, definition)
|
service = recursive_update(service, definition)
|
||||||
|
|
||||||
services.update({service_name: service})
|
return update(state, params, service)
|
||||||
|
|
||||||
return replace(state, after=project)
|
|
||||||
|
|
||||||
|
|
||||||
def apply_settings(state: State, params: dict[str, Any]) -> State:
|
def apply_settings(state: State, params: dict[str, Any]) -> State:
|
||||||
|
@ -70,22 +69,21 @@ def apply_settings(state: State, params: dict[str, Any]) -> State:
|
||||||
|
|
||||||
|
|
||||||
def update(state: State, params: dict[str, Any], update: dict[str, Any]) -> State:
|
def update(state: State, params: dict[str, Any], update: dict[str, Any]) -> State:
|
||||||
service_name: str = params["name"]
|
|
||||||
project = copy.deepcopy(state.after)
|
project = copy.deepcopy(state.after)
|
||||||
|
|
||||||
project["services"][service_name] = project["services"].get(service_name, {})
|
project["services"][params["name"]] = recursive_update(
|
||||||
_ = recursive_update(project["services"][service_name], update)
|
project["services"].get(params["name"], {}),
|
||||||
|
update,
|
||||||
# FIX: this silently throws out misconfigured volumes
|
|
||||||
unique_volumes = dict(
|
|
||||||
{
|
|
||||||
vol["target"]: vol
|
|
||||||
for vol in project["services"][service_name].get("volumes", [])
|
|
||||||
if "target" in vol
|
|
||||||
}.values(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
project["services"][service_name]["volumes"] = unique_volumes
|
new_definition = project["services"][params["name"]]
|
||||||
|
new_volumes: list[dict[str, Any]] = new_definition.get("volumes") or []
|
||||||
|
|
||||||
|
# FIX: this silently throws out misconfigured volumes
|
||||||
|
unique_volumes = list({vol["source"]: vol for vol in new_volumes if "target" in vol}.values())
|
||||||
|
|
||||||
|
project["services"][params["name"]]["volumes"] = unique_volumes
|
||||||
|
|
||||||
return replace(state, after=project)
|
return replace(state, after=project)
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,11 +95,11 @@ def run_helper(
|
||||||
if not params.get("name"):
|
if not params.get("name"):
|
||||||
params["name"] = str.split(helper.__module__, ".")[-1]
|
params["name"] = str.split(helper.__module__, ".")[-1]
|
||||||
|
|
||||||
if not params.get("overwrite"):
|
if not (overwrite := params.get("overwrite")):
|
||||||
params["overwrite"] = params.get("definition", {})
|
overwrite = params.get("definition", {})
|
||||||
|
|
||||||
state = apply_base(state, params)
|
state = apply_base(state, params)
|
||||||
state = apply_settings(state, params)
|
state = apply_settings(state, params)
|
||||||
state = helper(state, params)
|
state = helper(state, params)
|
||||||
state = apply_definition(state, params, params["overwrite"])
|
state = apply_definition(state, params, overwrite)
|
||||||
return update_project(state)
|
return update_project(state)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
# ruff: noqa: E402
|
# ruff: noqa: E402
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from pprint import pp
|
|
||||||
|
|
||||||
# TODO: break this down per module
|
# TODO: break this down per module
|
||||||
# TODO: generate this by reassembling
|
# TODO: generate this by reassembling
|
||||||
|
@ -485,10 +484,12 @@ def main() -> None:
|
||||||
state = common.get_state(module)
|
state = common.get_state(module)
|
||||||
|
|
||||||
for name, services_params in [(x, y) for x, y in module.params["services"].items() if y]:
|
for name, services_params in [(x, y) for x, y in module.params["services"].items() if y]:
|
||||||
for service_params in services_params:
|
for index, service_params in enumerate(services_params):
|
||||||
|
service_params["_index"] = index
|
||||||
helper = getattr(service, name).helper
|
helper = getattr(service, name).helper
|
||||||
state = service.common.run_helper(state, service_params, helper)
|
state = service.common.run_helper(state, service_params, helper)
|
||||||
pp(state.after)
|
|
||||||
|
print("fuck")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue