Improve Python config file template substitution #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "jan/feature/20260609-pyproject-toml-add-mypypath"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Improve Python config file template substitution
This PR introduces a series of commits leading up to automatic management of dependency paths in the Python devtools configuration files
pyproject.tomlandpyrightconfig.jsonin the root of every jw-pkg - compatible repository.py-topdir.mk: Introduce $(PY_CHECK_ROOTS)
Replace variable
PY_SRC_ROOTbyPY_CHECK_ROOTS. The namePY_SRC_ROOTwas a bad choice, given that it isn't immediately obvious that it a) can contain multiple root locations to be checked, and that it b) specifically concerns static type checking.As of this commit, it's possible to limit the type checking scope with
PY_CHECK_ROOTSas inPY_CHECK_ROOTS="src/python/jw/pkg/CmdBase.py src/python/jw/lib" make checkcmds.projects.CmdCreateFile: Add subdirs src/python
In order to allow Pyright to check the types provided by dependant repositories without installing them, pyrightconfig.json contains a list of paths to their root directories in "extraPaths". These paths are unusable for Pyright, though: For type checking to work, it needs to be pointed to the
jwnamespace package paths within those repos. This commit achieves that by appending the subdirs src/python and tools/python to them, provided they exist.TODO: This fix hardcodes the current project directory structure. Better would be a way to customize that via makefiles, where the paths can be more easily customized.
conf/templates: Add subdir
Add $(TOPDIR)/conf/templates as a location for templates, i.e. input files to the CmdCreateFile template rendering command.
cmds.projects.lib.templates.tmpl_render(): search_path
Add an additional keyword-argument
search_pathtotemplates.tmpl_render(). It allows to specifiy a list of directory paths in which a template of a given name can be found. It defaults to[], in which case only the built-in templates are considered. Otherwise file locations are tried first, then the built-in templates.cmds.projects.lib.templates.tmpl_render(): RenderValues
tmpl_render()'s "values" argument currently understandsdict[str,str|list[str]]. Enhance that to understand the broaderRenderValuestype, which also includesIterable[tuple[str, str]], as produced byargparse.add_argument(action='append').This commit also adds proper type-checking for the values argument. Before, its type had gone unchecked entirely.
cmds.projects.CmdCreateFile: Support --search-path
Add --search-path to the list of CmdCreateFile's supported options. Its value is split by ":" and subsequently passed to the tmpl_render()'s search_path argument.
cmds.projects.CmdCreateFile: Add more options
Add an additional, more generic value that
--formatunderstands:tmpl. If chosen, the template selected by the new option--template-nameis rendered by replacing--field key=valuepairs.This commit also adds the option --quote, which makes the renderer enclose the rendered variable values in double quotes.
py-topdir.mk: Add --config pyproject.toml
ruff tries to recursivley use every config file it finds and stumbles over a template:
Limiting it to the toplevel pyproject.toml by explicitly specifying --config fixes the behaviour, so that's what this commit does.
py-topdir.mk: Add machinery to generate pyproject.toml
pyproject.toml is currently copied unchanged from conf/topdir to the toplevel directory. Set up machinery in py-topdir.mk to render it from a template in conf/templates instead, replacing {mypypath} in the process.
pyproject.toml: Add {mypypath}
Add a [tool.mypy] section to pyproject.toml with a {mypypath} template variable. The already existing template generation mechanism in py-topdir.mk should fill that in with a path pointing to all Python modules managed by jw-pkg:
pyproject.toml: Add {mypypath}to Improve Python config file template substitution