feature:inject-config

Generate or update a feature’s config.py from environment variables detected in source code.


Usage

splent feature:inject-config <feature_ref> [--dry-run]
Argument / Option Description
<feature_ref> Feature name (e.g. splent_feature_confirmemail). Must be editable (workspace root).
--dry-run Show the generated config.py without writing it.

Examples

Preview what would be generated:

splent feature:inject-config splent_feature_confirmemail --dry-run

Generate or update config.py:

splent feature:inject-config splent_feature_confirmemail

Example output

  feature:inject-config -- splent_feature_confirmemail

  Detected 2 env var(s):
    CONFIRM_EMAIL_SALT                  default: "sample_salt"
    CONFIRM_EMAIL_TOKEN_MAX_AGE         default: 3600

  ✅ config.py created.

Generated config.py

"""
confirmemail feature configuration.

Auto-generated by `splent feature:inject-config`.
Injects environment variables into Flask app.config.
"""

import os


def inject_config(app):
    app.config.update({
        "CONFIRM_EMAIL_SALT": os.getenv("CONFIRM_EMAIL_SALT", "sample_salt"),
        "CONFIRM_EMAIL_TOKEN_MAX_AGE": int(os.getenv("CONFIRM_EMAIL_TOKEN_MAX_AGE", "3600")),
    })

Description

Scans all .py files in the feature’s source directory (excluding config.py itself and migrations/) for environment variable usage:

Pattern Example
os.getenv("KEY", "default") Detected with default
os.environ.get("KEY", "default") Detected with default
os.getenv("KEY") Detected, default set to ""
os.environ["KEY"] Detected, default set to ""

Type coercion

The generator detects types from defaults and adds appropriate coercion:

Default Generated expression
"True" / "False" os.getenv("KEY", "True").lower() == "true"
3600 (digits) int(os.getenv("KEY", "3600"))
"text" os.getenv("KEY", "text")

Update mode

If config.py already exists, the command checks for new variables that are missing from the existing file. If all detected variables are already present, it reports the file is up to date.


Integration with feature:contract

When you run splent feature:contract --write, it checks whether config.py is missing or outdated. If env vars are detected but not in config.py, it prompts you to run feature:inject-config automatically.

This ensures that developers never forget to create config.py – the contract workflow catches it.


Why config.py matters

Without config.py, environment variables used via os.getenv() in services or routes are invisible to the framework:

  • check:product cannot verify they are satisfied
  • Config overwrites by refinement features (e.g. mailhog overriding mail) are not tracked
  • The splent_config_trace has no record of them

With config.py, the framework’s FeatureIntegrator calls inject_config(app) during feature loading, which populates app.config and the config trace.


Requirements

  • The feature must be editable (at workspace root, not pinned in cache).

See also


Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es