Skip to content

Commit

Permalink
🐛 v2.2.1 Minor bugfixes. (#157)
Browse files Browse the repository at this point in the history
# v2.2.1

- **Fix `--schedule` in the interactive shell.**  
  The `--schedule` flag may now be used from both the CLI and the Shell.

- **Fix the `SQLConnector` CLI.**  
  The `sql` action now correctly opens an interactive CLI.

- **Bumped `duckdb` to `>=1.0.0`.**  
  The upstream breaking changes that required `duckdb` to be held back have to do with how indices behave. For now, index creation has been disabled so that `duckdb` may be upgraded to 1.0+.
  • Loading branch information
bmeares authored Jun 7, 2024
1 parent b2e1c06 commit 9a62f98
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

This is the current release cycle, so stay tuned for future releases!

### v2.2.1

- **Fix `--schedule` in the interactive shell.**
The `--schedule` flag may now be used from both the CLI and the Shell.

- **Fix the `SQLConnector` CLI.**
The `sql` action now correctly opens an interactive CLI.

- **Bumped `duckdb` to `>=1.0.0`.**
The upstream breaking changes that required `duckdb` to be held back have to do with how indices behave. For now, index creation has been disabled so that `duckdb` may be upgraded to 1.0+.

### v2.2.0

**New Features**
Expand Down
11 changes: 11 additions & 0 deletions docs/mkdocs/news/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

This is the current release cycle, so stay tuned for future releases!

### v2.2.1

- **Fix `--schedule` in the interactive shell.**
The `--schedule` flag may now be used from both the CLI and the Shell.

- **Fix the `SQLConnector` CLI.**
The `sql` action now correctly opens an interactive CLI.

- **Bumped `duckdb` to `>=1.0.0`.**
The upstream breaking changes that required `duckdb` to be held back have to do with how indices behave. For now, index creation has been disabled so that `duckdb` may be upgraded to 1.0+.

### v2.2.0

**New Features**
Expand Down
47 changes: 36 additions & 11 deletions meerschaum/_internal/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def entry(sysargs: Optional[List[str]] = None) -> SuccessTuple:
)
)

if args.get('schedule', None):
from meerschaum.utils.schedule import schedule_function
return schedule_function(entry_with_args, **args)
# if args.get('schedule', None):
# from meerschaum.utils.schedule import schedule_function
# return schedule_function(entry_with_args, **args)
return entry_with_args(**args)


