Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.2.2 magic updates #26

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# Changelog

## v3.2.1 (2023-10-18)

* implemented non `server_mode` magic extension

### Updates

* `pandas` type fixes

## v3.1.2 (2023-10-16)

### Updates

* `pandas` type fixes

## v3.1.1 (2023-10-14)
## v3.2.2 (2023-10-18)

### Updates

* implemented non `server_mode` magic extension
* `pandas` type updates
* updated class parameters
* added additional tests

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ To publish the package to PyPI, run the following command:

::

twine upload dist/pystackql-3.2.1.tar.gz
twine upload dist/pystackql-3.2.2.tar.gz
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '3.2.1'
release = '3.2.2'


# -- General configuration ---------------------------------------------------
Expand Down
35 changes: 1 addition & 34 deletions pystackql/base_stackql_magic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import print_function
import pandas as pd
import json, argparse
from IPython.core.magic import (Magics, line_cell_magic)
from IPython.core.magic import (Magics)
from string import Template

class BaseStackqlMagic(Magics):
Expand Down Expand Up @@ -40,34 +38,3 @@ def run_query(self, query):
:rtype: pandas.DataFrame
"""
return self.stackql_instance.execute(query)

@line_cell_magic
def stackql(self, line, cell=None):
"""A Jupyter magic command to run StackQL queries.

Can be used as both line and cell magic:
- As a line magic: `%stackql QUERY`
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.

:param line: The arguments and/or StackQL query when used as line magic.
:param cell: The StackQL query when used as cell magic.
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
"""
is_cell_magic = cell is not None

if is_cell_magic:
parser = argparse.ArgumentParser()
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
args = parser.parse_args(line.split())
query_to_run = self.get_rendered_query(cell)
else:
args = None
query_to_run = self.get_rendered_query(line)

results = self.run_query(query_to_run)
self.shell.user_ns['stackql_df'] = results

if is_cell_magic and args and not args.no_display:
return results
elif not is_cell_magic:
return results
34 changes: 33 additions & 1 deletion pystackql/magic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
# `%load_ext pystackql.magic` - loads the stackql magic with server_mode=False
from IPython.core.magic import magics_class
from IPython.core.magic import (magics_class, line_cell_magic)
from .base_stackql_magic import BaseStackqlMagic
import argparse

@magics_class
class StackqlMagic(BaseStackqlMagic):
def __init__(self, shell):
super().__init__(shell, server_mode=False)

@line_cell_magic
def stackql(self, line, cell=None):
"""A Jupyter magic command to run StackQL queries.

Can be used as both line and cell magic:
- As a line magic: `%stackql QUERY`
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.

:param line: The arguments and/or StackQL query when used as line magic.
:param cell: The StackQL query when used as cell magic.
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
"""
is_cell_magic = cell is not None

if is_cell_magic:
parser = argparse.ArgumentParser()
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
args = parser.parse_args(line.split())
query_to_run = self.get_rendered_query(cell)
else:
args = None
query_to_run = self.get_rendered_query(line)

results = self.run_query(query_to_run)
self.shell.user_ns['stackql_df'] = results

if is_cell_magic and args and not args.no_display:
return results
elif not is_cell_magic:
return results

def load_ipython_extension(ipython):
"""Load the non-server magic in IPython."""
ipython.register_magics(StackqlMagic)
34 changes: 33 additions & 1 deletion pystackql/magics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
# `%load_ext pystackql.magics` - loads the stackql magic with server_mode=True
from IPython.core.magic import magics_class
from IPython.core.magic import (magics_class, line_cell_magic)
from .base_stackql_magic import BaseStackqlMagic
import argparse

@magics_class
class StackqlServerMagic(BaseStackqlMagic):
def __init__(self, shell):
super().__init__(shell, server_mode=True)

@line_cell_magic
def stackql(self, line, cell=None):
"""A Jupyter magic command to run StackQL queries.

Can be used as both line and cell magic:
- As a line magic: `%stackql QUERY`
- As a cell magic: `%%stackql [OPTIONS]` followed by the QUERY in the next line.

:param line: The arguments and/or StackQL query when used as line magic.
:param cell: The StackQL query when used as cell magic.
:return: StackQL query results as a named Pandas DataFrame (`stackql_df`).
"""
is_cell_magic = cell is not None

if is_cell_magic:
parser = argparse.ArgumentParser()
parser.add_argument("--no-display", action="store_true", help="Suppress result display.")
args = parser.parse_args(line.split())
query_to_run = self.get_rendered_query(cell)
else:
args = None
query_to_run = self.get_rendered_query(line)

results = self.run_query(query_to_run)
self.shell.user_ns['stackql_df'] = results

if is_cell_magic and args and not args.no_display:
return results
elif not is_cell_magic:
return results

def load_ipython_extension(ipython):
"""Load the extension in IPython."""
ipython.register_magics(StackqlServerMagic)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='pystackql',
version='3.2.1',
version='3.2.2',
description='A Python interface for StackQL',
long_description=readme,
author='Jeffrey Aven',
Expand Down