wads.profiles¶
Declarative generation profiles and overlays built on the engine.
A profile is a named declarative description of a project setup expressed as a
list of wads.templating.Artifact. The default profile (python-lib)
is produced by wads.populate.
This module hosts two opt-in overlays added on top of an existing project:
The frontend profile registry (issue #39): a small registry of language/toolchain profiles –
js(the original #32 overlay, the back-compat anchor),ts(single-package TypeScript), andts-monorepo(pnpm workspaces + turbo). A project may declare several frontend components (e.g.jsandts); each lives in its own subdir with its own path-filtered workflow, so they never collide. Selected viapopulate --frontend <profile>[,<profile>](--with-npmstays as an alias for--frontend js). Profiles are extensible throughregister_frontend_profile().The tests-folder overlay (issue #4): scaffolds a
tests/package.The native-core registry (issue #214): a Rust core built by maturin behind a Python facade (
populate --native maturin); seeapply_native().
Nothing here runs by default; the Python populate path and the
name/name/ root layout are untouched.
Module Attributes
Where a Python package and its npm twin keep the golden cases both test suites run (i2mint/wads#209). |
|
Where a Rust core lives in the native (maturin) layout; when present, a change there runs the npm CI too (a wasm build may compile it). |
|
|
|
vitest's semver range in the |
|
Node versions a component's CI matrix runs, unless its profile says otherwise. |
|
Where the |
|
Root licence file names a frontend component copies, in order of preference. |
|
The frontend profile registry. |
|
The native-backend registry. |
Functions
|
Apply one frontend profile component to an existing project directory. |
|
Scaffold a native core ( |
|
Deprecated alias for |
|
Scaffold a |
|
Inputs outside its subdir an npm component's CI should run on. |
|
|
|
Build the render context shared by all frontend-profile templates. |
|
Look up a registered profile, with an informative error if unknown. |
|
Look up a registered native profile, with an informative error if unknown. |
|
|
|
Artifacts that scaffold a |
|
A copy of |
|
The |
|
The lines a kept (real) facade lacks for the template's tests ('' if none). |
|
The SPDX expression the package at |
|
Map the template tokens to their values for |
|
The pyproject tables |
|
|
|
What an EXISTING pyproject needs for |
|
Deprecated: the |
|
Deprecated: render context for the |
|
Register (or override) a frontend profile by name. |
|
Register (or override) a native profile by name. |
Classes
|
A declarative frontend language/toolchain profile. |
|
A native (compiled-extension) backend that |
- wads.profiles.DFLT_NODE_VERSIONS = ('20', '22', '24')¶
Node versions a component’s CI matrix runs, unless its profile says otherwise.
- wads.profiles.DFLT_RUST_DIR = 'rust'¶
Where a Rust core lives in the native (maturin) layout; when present, a change there runs the npm CI too (a wasm build may compile it).
- wads.profiles.DFLT_SHARED_FIXTURES_DIR = 'fixtures'¶
Where a Python package and its npm twin keep the golden cases both test suites run (i2mint/wads#209). A change there runs the npm CI as well as the Python CI.
- wads.profiles.DFLT_VITEST_RANGE = '^3'¶
vitest’s semver range in the
tstemplate. 3.x still installs on Node 20; 2.x has a critical advisory (tinypool) and 4.x a moderate one (@vitest/mocker); 5.x needs Node >= 22.12, so only a profile that sets a Node floor of 22 uses it.
- wads.profiles.EXAMPLE_PACKAGE_DIR = 'packages/core'¶
Where the
ts-monorepoexample package lives, relative to the workspace root.
- wads.profiles.FRONTEND_PROFILES: dict = {'js': FrontendProfile(name='js', default_subdir='js', default_package_manager='npm', artifacts=<function _js_artifacts>, description='JavaScript single package (the original #32 overlay).', context_defaults={}), 'ts': FrontendProfile(name='ts', default_subdir='ts', default_package_manager='npm', artifacts=<function _ts_artifacts>, description='TypeScript single package (tsconfig + tsup build + vitest).', context_defaults={}), 'ts-monorepo': FrontendProfile(name='ts-monorepo', default_subdir='ts', default_package_manager='pnpm', artifacts=<function _ts_monorepo_artifacts>, description='TypeScript monorepo (pnpm workspaces + turbo).', context_defaults={}), 'ts-package': FrontendProfile(name='ts-package', default_subdir='.', default_package_manager='npm', artifacts=<function _ts_artifacts>, description='A repo that is only a TypeScript package, at its root (no Python project; Node >= 22, CI on 22 and 24).', context_defaults={'node_versions': ('22', '24'), 'engines_node': '>=22.12', 'vitest_range': '^5'})}¶
The frontend profile registry. Extend it via
register_frontend_profile().
- class wads.profiles.FrontendProfile(name, default_subdir, default_package_manager, artifacts, description='', context_defaults=dict())[source]¶
Bases:
objectA declarative frontend language/toolchain profile.
- Parameters:
name (
str) – registry key (e.g."js","ts","ts-monorepo").default_subdir (
str) – subdir the component lives in when unspecified.default_package_manager (
str) –"npm"or"pnpm".artifacts (
Callable[[Mapping],list]) –context -> list[Artifact]builder for this profile.description (
str) – one-line human summary.context_defaults (
Mapping) –frontend_context()keyword defaults this profile sets (node_versions,engines_node,vitest_range).
- wads.profiles.LICENSE_FILENAMES = ('LICENSE', 'LICENSE.md', 'LICENSE.txt', 'LICENCE', 'COPYING')¶
Root licence file names a frontend component copies, in order of preference.
- wads.profiles.NATIVE_PROFILES: dict = {'maturin': NativeProfile(name='maturin', template_dir='/home/runner/work/wads/wads/wads/data/native/maturin', pyproject_fragment='/home/runner/work/wads/wads/wads/data/native/maturin_pyproject.toml', replaces=('build-system',), drops=('tool.hatch',), facade='tmpl_pkg/__init__.py', new_package_only=('tmpl_pkg/py.typed',), gitignore_patterns=('target', '*.so'), lockfile='Cargo.lock', lockfile_command=('cargo', 'generate-lockfile', '--quiet'), lockfile_env=(('RUSTUP_AUTO_INSTALL', '0'),), missing_toolchain=('is not installed', 'rustup toolchain install'), toolchain_pin=('rust-toolchain.toml', 'toolchain', 'channel'), toolchain_list=('rustup', 'toolchain', 'list'), unlicensed=(('license = "tmpl-license"', '# license = "<SPDX id>"'), ('license.workspace = true', '# license.workspace = true')), description='Rust core (rust/core) + PyO3 binding (rust/py) built by maturin.')}¶
The native-backend registry. Extend it via
register_native_profile().
- class wads.profiles.NativeProfile(name, template_dir, pyproject_fragment, replaces=(), drops=(), facade='', new_package_only=(), gitignore_patterns=(), lockfile='', lockfile_command=(), lockfile_env=(), missing_toolchain=(), toolchain_pin=(), toolchain_list=(), unlicensed=(), description='')[source]¶
Bases:
objectA native (compiled-extension) backend that
populate --nativecan scaffold.Paths are template paths (with the tokens); pyproject tables are dotted (
"tool.hatch").- Parameters:
name (
str) – registry key; also the backend namewads.native_buildknows.template_dir (
str) – folder of files written at their (token-substituted) paths.pyproject_fragment (
str) – TOML file of the pyproject tables the backend needs.replaces (
tuple) – fragment tables that replace the pyproject’s whole (rather than merge into it), e.g."build-system".drops (
tuple) – tables a NEW pyproject loses, because they configure whatreplacesreplaced (e.g."tool.hatch"); an existing one is told to.facade (
str) – the package’s__init__.pytemplate. A missing or blank one is written; a real one is kept and the lines the template tests need are reported.new_package_only (
tuple) – files written only when the package is new (no real facade).gitignore_patterns (
tuple) –.gitignoreentries the layout relies on.lockfile (
str) – lockfile the build needs (--locked), generated when missing.lockfile_command (
tuple) – command generatinglockfile, run in the project root.lockfile_env (
tuple) –(name, value)pairs added to that command’s environment.missing_toolchain (
tuple) –(marker, command): when the lockfile command’s stderr hasmarker, the pinned toolchain is missing andcommandinstalls it.toolchain_pin (
tuple) –(file, table, key)naming the pinned toolchain channel (checked againsttoolchain_listbefore the lockfile command runs).toolchain_list (
tuple) – command listing the installed toolchains, one per line.unlicensed (
tuple) –(text, replacement)pairs applied to the templates when the package’s licence cannot be determined (the crates then declare none).description (
str) – one-line human summary.
- wads.profiles.ROOT_SUBDIR = '.'¶
subdirof a component that is the repo root (a TypeScript-only package).
- wads.profiles.apply_frontend(pkg_dir, *, profile='js', project_name, description='', license=None, subdir=None, package_name=None, version='0.0.1', package_manager=None, workspace_glob='packages/*', example_package_name=None, watch_paths=None, repository_url=None, overwrite=(), on_add=None, on_skip=None)[source]¶
Apply one frontend profile component to an existing project directory.
subdirandpackage_managerdefault to the selected profile’s defaults.watch_pathsare the inputs outside the subdir that also run the component’s CI (defaultdefault_npm_watch_paths()ofpkg_dir). Returns thewads.templating.GenerationResult.>>> import tempfile >>> d = tempfile.mkdtemp() >>> res = apply_frontend(d, profile="ts", project_name="widget") >>> sorted(res.added) ['.github/workflows/npm-ci-ts.yml', 'ts/package.json', 'ts/src/index.test.ts', 'ts/src/index.ts', 'ts/tsconfig.json', 'ts/tsconfig.test.json']
- Return type:
- wads.profiles.apply_native(pkg_dir, *, backend='maturin', project_name, license=None, overwrite=(), generate_lockfile=True, lockfile_timeout=300, on_add=None, on_skip=None, on_error=None, on_attention=<function _warn_attention>)[source]¶
Scaffold a native core (
backend) into the project atpkg_dir.Writes the backend’s template files that do not exist yet (
overwritenames the ones to replace). A missing or blank facade (__init__.py) is written; a real one is kept, the files of a new package only (py.typed) are left out, and the lines the template’s tests need are reported.on_attention(filename, reason)also gets missing.gitignoreentries and a lockfile it could not generate. pyproject.toml is not touched here:populatemergesnative_pyproject_fragment()into a new one and reportsnative_pyproject_todo()for an existing one.>>> import tempfile >>> d = tempfile.mkdtemp() >>> res = apply_native( ... d, project_name="fast_thing", generate_lockfile=False, on_attention=None ... ) >>> [t for t in res.added if t.startswith("rust/")] ['rust/core/Cargo.toml', 'rust/core/src/lib.rs', 'rust/py/Cargo.toml', 'rust/py/src/lib.rs']
- Return type:
- wads.profiles.apply_npm_overlay(pkg_dir, *, project_name, description='', license=None, npm_subdir='js', npm_package_name=None, npm_version='0.0.1', npm_package_manager='npm', overwrite=(), on_add=None, on_skip=None)[source]¶
Deprecated alias for
apply_frontend(profile="js", ...)(issue #32 surface).Kept so existing callers and tests keep working; new code should call
apply_frontend().
- wads.profiles.apply_tests_overlay(pkg_dir, *, project_name, with_data_util=True, overwrite=(), on_add=None, on_skip=None)[source]¶
Scaffold a
tests/folder in an existing project (issue #4).
- wads.profiles.default_npm_watch_paths(repo_dir=None)[source]¶
Inputs outside its subdir an npm component’s CI should run on.
The shared fixtures directory always (a pattern that matches nothing costs nothing), and the Rust core when
repo_dirhas one.>>> default_npm_watch_paths() ['fixtures/**']
- Return type:
- wads.profiles.find_license_file(repo_dir, *, names=('LICENSE', 'LICENSE.md', 'LICENSE.txt', 'LICENCE', 'COPYING'))[source]¶
(file name, text)of the repo’s root licence, orNoneif it has none.>>> import tempfile >>> d = tempfile.mkdtemp() >>> find_license_file(d) is None True >>> _ = open(os.path.join(d, "LICENSE.md"), "w").write("MIT") >>> find_license_file(d) ('LICENSE.md', 'MIT')
- wads.profiles.frontend_context(*, profile_name, project_name, description='', license=None, subdir, package_name=None, version='0.0.1', package_manager='npm', workspace_glob='packages/*', example_package_name=None, license_file=None, watch_paths=None, node_versions=('20', '22', '24'), engines_node=None, vitest_range='^3', repository_url=None)[source]¶
Build the render context shared by all frontend-profile templates.
The returned mapping is a superset: it carries the keys every profile’s templates may reference (single-package and monorepo). Unused keys are harmless under Jinja
StrictUndefinedbecause that only errors on keys a template references yet are missing.- Return type:
- wads.profiles.get_frontend_profile(name)[source]¶
Look up a registered profile, with an informative error if unknown.
- Return type:
- wads.profiles.get_native_profile(name)[source]¶
Look up a registered native profile, with an informative error if unknown.
- Return type:
- wads.profiles.git_repository_url(url)[source]¶
urlas thegit+https://....gitform package.json’srepositorytakes.An ssh remote (
git@host:o/r) becomes https, credentials in a url are dropped (package.json is published), and agit+or shorthand (github:o/r) url is kept as it is.>>> git_repository_url("https://github.com/thorwhalen/byok/") 'git+https://github.com/thorwhalen/byok.git' >>> git_repository_url("git+https://github.com/o/r.git") 'git+https://github.com/o/r.git' >>> git_repository_url("git@github.com:o/r.git") 'git+https://github.com/o/r.git' >>> git_repository_url("https://user:tok@github.com/o/r") 'git+https://github.com/o/r.git' >>> git_repository_url("github:o/r") 'github:o/r' >>> git_repository_url(None) is None True
- wads.profiles.make_tests_overlay_artifacts(project_name, *, with_data_util=True)[source]¶
Artifacts that scaffold a
tests/folder for a project.Writes
tests/__init__.py,tests/test_<project_name>.py(a smoke test), and optionallytests/util.py(atests/dataaccessor, per #4). The smoke-test filename embeds the package name, so it is built here where the name is known.- Return type:
- wads.profiles.merge_native_pyproject(pyproject, fragment, *, backend='maturin')[source]¶
A copy of
pyprojectwith a nativefragmentmerged in (for a NEW package).The profile’s
replacestables are replaced and itsdropstables removed; the other tables merge, lists gaining the items they lack.>>> new = merge_native_pyproject( ... {"build-system": {"requires": ["hatchling"], "build-backend": "hatchling.build"}, ... "project": {"optional-dependencies": {"dev": ["pytest"]}}, ... "tool": {"hatch": {"build": {}}, "ruff": {}}}, ... native_pyproject_fragment("fast_thing"), ... ) >>> new["build-system"]["build-backend"], sorted(new["tool"]) ('maturin', ['maturin', 'pytest', 'ruff', 'uv']) >>> new["project"]["optional-dependencies"]["dev"] ['pytest', 'hypothesis']
- Return type:
- wads.profiles.native_artifacts(backend, project_name, *, license=None, skip=())[source]¶
The
Artifactlist a native backend writes forproject_name.skipnames template paths to leave out.>>> sorted(a.target for a in native_artifacts("maturin", "fast_thing"))[:3] ['Cargo.toml', 'clippy.toml', 'deny.toml']
- Return type:
- wads.profiles.native_facade_todo(pkg_dir, project_name, *, backend='maturin', license=None)[source]¶
The lines a kept (real) facade lacks for the template’s tests (’’ if none).
>>> import tempfile >>> d = tempfile.mkdtemp() >>> os.makedirs(os.path.join(d, "fast_thing")) >>> _ = open(os.path.join(d, "fast_thing", "__init__.py"), "w").write("X = 1\n") >>> print(native_facade_todo(d, "fast_thing")) from importlib.metadata import version as _version from fast_thing import _core ... def hamming(a: str, b: str) -> int: ...
- Return type:
- wads.profiles.native_licence(pkg_dir)[source]¶
The SPDX expression the package at
pkg_dirdeclares, orNone.Metadata only, never a guess from a licence document:
[project].licenseas a string or{text = ...}, canonicalised; else theLicense ::classifiers, joined withOR(Noneif any is not recognised).{file = ...}orlicense-filesalone say no SPDX id, soNone.>>> import tempfile >>> d = tempfile.mkdtemp() >>> native_licence(d) is None True >>> _ = open(os.path.join(d, "pyproject.toml"), "w").write( ... '[project]\nclassifiers = ["License :: OSI Approved :: MIT License",' ... ' "License :: OSI Approved :: Apache Software License"]\n' ... ) >>> native_licence(d) 'MIT OR Apache-2.0'
- wads.profiles.native_names(project_name, *, license=None, backend='maturin')[source]¶
Map the template tokens to their values for
project_name.The project name is the import name (
populatemakes<name>/<name>/), so it must be a lowercase identifier; Cargo package names are its kebab-case form.licenseis the package’s SPDX id; without one the crates declare no licence (the profile’sunlicensededits) rather than a guessed one.>>> native_names("fast_thing", license="Apache-2.0") {'tmpl_pkg': 'fast_thing', 'tmpl-pkg': 'fast-thing', 'tmpl-license': 'Apache-2.0'} >>> native_names("fast_thing")['license = "tmpl-license"'] '# license = "<SPDX id>"'
- Return type:
- wads.profiles.native_pyproject_fragment(project_name, *, backend='maturin')[source]¶
The pyproject tables
backendneeds, forproject_name.>>> frag = native_pyproject_fragment("fast_thing") >>> frag["build-system"]["build-backend"], frag["tool"]["maturin"]["module-name"] ('maturin', 'fast_thing._core')
- Return type:
- wads.profiles.native_pyproject_gaps(pyproject, project_name, *, backend='maturin')[source]¶
(required, recommended): what an EXISTING pyproject lacks forbackend.Required: absent keys and missing list items, and a
replacestable whose scalars differ (another build backend) or are absent, given whole. Recommended: values set otherwise than the template’s (a deliberate choice stays yours), and areplacestable that only lacks list items (e.g. an olderrequirespin).>>> required, recommended = native_pyproject_gaps( ... {"build-system": {"requires": ["maturin>=1.9.4,<2"], "build-backend": "maturin"}}, ... "fast_thing", ... ) >>> "build-system" in required, recommended["build-system"]["build-backend"] (False, 'maturin')
- Return type:
- wads.profiles.native_pyproject_todo(pyproject, project_name, *, backend='maturin')[source]¶
What an EXISTING pyproject needs for
backend, as TOML text (’’ if nothing).populatenever rewrites an existing pyproject.toml; it reports this instead. Two blocks, each valid TOML:# Requiredand# Recommended(native_pyproject_gaps()).>>> print(native_pyproject_todo({}, "fast_thing")) # Required: merge into pyproject.toml (lists: add the items shown). # [build-system] replaces yours. [build-system] requires = [...] build-backend = "maturin" ... module-name = "fast_thing._core" ... >>> pyproject = merge_native_pyproject({}, native_pyproject_fragment("fast_thing")) >>> native_pyproject_todo(pyproject, "fast_thing") ''
- Return type:
- wads.profiles.npm_overlay_artifacts(npm_subdir='js')[source]¶
Deprecated: the
jsoverlay artifacts. Use thejsfrontend profile.- Return type:
- wads.profiles.npm_overlay_context(*, project_name, description='', license=None, npm_subdir='js', npm_package_name=None, npm_version='0.0.1', npm_package_manager='npm')[source]¶
Deprecated: render context for the
jsoverlay. Useapply_frontend().- Return type:
- wads.profiles.register_frontend_profile(profile)[source]¶
Register (or override) a frontend profile by name. Returns the profile.
Its
context_defaultskeys must befrontend_context()keywords, so a typo fails here and not at the firstapply_frontend.- Return type: