Skip to content

Instantly share code, notes, and snippets.

@chr15m
Last active August 29, 2015 14:26
Show Gist options
  • Save chr15m/41ff6e25189190bcec4f to your computer and use it in GitHub Desktop.
Save chr15m/41ff6e25189190bcec4f to your computer and use it in GitHub Desktop.
Hy REPL in Django
  • Make sure you've installed hy or put it in requirements.txt
  • Put hy.py in management/commands/hy.py
  ./manage.py hy
  hy 0.11.0 using CPython(default) 2.7.6 on Linux
  => (import [yourapp [settings]])
  => settings.DEBUG
  True

You can also run a hy script in the Django context like this:

./manage.py hy test.hy

#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'hy==0.11.0','console_scripts','hy'
__requires__ = 'hy==0.11.0'
import sys
from pkg_resources import load_entry_point
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = "Runs an arbitrary module, in the Django environment, for quick prototyping of code that's too big for the shell."
def handle(self, *args, **options):
# remove this module from the arguments
sys.argv[1] == "hy" and sys.argv.pop(1)
sys.exit(
load_entry_point('hy==0.11.0', 'console_scripts', 'hy')()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment