Skip to content

Commit

Permalink
feat(configuration): Add core.configuration.extra to include addition…
Browse files Browse the repository at this point in the history
…al configuration files

Close #123
  • Loading branch information
Toilal committed Dec 11, 2020
1 parent 50be41d commit b7d30de
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ History
1.2.4 (unreleased)
------------------

- JSonnet: Add XDebug Version 3 support.
- Jsonnet: Add XDebug Version 3 support.
- Configuration: Add `core.configuration.extra` to load additional configuration files.

1.2.3 (2020-11-13)
------------------
Expand Down
5 changes: 4 additions & 1 deletion ddb/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def files(self):
continue
for basename in self.filenames:
for ext in self.extensions:
file = os.path.join(path, basename + '.' + ext)
if basename.endswith('.' + ext) and os.path.exists(os.path.join(path, basename)):
file = os.path.join(path, basename)
else:
file = os.path.join(path, basename + '.' + ext)
ret.append(file)
return ret

Expand Down
7 changes: 6 additions & 1 deletion ddb/feature/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def _load_environment_configuration(self):
current = config.data.get('core.env.current')

filenames = list(config.filenames)
filenames.insert(1, filenames[0] + '.' + current)
filenames.insert(len(filenames) - 1, filenames[0] + '.' + current)

extra = config.data.get('core.configuration.extra')
if extra:
for extra_item in extra:
filenames.insert(len(filenames) - 1, extra_item)

config.clear()
config.filenames = tuple(filenames)
Expand Down
8 changes: 8 additions & 0 deletions ddb/feature/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class ProcessSchema(Schema):
append = fields.Raw(required=False, allow_none=True, default=None) # List[str] or str splitted with shlex


class ConfigurationSchema(Schema):
"""
Process settings for core feature schema.
"""
extra = fields.List(fields.String(), required=False)


class CoreFeatureSchema(FeatureSchema):
"""
Core feature schema.
Expand All @@ -57,3 +64,4 @@ class CoreFeatureSchema(FeatureSchema):
os = fields.String(required=True, default=os.name)
path = fields.Nested(PathSchema(), default=PathSchema())
process = fields.Dict(fields.String(), fields.Nested(ProcessSchema()), default={}) # Process binary mappings
configuration = fields.Nested(ConfigurationSchema(), default=ConfigurationSchema())
15 changes: 14 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ configuration settings, please check the documentation of related feature.

When activating the environment `$(ddb activate)` with [shell feature (Environment activation)](#environment-activation),
the whole configuration is also exported as environment variables using the same naming convention.


!!! info "Extra configuration files"
You may add additional configuration files using core.configuration.extra_files configuration property into default
configuration files.

```yml
core:
configuration:
extra: ['ddb.custom.yml']
```

This will load `ddb.custom.yml` configuration file from each supported configuration directories. `ddb.local.yml`
still has the priority other those extra configuration files.

!!! abstract "Default configuration"
```ddb config``` can provide default configuration if `ddb.yml` configuration file is empty.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
another: true
app:
value: config
2 changes: 2 additions & 0 deletions tests/it/test_config_it.data/extra-filenames/ddb.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app:
value: local
5 changes: 5 additions & 0 deletions tests/it/test_config_it.data/extra-filenames/ddb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
core:
configuration:
extra: [ 'some.custom.yml', 'another.config.file' ]
app:
value: default
3 changes: 3 additions & 0 deletions tests/it/test_config_it.data/extra-filenames/some.custom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
some: true
app:
value: custom
11 changes: 11 additions & 0 deletions tests/it/test_config_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ def test_config_env_ddb2(self, project_loader):
assert not os.path.islink("ddb.yml")

reset()

def test_config_extra_filenames(self, project_loader):
project_loader("extra-filenames")

main(["configure"], reset_disabled=True)

assert config.data.get('another') is True
assert config.data.get('some') is True
assert config.data.get('app.value') == 'local'

reset()

0 comments on commit b7d30de

Please sign in to comment.