Skip to content

Commit

Permalink
Rename context import from_file -> from_path
Browse files Browse the repository at this point in the history
This makes folder path imports non-breakable in the future.
  • Loading branch information
JakobGM committed Feb 17, 2018
1 parent 0450fe2 commit e24e6c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion astrality/config/astrality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module/solar_wallpaper:
# e.g. `night`, into the global context section named `colors`,
# from the file: wallpaper_themes/default/colors.yaml.
import_context:
- from_file: modules/solar_wallpaper/solar_colors.yaml
- from_path: modules/solar_wallpaper/solar_colors.yaml
from_section: '{period}'
to_section: colors

Expand Down
4 changes: 2 additions & 2 deletions astrality/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def context_section_imports(

for context_import in import_config:
# Insert placeholders
from_file = self.interpolate_string(context_import['from_file'])
from_path = self.interpolate_string(context_import['from_path'])

from_section: Optional[str]
to_section: Optional[str]
Expand All @@ -320,7 +320,7 @@ def context_section_imports(
to_section = None

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

# Isert a ContextSectionImport tuple into the return value
context_section_imports.append(
Expand Down
2 changes: 1 addition & 1 deletion astrality/tests/module/test_context_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_importing_all_context_sections_from_file(
'module/A': {
'on_startup': {
'import_context': [
{'from_file': str(context_file)}
{'from_path': str(context_file)}
]
},
},
Expand Down
12 changes: 6 additions & 6 deletions astrality/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ 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'] = [{
'to_section': 'week',
'from_file': 'astrality/tests/templates/weekday.yaml',
'from_path': 'astrality/tests/templates/weekday.yaml',
'from_section': '{period}',
}]
config_with_modules.pop('module/solar_module')
Expand Down Expand Up @@ -679,14 +679,14 @@ def test_import_sections_on_startup(config_with_modules, freezer):
# Insert day the module was started into 'start day'
config_with_modules['module/weekday_module']['on_startup']['import_context'] = [{
'to_section': 'start_day',
'from_file': 'astrality/tests/templates/weekday.yaml',
'from_path': 'astrality/tests/templates/weekday.yaml',
'from_section': '{period}',
}]

# Insert the current day into 'day_now'
config_with_modules['module/weekday_module']['on_period_change']['import_context'] = [{
'to_section': 'day_now',
'from_file': 'astrality/tests/templates/weekday.yaml',
'from_path': 'astrality/tests/templates/weekday.yaml',
'from_section': '{period}',
}]
config_with_modules.pop('module/solar_module')
Expand Down Expand Up @@ -724,7 +724,7 @@ def test_context_section_imports(folders):
'on_startup': {
'import_context': [
{
'from_file': '/testfile',
'from_path': '/testfile',
'from_section': 'source_section',
'to_section': 'target_section',
}
Expand All @@ -733,7 +733,7 @@ def test_context_section_imports(folders):
'on_period_change': {
'import_context': [
{
'from_file': '/testfile',
'from_path': '/testfile',
'from_section': 'source_section',
}
]
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def test_trigger_event_module_action(conf_path, default_global_options):
'on_period_change': {
'run': ['echo period_change'],
'import_context': [{
'from_file': 'contexts/file.yaml',
'from_path': 'contexts/file.yaml',
'from_section': 'section',
}],
},
Expand Down
14 changes: 7 additions & 7 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Then let us import the gruvbox color scheme into the "colors" :ref:`context <con
module/color_scheme:
on_startup:
import_context:
- from_file: contexts/color_schemes.yaml
- from_path: contexts/color_schemes.yaml
from_section: gruvbox_dark
to_section: colors
Expand All @@ -239,13 +239,13 @@ This is functionally equivalent to writing:

The available attributes for ``import_context`` are:

``from_file``:
``from_path``:
A YAML formatted file containing :ref:`context sections <context>`.

``from_section``: *[Optional]*
Which context section to import from the file specified in ``from_file``.
Which context section to import from the file specified in ``from_path``.

If none is specified, all sections defined in ``from_file`` will be
If none is specified, all sections defined in ``from_path`` will be
imported.

``to_section``: *[Optional]*
Expand Down Expand Up @@ -360,7 +360,7 @@ An example of a module using ``trigger`` actions:
on_period_change:
import_context:
- from_file: contexts/A.yaml
- from_path: contexts/A.yaml
from_section: '{period}'
to_section: a_stuff
trigger: on_modified.templateA
Expand All @@ -386,7 +386,7 @@ This is equivalent to writing the following module:
on_startup:
import_context:
- from_file: contexts/A.yaml
- from_path: contexts/A.yaml
from_section: '{period}'
to_section: a_stuff
compile:
Expand All @@ -397,7 +397,7 @@ This is equivalent to writing the following module:
on_period_change:
import_context:
- from_file: contexts/A.yaml
- from_path: contexts/A.yaml
from_section: '{period}'
to_section: a_stuff
compile:
Expand Down

0 comments on commit e24e6c2

Please sign in to comment.