Skip to content

Commit 0eb292d

Browse files
committed
refactor: a nicer way to inject config from the environment
1 parent 183cd9b commit 0eb292d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

coverage/control.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def override_config(cov: Coverage, **kwargs: TConfigValueIn) -> Iterator[None]:
8989

9090
DEFAULT_DATAFILE = DefaultValue("MISSING")
9191
_DEFAULT_DATAFILE = DEFAULT_DATAFILE # Just in case, for backwards compatibility
92-
CONFIG_FROM_ENVIRONMENT = ":envvar:"
92+
CONFIG_DATA_PREFIX = ":data:"
9393

9494
class Coverage(TConfigurable):
9595
"""Programmatic access to coverage.py.
@@ -317,8 +317,8 @@ def __init__( # pylint: disable=too-many-arguments
317317
self._should_write_debug = True
318318

319319
# Build our configuration from a number of sources.
320-
if config_file == CONFIG_FROM_ENVIRONMENT:
321-
self.config = deserialize_config(cast(str, os.getenv("COVERAGE_PROCESS_CONFIG")))
320+
if isinstance(config_file, str) and config_file.startswith(CONFIG_DATA_PREFIX):
321+
self.config = deserialize_config(config_file[len(CONFIG_DATA_PREFIX):])
322322
else:
323323
if not isinstance(config_file, bool):
324324
config_file = os.fspath(config_file)
@@ -1426,7 +1426,7 @@ def process_startup() -> Coverage | None:
14261426
config_data = os.getenv("COVERAGE_PROCESS_CONFIG")
14271427
cps = os.getenv("COVERAGE_PROCESS_START")
14281428
if config_data is not None:
1429-
config_file = CONFIG_FROM_ENVIRONMENT
1429+
config_file = CONFIG_DATA_PREFIX + config_data
14301430
elif cps is not None:
14311431
config_file = cps
14321432
else:

0 commit comments

Comments
 (0)