Skip to content

Commit e39a567

Browse files
authored
Merge pull request #437 from dipdup-net/fix/commented-config-lines
Stop processing commented config lines
2 parents dfb4ed5 + d9625ca commit e39a567

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog],
66
and this project adheres to [Semantic Versioning].
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- config: Do not perform env variable substitution in commented out lines.
13+
814
## [6.0.0-rc1] - 2022-07-26
915

1016
### Added

src/dipdup/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,14 @@ def _load_raw_config(cls, path: str) -> str:
13911391
_logger.debug('Loading config from %s', path)
13921392
try:
13931393
with open(path) as file:
1394-
return file.read()
1394+
return ''.join(filter(cls._filter_commented_lines, file.readlines()))
13951395
except OSError as e:
13961396
raise ConfigurationError(str(e)) from e
13971397

1398+
@classmethod
1399+
def _filter_commented_lines(cls, line: str) -> bool:
1400+
return '#' not in line or line.lstrip()[0] != '#'
1401+
13981402
@classmethod
13991403
def _substitute_env_variables(cls, raw_config: str) -> Tuple[str, Dict[str, str]]:
14001404
_logger.debug('Substituting environment variables')

tests/test_dipdup/test_config/test_custom_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,17 @@ def test_env_parsing_negative(self, value, dummy_config_path, tmp_path_factory)
111111
assert exc.args[0] == 'Environment variable `DEFINITELY_NOT_DEFINED` is not set'
112112
else:
113113
raise AssertionError('ConfigurationError not raised')
114+
115+
@pytest.mark.parametrize(
116+
'value',
117+
(
118+
'${DEFINITELY_NOT_DEFINED}',
119+
'${DEFINITELY_NOT_DEFINED:-}',
120+
),
121+
)
122+
def test_skip_commented_variables(self, value, dummy_config_path, tmp_path_factory) -> None:
123+
append_raw = f"""
124+
# some commented line corresponding to ENV_VARIABLE_REGEX with {value}
125+
"""
126+
config_path = self.appended_config_path(dummy_config_path, tmp_path_factory, append_raw)
127+
DipDupConfig.load([config_path], True)

0 commit comments

Comments
 (0)