Skip to content

Commit

Permalink
Use dicts to represent context imports
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed Feb 7, 2018
1 parent 09f1e3f commit d10f586
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion astrality/config/astrality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ module/wallpaper:
run:
- feh --bg-fill wallpaper_themes/default/{period}.*
import_context:
- colors wallpaper_themes/default/colors.yaml {period}
- from_file: wallpaper_themes/default/colors.yaml
from_section: '{period}'
to_section: colors

on_exit:
run:
Expand Down
13 changes: 6 additions & 7 deletions astrality/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,19 @@ def context_section_imports(self) -> Tuple[ContextSectionImport, ...]:
{},
).get('import_context', [])

for command in import_config:
for context_import in import_config:
# Insert placeholders
command = self.interpolate_string(command)

# Split string into its defined components
into_section, path, from_section = command.split(' ')
from_file = self.interpolate_string(context_import['from_file'])
from_section = self.interpolate_string(context_import['from_section'])
to_section = self.interpolate_string(context_import['to_section'])

# Get the absolute path
config_path = self.expand_path(Path(path))
config_path = self.expand_path(Path(from_file))

# Isert a ContextSectionImport tuple into the return value
context_section_imports.append(
ContextSectionImport(
into_section=into_section,
into_section=to_section,
from_section=from_section,
from_config_file=config_path,
)
Expand Down
7 changes: 5 additions & 2 deletions astrality/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,11 @@ def module_manager(config_with_modules):


def test_import_sections_on_period_change(config_with_modules, freezer):
config_with_modules['module/weekday_module']['on_period_change']['import_context'] = \
['week astrality/tests/templates/weekday.yaml {period}']
config_with_modules['module/weekday_module']['on_period_change']['import_context'] = [{
'to_section': 'week',
'from_file': 'astrality/tests/templates/weekday.yaml',
'from_section': '{period}',
}]
module_manager = ModuleManager(config_with_modules)

assert 'env' in module_manager.application_context
Expand Down

0 comments on commit d10f586

Please sign in to comment.