Skip to content

Commit

Permalink
Syntax hilighting
Browse files Browse the repository at this point in the history
  • Loading branch information
alope107 committed Jul 15, 2015
1 parent 3d3357b commit 34b4d86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.pyc
examples/.ipynb_checkpoints/
sparksql.egg-info/
12 changes: 11 additions & 1 deletion examples/Spark SQL Magic Demo.ipynb
Expand Up @@ -36,7 +36,17 @@
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"data": {
"application/javascript": [
"IPython.CodeCell.config_defaults.highlight_modes['magic_text/x-sql'] = {'reg':[/^%%sparksql/]};"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%load_ext sparksql"
]
Expand Down
8 changes: 6 additions & 2 deletions src/sparksql/magic.py
Expand Up @@ -8,19 +8,21 @@
import sqlparse
from fillPlaceholder import replace
from fileManip import load_file, write_file
from IPython.core.display import display_javascript

@magics_class
class SparkSqlMagic(Magics):
"""Runs SQL statement through Spark using provided SQLContext.
Provides the %sparksql magic.
"""


def __init__(self, shell):
Magics.__init__(self, shell=shell)
self.context = None
self.user_ns = None


#TODO fix help doc, currently has execute shown for usage
#TODO support for custom data sources
@magic_arguments()
Expand Down Expand Up @@ -121,4 +123,6 @@ def find_insts(self, namespace, to_find):
return {k:v for k, v in namespace.iteritems() if isinstance(v, to_find)}

def load_ipython_extension(ip):
ip.register_magics(SparkSqlMagic)
js = "IPython.CodeCell.config_defaults.highlight_modes['magic_text/x-sql'] = {'reg':[/^%%sparksql/]};"
display_javascript(js, raw=True)
ip.register_magics(SparkSqlMagic)

0 comments on commit 34b4d86

Please sign in to comment.