Extension points¶
LangAdapter takes these additions without a change to the library. Each has one guide.
| Extension point | What you write | How a program finds it | Guide |
|---|---|---|---|
| A language | one file, <language>.py, with its adapter class and langadapter_language = <Class>, or a module of an installed package that names its class the same way |
--extension ITEM of langadapter check and langadapter toolchains, langadapter.load_extension, or a consumer's setting, each taking the file or the module's name |
Add a language |
| A metric provider | one file with a provider object and langadapter_metric_provider = <object> |
--extension FILE of langadapter check, langadapter.load_extension, or a consumer's setting |
A metric provider |
| A metric provider on one adapter | adapter.sources.register_metric_provider(provider) in a consumer's own code |
that adapter object only | A metric provider |
| A language's own metric providers | the adapter class's metric_providers() |
every adapter of the language | A metric provider |
| A toolchain part | in the language's file, langadapter_toolchain = {"<system>": "<shell text>"} |
langadapter toolchains LANGUAGE --extension FILE |
Install the toolchains |
| A consumer's requirements | langadapter_profile.json in the consumer's package |
the consumer's module name, or the file, as --for takes them |
Who needs what |
| A language registered in code | langadapter.register(name, file_extensions, factory) in a consumer's own code |
the consumer that calls it | Below |
| A faster per-suite mutation run | a mutation session's per_suite_fast(request) |
the session | Add a language and The conformance check |
| A mutation engine | the adapter's native_mutation_engines, open_mutation_session(engine, ...), which returns a session, and mutation_operators(engine) |
the adapter | Add a language |
A file names its additions with the three top-level names
langadapter_language, langadapter_metric_provider and
langadapter_toolchain, and LangAdapter reads them without any installation
or registration step. A toolchain part belongs to the language the same file
names. LangAdapter has no settings file of its own: a setting that names an
extension file is a consumer's, such as Testuary's, and the consumer loads
the file with langadapter.load_extension.
A language registered in code¶
A consumer that ships its language in its own package can register it from its own code instead of a file:
import langadapter as la
la.register("toy", [".toy"], ToyAdapter)
adapter = la.create("toy", la.ProjectContext("path/to/project"))
la.unregister("toy")
The factory is what create calls with the project's context, usually the
adapter class. A language name or file extension another registration holds
raises RegistrationConflict, unless the call passes replace=True.
langadapter.unregister(name) removes the registration again. The
register
entry gives its arguments.