diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d709a4..d0333a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.rst b/README.rst index 7ca36e7..a0be894 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/docs/source/conf.py b/docs/source/conf.py index 3c27b40..8686d32 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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 --------------------------------------------------- diff --git a/pystackql/base_stackql_magic.py b/pystackql/base_stackql_magic.py index 697aa6f..66636d4 100644 --- a/pystackql/base_stackql_magic.py +++ b/pystackql/base_stackql_magic.py @@ -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): @@ -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 \ No newline at end of file diff --git a/pystackql/magic.py b/pystackql/magic.py index db4fd72..13f7432 100644 --- a/pystackql/magic.py +++ b/pystackql/magic.py @@ -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) diff --git a/pystackql/magics.py b/pystackql/magics.py index bfd48e0..6d69b68 100644 --- a/pystackql/magics.py +++ b/pystackql/magics.py @@ -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) \ No newline at end of file diff --git a/setup.py b/setup.py index 884f78b..153ae3e 100644 --- a/setup.py +++ b/setup.py @@ -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',