democrasite.webiscite.constitution module

This module handles the logic behind the constitution.

This contains functions to read the constitution as json, check which files in a diff contain constitutional amendments, and automatically update the constitution for changes that moved constitutionally protected sections without editing them

democrasite.webiscite.constitution.is_constitutional(diff_str: str) list[str]

Check which files include changes protected by the constitution

Parameters:

diff_str – A string containing the output of a git diff

Returns:

A list of the files that include consitutionally protected edits

Return type:

list[str]

democrasite.webiscite.constitution.read_constitution() dict[str, list[list[int]] | None]

Read the constitution and return it as a type-annotated dict

democrasite.webiscite.constitution.update_constitution(diff_str: str) str

Automatically update the constitution

If a commit edits a file which has some portions protected by the constitution, but does not edit those portions, this method will update the constitution to ensure the same pieces of code remain covered.

For example, say the constitution protects “foo.py” on lines 9 and 10, but a change is made where a line is added between lines 4 and 5. The change is not a constitutional amendment, so the constitution will be altered to protect lines 10 and 11, ensuring the contents of the protected block remain consistent.

Parameters:

diff_str – A string containing the output of a git diff

Returns:

A JSON string containing the updated constitution, or an empty string if no updates are needed

Return type:

str