Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bennet authored Oct 11, 2023
2 parents 42b0821 + f2fcdc8 commit 2dbff0a
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 34 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ jobs:
linux:
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: [
'3.7',
'3.8',
'3.9',
'3.10',
]
include:
- python-version: '3.7'
os: ubuntu-18.04 # MySQL 5.7.32
Expand Down Expand Up @@ -61,4 +66,3 @@ jobs:
run: |
coverage combine
coverage report
codecov
41 changes: 41 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: "12 18 * * 1"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ python ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
24 changes: 12 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Upcoming
========

Internal:
---------
* paramiko is newer than 2.11.0 now, remove version pinning `cryptography`.



Upcoming
========
1.27.0 (2023/08/11)
===================

Features:
---------

* Detect TiDB instance and show in the prompt and use additional keywords.
* Fix the completion order to show more commonly use keywords in the top.

* Detect TiDB instance, show in the prompt, and use additional keywords.
* Fix the completion order to show more commonly-used keywords at the top.

TBD
===

=======
Bug Fixes:
----------
* better handle empty statements in un/prettify

* Better handle empty statements in un/prettify
* Remove vi-mode bindings for prettify/unprettify.
* Honor `\G` when executing from commandline with `-e`.
* Correctly report the version of TiDB.


1.26.1 (2022/09/01)
Expand Down
12 changes: 6 additions & 6 deletions doc/key_bindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ Introduce a line break in multi-line mode, or dispatch the command in single-lin

The sequence ESC-Enter is often sent by Alt-Enter.

#################################
C-x p (Emacs-mode) or > (Vi-mode)
#################################
##################
C-x p (Emacs-mode)
##################

Prettify and indent current statement, usually into multiple lines.

Only accepts buffers containing single SQL statements.

#################################
C-x u (Emacs-mode) or < (Vi-mode)
#################################
##################
C-x u (Emacs-mode)
##################

Unprettify and dedent current statement, usually into one line.

Expand Down
2 changes: 1 addition & 1 deletion mycli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.26.1'
__version__ = '1.27.0'
4 changes: 1 addition & 3 deletions mycli/key_bindings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.filters import completion_is_selected, emacs_mode, vi_mode
from prompt_toolkit.filters import completion_is_selected, emacs_mode
from prompt_toolkit.key_binding import KeyBindings

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -61,7 +61,6 @@ def _(event):
else:
b.start_completion(select_first=False)

@kb.add('>', filter=vi_mode)
@kb.add('c-x', 'p', filter=emacs_mode)
def _(event):
"""
Expand All @@ -82,7 +81,6 @@ def _(event):
cursorpos_abs -= 1
b.cursor_position = min(cursorpos_abs, len(b.text))

@kb.add('<', filter=vi_mode)
@kb.add('c-x', 'u', filter=emacs_mode)
def _(event):
"""
Expand Down
12 changes: 10 additions & 2 deletions mycli/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ def load_ipython_extension(ipython):
def mycli_line_magic(line):
_logger.debug('mycli magic called: %r', line)
parsed = sql.parse.parse(line, {})
conn = sql.connection.Connection(parsed['connection'])

# "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 = conn._mycli
Expand Down
9 changes: 7 additions & 2 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def run_query(self, query, new_line=True):
for result in results:
title, cur, headers, status = result
self.formatter.query = query
output = self.format_output(title, cur, headers)
output = self.format_output(title, cur, headers, special.is_expanded_output())
for line in output:
click.echo(line, nl=new_line)

Expand Down Expand Up @@ -1331,7 +1331,12 @@ def cli(database, user, host, port, socket, password, dbname,
try:
if csv:
mycli.formatter.format_name = 'csv'
elif not table:
if execute.endswith(r'\G'):
execute = execute[:-2]
elif table:
if execute.endswith(r'\G'):
execute = execute[:-2]
else:
mycli.formatter.format_name = 'tsv'

mycli.run_query(execute)
Expand Down
2 changes: 1 addition & 1 deletion mycli/sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def from_version_string(cls, version_string):

re_species = (
(r'(?P<version>[0-9\.]+)-MariaDB', ServerSpecies.MariaDB),
(r'(?P<version>[0-9\.]+)[a-z0-9]*-TiDB', ServerSpecies.TiDB),
(r'[0-9\.]*-TiDB-v(?P<version>[0-9\.]+)-?(?P<comment>[a-z0-9\-]*)', ServerSpecies.TiDB),
(r'(?P<version>[0-9\.]+)[a-z0-9]*-(?P<comment>[0-9]+$)',
ServerSpecies.Percona),
(r'(?P<version>[0-9\.]+)[a-z0-9]*-(?P<comment>[A-Za-z0-9_]+)',
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ twine>=1.12.1
behave>=1.2.4
pexpect>=3.3
coverage>=5.0.4
codecov>=2.0.9
autopep8==1.3.3
colorama>=0.4.1
git+https://github.com/hayd/pep8radius.git # --error-status option not released
Expand Down
2 changes: 1 addition & 1 deletion test/test_smart_completion_public_schema_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_auto_escaped_col_names(completer, complete_event):
Completion(text='`ABC`', start_position=0),
] + \
list(map(Completion, completer.functions)) + \
[Completion(text='`select`', start_position=0)] + \
[Completion(text='select', start_position=0)] + \
list(map(Completion, completer.keywords))


Expand Down
3 changes: 2 additions & 1 deletion test/test_sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ def test_multiple_results(executor):
@pytest.mark.parametrize(
'version_string, species, parsed_version_string, version',
(
('5.7.25-TiDB-v6.1.0','TiDB', '5.7.25', 50725),
('5.7.25-TiDB-v6.1.0','TiDB', '6.1.0', 60100),
('8.0.11-TiDB-v7.2.0-alpha-69-g96e9e68daa', 'TiDB', '7.2.0', 70200),
('5.7.32-35', 'Percona', '5.7.32', 50732),
('5.7.32-0ubuntu0.18.04.1', 'MySQL', '5.7.32', 50732),
('10.5.8-MariaDB-1:10.5.8+maria~focal', 'MariaDB', '10.5.8', 100508),
Expand Down
4 changes: 2 additions & 2 deletions test/test_tabular_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def description(self):
mycli.formatter.query = "SELECT * FROM `table`"
output = mycli.format_output(None, FakeCursor(), headers)
assert "\n".join(output) == dedent('''\
INSERT INTO `table` (`letters`, `number`, `optional`, `float`, `binary`) VALUES
INSERT INTO table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
;''')
Expand All @@ -112,7 +112,7 @@ def description(self):
mycli.formatter.query = "SELECT * FROM `database`.`table`"
output = mycli.format_output(None, FakeCursor(), headers)
assert "\n".join(output) == dedent('''\
INSERT INTO `database`.`table` (`letters`, `number`, `optional`, `float`, `binary`) VALUES
INSERT INTO database.table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
;''')

0 comments on commit 2dbff0a

Please sign in to comment.