Skip to content

Commit

Permalink
Add support for short YAML file extension (#8)
Browse files Browse the repository at this point in the history
When I tried out Slippers it didn't work initially because
I had created a "components.yml" file instead of "components.yaml".
I didn't see the system check message either because the
log statements already moved it too far up the terminal.

I'm not sure what suffix is more widely used but, for example,
Docker Compose refers its config as "docker-compose.yml" while
suporting both file endings:

> The Compose file is a YAML file defining services, networks and
> volumes. The default path for a Compose file is ./docker-compose.yml.
>
> Tip: You can use either a .yml or .yaml extension for this file.
> They both work.
  • Loading branch information
jnns committed Oct 24, 2021
1 parent 845b6e2 commit fd67e29
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions slippers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
from django.apps import AppConfig
from django.core.checks import Warning, register
from django.template.exceptions import TemplateDoesNotExist
from django.template.loader import get_template
from django.template.loader import select_template
from django.utils.autoreload import autoreload_started, file_changed

import yaml

from slippers.templatetags.slippers import register_components


def get_components_yaml():
return select_template(["components.yaml", "components.yml"])


def register_tags():
"""Register tags from components.yaml"""
try:
template = get_template("components.yaml")
template = get_components_yaml()
components = yaml.safe_load(template.template.source)
register_components(components.get("components", {}))
except TemplateDoesNotExist:
Expand All @@ -24,7 +28,7 @@ def register_tags():
def watch(sender, **kwargs):
"""Watch when component.yaml changes"""
try:
template = get_template("components.yaml")
template = get_components_yaml()
sender.extra_files.add(Path(template.origin.name))
except TemplateDoesNotExist:
pass
Expand All @@ -40,7 +44,7 @@ def changed(sender, file_path: PosixPath, **kwargs):
def checks(app_configs, **kwargs):
"""Warn if unable to find components.yaml"""
try:
get_template("components.yaml")
get_components_yaml()
except TemplateDoesNotExist:
return [
Warning(
Expand Down

0 comments on commit fd67e29

Please sign in to comment.