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)
¶
host_config(env)
¶
Resolves the Modal-host reservations (CPU, memory, concurrency) with their managed-config defaults
Every defaulted MODAL_HOST_VARS entry is included so each sizing key is
always present in the deploy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Mapping[str, str]
|
The resolved managed configuration values |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Each defaulted host sizing variable and its value |
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 |
resolve_backend(flag, env_path)
¶
Resolves which transcription backend to use
Order of Precedence
-
The explicit
flagoverride, when provided -
The persisted
MIRUMOJI_TRANSCRIBE_BACKEND -
The default (
MODAL)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
Backend | None
|
An explicit backend override, or |
required |
env_path
|
Path
|
The managed config file to fall back to |
required |
Returns:
| Type | Description |
|---|---|
Backend
|
The backend to use |
resolve_host_nonpreemptible(env_path, flag=None)
¶
Reports whether the CPU host runs on non-preemptible capacity
Order of Precedence
-
The explicit
flagoverride, when provided -
The persisted
MIRUMOJI_HOST_NONPREEMPTIBLE, overlaid with the process environment -
The default (
False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_path
|
Path
|
The managed config file to read |
required |
flag
|
bool | None
|
An explicit override, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
resolve_host_on_gpu(env_path, flag=None)
¶
Reports whether the host runs on a GPU instead of offloading to the worker
Order of Precedence
-
The explicit
flagoverride, when provided -
The persisted
MIRUMOJI_HOST_ON_GPU, overlaid with the process environment -
The default (
False)
A CPU host (the toggle unset or 0) offloads transcription to the separate
worker, so this returns False
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_path
|
Path
|
The managed config file to read |
required |
flag
|
bool | None
|
An explicit override, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
resolve_image_version(env_path, flag=None)
¶
Resolves the published image version the launcher pulls and composes with
Order of Precedence
The value is considered in the following order
-
The explicit
flagoverride, when provided -
The persisted
MIRUMOJI_IMAGE_VERSION, overlaid with the process environment -
The installed package version
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_path
|
Path
|
The managed config file to read |
required |
flag
|
str | None
|
An explicit version override, or |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The version that fills the |
resolve_managed_config(env_path)
¶
Resolves the managed config, overlaying it with the process environment
Reads the managed .env, overlays the process environment (see
overlay_environ), and keeps only the non-empty managed config keys
Usage
Both the CLI and the GUI build the configuration injected into a Modal-hosted container (and the Modal credentials the deploy authenticates with) from this, so they always agree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_path
|
Path
|
The managed config file to read |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The resolved non-empty managed configuration values |
resolve_source(flag, env_path)
¶
Resolves which image source to use
Order of Precedence
-
The explicit
flagoverride, when provided -
The persisted
MIRUMOJI_IMAGE_SOURCE -
The default (
PULL)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flag
|
bool | None
|
|
required |
env_path
|
Path
|
The managed config file to fall back to |
required |
Returns:
| Type | Description |
|---|---|
ImageSource
|
The image source to use |