Envfile
envfile
¶
Defines functions to read, edit, and write a .env configuration file for an
end-user
The .env file is stored in the application's data directory in the user's
machine and is used to start the Mirumoji Docker Compose application with the
configuration that was selected by the user via the launcher. It is also
used to perist that information for future runs
delete_value(path, key)
¶
import_file(source, target)
¶
Merges an external .env file into the managed config file
Reads the managed target, overrides its values with the values present
in source (keys absent from source are kept),
and writes the merged result back to target
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path
|
The external |
required |
target
|
Path
|
The managed config file to overwrite |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The merged values now persisted in |
Raises:
| Type | Description |
|---|---|
EnvConfigError
|
If |
missing_required(specs, values)
¶
Returns the required environment variables that still have no value set
Checks the EnvVar.required attribute to check if the environment
variable is required and appends it to a list if it doesn't contain a
value in values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specs
|
Iterable[EnvVar]
|
The environment variables to check |
required |
values
|
Mapping[str, str]
|
The currently resolved values |
required |
Returns:
| Type | Description |
|---|---|
list[EnvVar]
|
The required environment variables with no non-empty values |
overlay_environ(values, names)
¶
Merges the environment variables stored in values with the ones set in
the current proccess' context (accessed via os.environ) if they're listed
in names
For each named variable not already set in values, adds a non-empty
value from os.environ if present. The values in values take precedence
when a named variable is present both in values and os.environ.
Empty string values are considered as not set
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Mapping[str, str]
|
The values read from the |
required |
names
|
Iterable[str]
|
The variable names to consider |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A new dict combining the file values and any environment fallbacks |
read(path)
¶
read_deployment(env)
¶
Parses the persisted deployment choice from the resolved values of a managed config file
Missing or unrecognised values return None so that callers can
fall back to a flag or a built-in default
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str]
|
The resolved environment values |
required |
Returns:
| Type | Description |
|---|---|
tuple[Backend | None, ImageSource | None]
|
The persisted |