PYTHON: Project setup fixed and working, just need to add providers

This commit is contained in:
2026-10-19 20:24:45 -04:00
parent e2864159a8
commit 0f542d56ef
8 changed files with 140 additions and 160 deletions
+5 -5
View File
@@ -1,7 +1,7 @@
local M = {}
---@param opts table
M.template = function(opts)
---@param lang string
M.template = function(lang)
local base = [=[
.DS_Store
@@ -13,7 +13,7 @@ M.template = function(opts)
]=]
local lang_block = {
python = [=[
python = vim.trim([=[
__pycache__/
build/
dist/
@@ -21,10 +21,10 @@ dist/
env/
venv/
.pytest_cache/
]=],
]=]),
}
local extra = (opts and opts and lang_block[opts.lang]) or ""
local extra = (lang and lang_block[lang]) or ""
return base .. extra
end
+9 -4
View File
@@ -1,14 +1,19 @@
local M = {}
function M.imp(ft, template, name)
---@param ft string Filetype of template
---@param template string Template in language table
---@param name string A string to replace temp values in template
---@return string
function M.fetch(ft, template, name)
ft, template, name = ft or "", template or "", name or ""
if ft == "" or template == "" or name == "" then
return
return ""
end
local ok, mod = pcall(require, "vern.templates." .. ft)
if ok and type(mod) ~= "table" then
return string.gsub(mod[template], "%%s", name)
if ok and type(mod) == "table" then
return (string.gsub(mod[template], "%%s", name))
end
return ""
end
return M
+27 -5
View File
@@ -1,4 +1,9 @@
return {
--[[ =====================================================================
TEMPLATE: MAIN (Entrypoint)
File: main.py
Target: src/{project_name}/main.py
===================================================================== --]]
main = vim.trim([=[
def main() -> None:
print("Hello from %s!")
@@ -6,12 +11,24 @@ def main() -> None:
if __name__ == "__main__":
main()
]=]),
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: INIT (Package Anchor)
File: __init__.py
Target: src/{project_name}/__init__.py
===================================================================== --]]
__init__ = vim.trim([=[
# %s init
__all__: list[str] = []
]=]),
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: PYPROJECT (Spec / Build Manifest)
File: pyproject.toml
Target: pyproject.toml
===================================================================== --]]
pyproject = vim.trim([=[
[build-system]
requires = ["hatchling"]
@@ -27,11 +44,16 @@ dependencies = []
[project.scripts]
%s = "%s.main:main"
]=]),
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: MODULE (Standalone File)
File: {name}.py
Target: src/{project_name}/{name}.py
===================================================================== --]]
module = vim.trim([=[
"""
Module: %s
"""
]=]),
]=]) .. "\n",
}