Convention Class Reference¶
Convention
¶
A Convention is a pattern made up of Fields, and follows the syntax: - {field_name} -> field - {@convention} -> reference to another convention - {$env_variable} -> environment variable
Convention instances use Rules to validate the value of each Field. Convention instances may include FixedFields, ensuring specific fields always retain predetermined values.
Parameters:
-
template(str) –Template string
-
fixed_fields(dict[str, str], default:dict[str, str]()) –Optional mapping of field names to constant values.
Attributes¶
all_fields
¶
environment_variables_fields
¶
expanded_fixed_fields
¶
Returns the fixed fields from the Convention, merged with the fixed fields of referenced Conventions Returns: dict: fully merged fixed_fields
expanded_template
¶
expanded_template: str
Return the template with references to other Conventions resolved.
References use the {@other_convention} syntax and are expanded recursively.
Returns:
-
str–Template string with all {@...} references replaced.
Raises:
-
LucentRecursionError–when too much recursion is detected.
-
LucentConventionNotFoundError–when a referenced Convention does not exist.
mandatory_fields
¶
regex_pattern
¶
regex_pattern: str
Construct a regular expression that matches the Convention as a whole.
required_environment_variables
¶
required_fields
¶
Methods:¶
format
¶
Format the Convention's template with provided fields. FixedFields and environment variables are filled in automatically.
Parameters:
-
fields(dict[str, str] | None, default:None) –Mapping of field names to values to use when formatting.
Returns:
-
str–Formatted string.
Raises:
-
LucentMissingFieldsError–if required fields are missing.
-
LucentMissingEnvironmentVariablesError–if required environment vars are missing.
-
LucentFieldValueError–if any provided field value violates its Rule.
format_path
¶
generate_examples
¶
Generate up to num unique example strings by combining example values
from Rules for mandatory fields.
Parameters:
-
fields(dict[str, str] | None, default:None) –Optional mapping to prefill some fields.
-
num(int, default:5) –Maximum number of distinct examples to generate.
Returns:
-
–
Either a single human-readable pattern string (if no examples available)
-
–
or a sorted list of generated example strings.
get_last_path
¶
Return the last path in the requested ordering.
Parameters:
-
fields(dict[str, str] | None, default:None) –Optional mapping to prefill some fields. All fields that are not provided will be replaced by wildcards
-
order(str, default:'alphabetical') –"alphabetical" or "date".
Returns:
-
Path–Last Path matching the convention.
get_paths
¶
get_paths(fields: dict[str, str] | None = None, sort_callback: Callable[[list[Path]], list[Path]] | None = None) -> list[Path]
Resolve the Convention to a list of filesystem paths using globbing.
Parameters:
-
fields(dict[str, str] | None, default:None) –Optional mapping to prefill some fields (may include wildcards).
-
sort_callback(Callable[[list[Path]], list[Path]] | None, default:None) –Optional function to sort the matched paths.
Returns:
get_paths_sorted_by_date
¶
Return matching paths sorted by filesystem modification time.
glob_pattern
¶
Produce a glob-style pattern for filesystem lookups where unspecified fields are replaced by '*' wildcards.
Parameters:
Returns:
-
str–Glob-compatible pattern string.
Raises:
-
LucentFieldValueError–if provided fields violate their Rules.
-
LucentMissingEnvironmentVariablesError–if required environment vars are missing.
human_readable_example_pattern
¶
human_readable_pattern
¶
increment
¶
increment(string: str | Path, field_to_increment: str = 'version', fields_to_enforce: dict[str, str] | None = None) -> str
Increments a field from the provided string (by default, the "version" field) Additional fields may be set in the process.
Parameters:
-
string(str | Path) –string to modify
-
field_to_increment(str, default:'version') –name of the field that needs to be incremented
-
fields_to_enforce(dict[str, str] | None, default:None) –additional fields to format
Raises:
-
LucentFieldValueError–if any value does not match its Rule.
parse
¶
Parse a string according to the Convention. Extracted field values are returned as a dict.
Parameters:
Returns:
Raises:
-
LucentParseError–when the string does not match the convention.
-
LucentMissingEnvironmentVariablesError–if required environment vars are missing.
-
LucentInconsistentFieldsError–if a field appears multiple times with different values.