Skip to content

Commit a7a689b

Browse files
authored
Merge pull request #26 from stackql/feature/refactor
v3.2.2 magic updates
2 parents b65e667 + bef7396 commit a7a689b

File tree

7 files changed

+73
-54
lines changed

7 files changed

+73
-54
lines changed

CHANGELOG.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# Changelog
22

3-
## v3.2.1 (2023-10-18)
4-
5-
* implemented non `server_mode` magic extension
6-
7-
### Updates
8-
9-
* `pandas` type fixes
10-
11-
## v3.1.2 (2023-10-16)
12-
13-
### Updates
14-
15-
* `pandas` type fixes
16-
17-
## v3.1.1 (2023-10-14)
3+
## v3.2.2 (2023-10-18)
184

195
### Updates
206

7+
* implemented non `server_mode` magic extension
8+
* `pandas` type updates
219
* updated class parameters
2210
* added additional tests
2311

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ To publish the package to PyPI, run the following command:
193193

194194
::
195195

196-
twine upload dist/pystackql-3.2.1.tar.gz
196+
twine upload dist/pystackql-3.2.2.tar.gz

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# The short X.Y version
2727
version = ''
2828
# The full version, including alpha/beta/rc tags
29-
release = '3.2.1'
29+
release = '3.2.2'
3030

3131

3232
# -- General configuration ---------------------------------------------------

pystackql/base_stackql_magic.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import print_function
2-
import pandas as pd
3-
import json, argparse
4-
from IPython.core.magic import (Magics, line_cell_magic)
2+
from IPython.core.magic import (Magics)
53
from string import Template
64

75
class BaseStackqlMagic(Magics):
@@ -40,34 +38,3 @@ def run_query(self, query):
4038
:rtype: pandas.DataFrame
4139
"""
4240
return self.stackql_instance.execute(query)
43-
44-
@line_cell_magic
45-
def stackql(self, line, cell=None):
46-
"""A Jupyter magic command to run StackQL queries.
47-
48-
Can be used as both line and cell magic:
49-
- As a line magic: `%stackql QUERY`
50-
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.
51-
52-
:param line: The arguments and/or StackQL query when used as line magic.
53-
:param cell: The StackQL query when used as cell magic.
54-
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
55-
"""
56-
is_cell_magic = cell is not None
57-
58-
if is_cell_magic:
59-
parser = argparse.ArgumentParser()
60-
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
61-
args = parser.parse_args(line.split())
62-
query_to_run = self.get_rendered_query(cell)
63-
else:
64-
args = None
65-
query_to_run = self.get_rendered_query(line)
66-
67-
results = self.run_query(query_to_run)
68-
self.shell.user_ns['stackql_df'] = results
69-
70-
if is_cell_magic and args and not args.no_display:
71-
return results
72-
elif not is_cell_magic:
73-
return results

pystackql/magic.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
# `%load_ext pystackql.magic` - loads the stackql magic with server_mode=False
2-
from IPython.core.magic import magics_class
2+
from IPython.core.magic import (magics_class, line_cell_magic)
33
from .base_stackql_magic import BaseStackqlMagic
4+
import argparse
45

56
@magics_class
67
class StackqlMagic(BaseStackqlMagic):
78
def __init__(self, shell):
89
super().__init__(shell, server_mode=False)
910

11+
@line_cell_magic
12+
def stackql(self, line, cell=None):
13+
"""A Jupyter magic command to run StackQL queries.
14+
15+
Can be used as both line and cell magic:
16+
- As a line magic: `%stackql QUERY`
17+
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.
18+
19+
:param line: The arguments and/or StackQL query when used as line magic.
20+
:param cell: The StackQL query when used as cell magic.
21+
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
22+
"""
23+
is_cell_magic = cell is not None
24+
25+
if is_cell_magic:
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
28+
args = parser.parse_args(line.split())
29+
query_to_run = self.get_rendered_query(cell)
30+
else:
31+
args = None
32+
query_to_run = self.get_rendered_query(line)
33+
34+
results = self.run_query(query_to_run)
35+
self.shell.user_ns['stackql_df'] = results
36+
37+
if is_cell_magic and args and not args.no_display:
38+
return results
39+
elif not is_cell_magic:
40+
return results
41+
1042
def load_ipython_extension(ipython):
1143
"""Load the non-server magic in IPython."""
1244
ipython.register_magics(StackqlMagic)

pystackql/magics.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
# `%load_ext pystackql.magics` - loads the stackql magic with server_mode=True
2-
from IPython.core.magic import magics_class
2+
from IPython.core.magic import (magics_class, line_cell_magic)
33
from .base_stackql_magic import BaseStackqlMagic
4+
import argparse
45

56
@magics_class
67
class StackqlServerMagic(BaseStackqlMagic):
78
def __init__(self, shell):
89
super().__init__(shell, server_mode=True)
910

11+
@line_cell_magic
12+
def stackql(self, line, cell=None):
13+
"""A Jupyter magic command to run StackQL queries.
14+
15+
Can be used as both line and cell magic:
16+
- As a line magic: `%stackql QUERY`
17+
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.
18+
19+
:param line: The arguments and/or StackQL query when used as line magic.
20+
:param cell: The StackQL query when used as cell magic.
21+
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
22+
"""
23+
is_cell_magic = cell is not None
24+
25+
if is_cell_magic:
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
28+
args = parser.parse_args(line.split())
29+
query_to_run = self.get_rendered_query(cell)
30+
else:
31+
args = None
32+
query_to_run = self.get_rendered_query(line)
33+
34+
results = self.run_query(query_to_run)
35+
self.shell.user_ns['stackql_df'] = results
36+
37+
if is_cell_magic and args and not args.no_display:
38+
return results
39+
elif not is_cell_magic:
40+
return results
41+
1042
def load_ipython_extension(ipython):
1143
"""Load the extension in IPython."""
1244
ipython.register_magics(StackqlServerMagic)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='pystackql',
13-
version='3.2.1',
13+
version='3.2.2',
1414
description='A Python interface for StackQL',
1515
long_description=readme,
1616
author='Jeffrey Aven',

0 commit comments

Comments
 (0)