From 2af0ecfcf59b535e804778110bd17db02cf7f138 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 18 Apr 2026 14:36:09 -0400 Subject: [PATCH] remove non-working Jupyter magic.py This file has not been touched substantively in a few years, is not documented, and no longer works. If these missing dependencies are added to pyproject.toml: * ipython-sql * sql Then the user can do the following in a notebook/console started from the mycli repo root: In [1]: %load_ext sql In [2]: %load_ext mycli.magic In [3]: %sql mysql+pymysql://mycli:password@localhost:3306/mysql However, upon executing a query with the magic In [4]: %mycli show tables we find that magic.py has mycli: MyCli = conn._mycli but mycli has long since been refactored, such that AttributeError: 'Connection' object has no attribute '_mycli' and it throws similarly for u = conn.session.engine.url Given that this is not working, not maintained, and not documented, we should be comfortable deleting it without a deprecation cycle. In the future, if this functionality is desired, it should probably be implemented in a separate library which takes mycli as a dependency. That way it could be more discoverable on PyPi, and could declare additional dependencies needed only in the notebook context. --- changelog.md | 5 ++++ mycli/magic.py | 66 -------------------------------------------------- 2 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 mycli/magic.py diff --git a/changelog.md b/changelog.md index 32b3878b..fecc97bf 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,11 @@ Upcoming (TBD) ============== +Features +--------- +* Remove undocumented `%mycli` Jupyter magic. + + Bug Fixes --------- * Make LLM timings use the same format as other timings. diff --git a/mycli/magic.py b/mycli/magic.py deleted file mode 100644 index d1d3957b..00000000 --- a/mycli/magic.py +++ /dev/null @@ -1,66 +0,0 @@ -import logging -from typing import Any - -import sql.connection -import sql.parse - -from mycli.main import MyCli, Query - -_logger: logging.Logger = logging.getLogger(__name__) - - -def load_ipython_extension(ipython) -> None: - # This is called via the ipython command '%load_ext mycli.magic'. - - # First, load the sql magic if it isn't already loaded. - if not ipython.find_line_magic("sql"): - ipython.run_line_magic("load_ext", "sql") - - # Register our own magic. - ipython.register_magic_function(mycli_line_magic, "line", "mycli") - - -def mycli_line_magic(line: str): - _logger.debug("mycli magic called: %r", line) - parsed: dict[str, Any] = sql.parse.parse(line, {}) - # "get" was renamed to "set" in ipython-sql: - # https://github.com/catherinedevlin/ipython-sql/commit/f4283c65aaf68f961e84019e8b939e4a3c501d43 - if hasattr(sql.connection.Connection, "get"): - conn = sql.connection.Connection.get(parsed["connection"]) - else: - try: - conn = sql.connection.Connection.set(parsed["connection"]) - # a new positional argument was added to Connection.set in version 0.4.0 of ipython-sql - except TypeError: - conn = sql.connection.Connection.set(parsed["connection"], False) - try: - # A corresponding mycli object already exists - mycli: MyCli = conn._mycli - _logger.debug("Reusing existing mycli") - except AttributeError: - mycli = MyCli() - u = conn.session.engine.url - _logger.debug("New mycli: %r", str(u)) - - mycli.connect(host=u.host, port=u.port, passwd=u.password, database=u.database, user=u.username, init_command=None) - conn._mycli = mycli - - # For convenience, print the connection alias - print(f'Connected: {conn.name}') - - try: - mycli.run_cli() - except SystemExit: - pass - - if not mycli.query_history: - return - - q: Query = mycli.query_history[-1] - if q.mutating: - _logger.debug("Mutating query detected -- ignoring") - return - - if q.successful: - ipython = get_ipython() # type: ignore # noqa: F821 - return ipython.run_cell_magic("sql", line, q.query)