Expand All @@ -61,7 +61,7 @@ def entry_with_args(
Use `_entry()` for parsing sysargs before executing.
"""
import sys
from meerschaum.plugins import Plugin
import functools
from meerschaum.actions import get_action, get_main_action_name
from meerschaum._internal.arguments import remove_leading_action
from meerschaum.utils.venv import Venv, active_venvs, deactivate_venv
Expand All @@ -88,10 +88,41 @@ def entry_with_args(
action_function.__module__.startswith('plugins.')
) else None
)
plugin = Plugin(plugin_name) if plugin_name else None

skip_schedule = False
if (
kw['action']
and kw['action'][0] == 'start'
and kw['action'][1] in ('job', 'jobs')
):
skip_schedule = True

kw['action'] = remove_leading_action(kw['action'], _actions=_actions)

do_action = functools.partial(_do_action_wrapper, action_function, plugin_name, **kw)
if kw.get('schedule', None) and not skip_schedule:
from meerschaum.utils.schedule import schedule_function
from meerschaum.utils.misc import interval_str
import time
from datetime import timedelta
start_time = time.perf_counter()
schedule_function(do_action, **kw)
delta = timedelta(seconds=(time.perf_counter() - start_time))
result = True, f"Exited scheduler after {interval_str(delta)}."
else:
result = do_action()

### Clean up stray virtual environments.
for venv in [venv for venv in active_venvs]:
deactivate_venv(venv, debug=kw.get('debug', False), force=True)

return result


def _do_action_wrapper(action_function, plugin_name, **kw):
from meerschaum.plugins import Plugin
from meerschaum.utils.venv import Venv, active_venvs, deactivate_venv
plugin = Plugin(plugin_name) if plugin_name else None
with Venv(plugin, debug=kw.get('debug', False)):
action_name = ' '.join(action_function.__name__.split('_') + kw.get('action', []))
try:
Expand All @@ -111,14 +142,8 @@ def entry_with_args(
)
except KeyboardInterrupt:
result = False, f"Cancelled action `{action_name}`."

### Clean up stray virtual environments.
for venv in [venv for venv in active_venvs]:
deactivate_venv(venv, debug=kw.get('debug', False), force=True)

return result


_shells = []
_shell = None
def get_shell(
Expand Down
2 changes: 1 addition & 1 deletion meerschaum/config/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Specify the Meerschaum release version.
"""

__version__ = "2.2.0"
__version__ = "2.2.1"
9 changes: 8 additions & 1 deletion meerschaum/connectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
from meerschaum.connectors.api.APIConnector import APIConnector
from meerschaum.connectors.sql._create_engine import flavor_configs as sql_flavor_configs

__all__ = ("Connector", "SQLConnector", "APIConnector", "get_connector", "is_connected")
__all__ = (
"Connector",
"SQLConnector",
"APIConnector",
"get_connector",
"is_connected",
"poll",
)

### store connectors partitioned by
### type, label for reuse
Expand Down
8 changes: 7 additions & 1 deletion meerschaum/connectors/sql/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ def cli(
env = copy.deepcopy(dict(os.environ))
env[f'MRSM_SQL_{self.label.upper()}'] = json.dumps(self.meta)
cli_code = (
"import sys\n"
"import meerschaum as mrsm\n"
f"conn = mrsm.get_connector('sql:{self.label}')\n"
f"conn._cli_exit()"
"success, msg = conn._cli_exit()\n"
"mrsm.pprint((success, msg))\n"
"if not success:\n"
" raise Exception(msg)"
)
try:
_ = venv_exec(cli_code, venv=None, debug=debug, capture_output=False)
Expand Down Expand Up @@ -91,6 +95,8 @@ def _cli_exit(
cli_arg_str = self.DATABASE_URL
if self.flavor in ('sqlite', 'duckdb'):
cli_arg_str = str(self.database)
if cli_arg_str.startswith('postgresql+psycopg://'):
cli_arg_str = cli_arg_str.replace('postgresql+psycopg://', 'postgresql://')

### Define the script to execute to launch the CLI.
### The `mssqlcli` script is manually written to avoid telemetry
Expand Down
6 changes: 6 additions & 0 deletions meerschaum/connectors/sql/_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ def get_create_index_queries(
-------
A dictionary of column names mapping to lists of queries.
"""
### NOTE: Due to recent breaking changes in DuckDB, indices don't behave properly.
if self.flavor == 'duckdb':
return {}
from meerschaum.utils.sql import (
sql_item_name,
get_distinct_col_count,
Expand Down Expand Up @@ -554,6 +557,9 @@ def get_drop_index_queries(
-------
A dictionary of column names mapping to lists of queries.
"""
### NOTE: Due to breaking changes within DuckDB, indices must be skipped.
if self.flavor == 'duckdb':
return {}
if not pipe.exists(debug=debug):
return {}
from meerschaum.utils.sql import sql_item_name, table_exists, hypertable_queries
Expand Down
4 changes: 2 additions & 2 deletions meerschaum/utils/packages/_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
'pymysql' : 'PyMySQL>=0.9.0',
'aiomysql' : 'aiomysql>=0.0.21',
'sqlalchemy_cockroachdb' : 'sqlalchemy-cockroachdb>=2.0.0',
'duckdb' : 'duckdb<0.10.3',
'duckdb_engine' : 'duckdb-engine>=0.9.2',
'duckdb' : 'duckdb>=1.0.0',
'duckdb_engine' : 'duckdb-engine>=0.13.0',
},
'drivers-extras': {
'pyodbc' : 'pyodbc>=4.0.30',
Expand Down
11 changes: 9 additions & 2 deletions meerschaum/utils/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,22 @@ def schedule_function(
apscheduler = mrsm.attempt_import('apscheduler', lazy=False)
now = round_time(datetime.now(timezone.utc), timedelta(minutes=1))
trigger = parse_schedule(schedule, now=now)
_scheduler = apscheduler.AsyncScheduler()
_scheduler = apscheduler.AsyncScheduler(identity='mrsm-scheduler')
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()

async def run_scheduler():
async with _scheduler:
job = await _scheduler.add_schedule(function, trigger, args=args, kwargs=kw)
job = await _scheduler.add_schedule(
function,
trigger,
args = args,
kwargs = kw,
max_running_jobs = 1,
conflict_policy = apscheduler.ConflictPolicy.replace,
)
try:
await _scheduler.run_until_stopped()
except (KeyboardInterrupt, SystemExit) as e:
Expand Down
4 changes: 2 additions & 2 deletions requirements/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ psycopg[binary]>=3.1.18
PyMySQL>=0.9.0
aiomysql>=0.0.21
sqlalchemy-cockroachdb>=2.0.0
duckdb<0.10.3
duckdb-engine>=0.9.2
duckdb>=1.0.0
duckdb-engine>=0.13.0
wheel>=0.34.2
setuptools>=63.3.0
PyYAML>=5.3.1
Expand Down
4 changes: 2 additions & 2 deletions requirements/full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ psycopg[binary]>=3.1.18
PyMySQL>=0.9.0
aiomysql>=0.0.21
sqlalchemy-cockroachdb>=2.0.0
duckdb<0.10.3
duckdb-engine>=0.9.2
duckdb>=1.0.0
duckdb-engine>=0.13.0
toga>=0.3.0-dev29
pywebview>=3.6.3
pycparser>=2.21.0
Expand Down

0 comments on commit 9a62f98

Please sign in to comment.