CHORE: officially renamed files to be deprecated and also made making

templates simpler
This commit is contained in:
2026-10-19 14:29:51 -04:00
parent 380f295c93
commit e2864159a8
10 changed files with 550 additions and 496 deletions
+31 -91
View File
@@ -1,6 +1,7 @@
local M = {}
local utils = require("vern.utils")
local render = require("vern.templates")
local templates = require("vern.templates.python")
function M.create_project(opts)
@@ -25,99 +26,33 @@ function M.create_project(opts)
cfg.python.root,
pname
)
local context = {
local ctx = {
project_name = pname,
}
local bin = vim.tbl_get(
cfg,
"python",
"templates",
"project",
"bin",
"target"
) or ""
-- bin = bin["bin"].target or "src/{project_name}/main.py"
local dest = vim.tbl_get(cfg, "python", "templates", "project") or {}
local bin_path = utils.interpolate(bin, context)
vim.notify(bin_path, vim.log.levels.INFO)
vim.fn.mkdir(
vim.fs.dirname(vim.fs.joinpath(project_root, bin_path)),
vim.fs.joinpath(
project_root,
utils.fmt(cfg.python.source_root, ctx)
),
"p"
)
utils.write_file(
vim.fs.joinpath(project_root, bin_path),
templates.main(pname)
)
vim.notify(
string.format("Created project %s at %s", pname, project_root),
vim.log.levels.INFO
)
-- vim.cmd("edit " .. utils.get_project_root() .. "/" .. rel_path)
-- vim.fn.mkdir(full_project_root .. "/include", "p")
-- utils.write_file(
-- { full_project_root, "main.py" },
-- [[
-- def main():
-- print("Hello, World!")
--
-- if __name__ == "__main__":
-- main()
-- ]]
-- )
-- utils.write_file({ full_project_root, "include/__init__.py" }, "")
-- utils.write_file({ full_project_root, "requirements.txt" }, "")
-- utils.write_file(
-- { full_project_root, "setup.py" },
-- string.format(
-- [[
-- from setuptools import setup, find_packages
--
-- setup(
-- name="%s",
-- version="0.1.0",
-- packages=find_packages(),
-- install_requires=[],
-- python_requires=">=3.6",
-- )
-- ]],
-- project_name
-- )
-- )
-- local gitignore = {
-- "venv/",
-- }
-- utils.init_git(full_project_root, gitignore)
-- vim.cmd("edit " .. full_project_root .. "/main.py")
-- local venv_path = full_project_root .. "/venv"
-- vim.fn.system("python3 -m venv " .. venv_path)
-- vim.g.python3_host_prog = venv_path .. "/bin/python"
-- vim.fn.setenv("VIRTUAL_ENV", venv_path)
-- vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
-- print("Virtual environment activated for " .. project_name)
-- end
--
-- local context = {
-- project_name = utils.get_project_name(),
-- name = pname,
-- }
-- -- local exe = opts.python.templates.project["executable"].target
-- local init = opts.python.templates.project["init"].target
-- local manifest = opts.python.templates.project["manifest"].target
--
-- local exe = (
-- opts.python.templates.project["executable"].target:gsub(
-- "{(%w+)}",
-- context
-- )
-- )
--
-- -- local loc = opts.python.templates.file["module"].target
-- -- local rel_path = (loc:gsub("{(%w+)}", context))
-- local path = vim.fs.joinpath(utils.get_project_root(), exe)
-- utils.write_file(path, templates.main(pname))
local function dump(dst, alt, tmpl)
local full_path = vim.fs.joinpath(
project_root,
utils.fmt(vim.tbl_get(dest, dst, "target") or alt, ctx)
)
utils.dump(full_path, tmpl)
return full_path
end
local bin =
dump("bin", "src/{project_name}/main.py", templates.main(pname))
dump("pkg", "src/{project_name}/__init__.py", templates.__init__(pname))
dump("spec", "pyproject.toml", templates.pyproject(pname))
-- vim.cmd("edit " .. utils.get_project_root() .. "/" .. exe)
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end
@@ -128,14 +63,20 @@ function M.create_file(opts)
default = "",
}, function(fname)
if fname ~= nil and vim.trim(fname) ~= "" then
local loc = opts.python.templates.file["module"].target
local loc = vim.tbl_get(
opts,
"python",
"templates",
"file",
"module"
).target or {}
local context = {
project_name = utils.get_project_name(),
name = fname,
}
local rel_path = (loc:gsub("{(%w+)}", context))
local rel_path = utils.fmt(loc, context)
local path = vim.fs.joinpath(utils.get_project_root(), rel_path)
utils.write_file(path, templates.module(fname))
utils.dump(path, templates.)
vim.cmd("edit " .. utils.get_project_root() .. "/" .. rel_path)
end
end)
@@ -148,10 +89,9 @@ function M.run(opts)
local root = utils.get_project_root() or "."
local project_name = vim.fs.basename(root)
local exe = opts.python.templates.project.executable.target
or "src/%s/main.py"
local exe = opts.python.templates.project.bin.target or "src/%s/main.py"
-- local rel_path = exe:find("%%s") and string.format(exe, project_name) or exe
local rel_path = string.gsub(exe, "%%s", project_name)
local rel_path = utils.fmt(exe, { project_name = project_name })
local full_path = root .. "/" .. rel_path
utils.terminal({ "python3 " .. full_path }, opts.terminal or {})
end