Skip to content

Commit

Permalink
Merge pull request dbcli#1211 from dbcli/bugfix/behave
Browse files Browse the repository at this point in the history
fix behave test, keep support for prompt-toolkit 2.x; lock prompt-toolkit==3.0.5 for test.
  • Loading branch information
laixintao authored Sep 14, 2020
2 parents 59ae65c + 13bd678 commit 7626d9a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 38 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ before_install:
- pip install -U setuptools

install:
- pip install .
- pip install --no-cache-dir .
- pip install -r requirements-dev.txt
- pip install keyrings.alt>=3.1

script:
- set -e
- coverage run --source pgcli -m py.test
# TODO: fix failing tests and uncomment.
# commented out on 9/8/2020 by j-bennet
# - cd tests
# - behave --no-capture
# - cd ..
- cd tests
- behave --no-capture
- cd ..
# check for changelog ReST compliance
- rst2html.py --halt=warning changelog.rst >/dev/null
# check for black code compliance, 3.6 only
Expand Down
5 changes: 3 additions & 2 deletions pgcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def _handle_server_closed_connection(self, text):
click.secho(str(e), err=True, fg="red")

def refresh_completions(self, history=None, persist_priorities="all"):
""" Refresh outdated completions
"""Refresh outdated completions
:param history: A prompt_toolkit.history.FileHistory object. Used to
load keyword and identifier preferences
Expand Down Expand Up @@ -1235,7 +1235,8 @@ def cli(
else:
print("Config file is now located at", config_full_path)
print(
"Please move the existing config file ~/.pgclirc to", config_full_path,
"Please move the existing config file ~/.pgclirc to",
config_full_path,
)
if list_dsn:
try:
Expand Down
13 changes: 6 additions & 7 deletions pgcli/packages/parseutils/ctes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@


def isolate_query_ctes(full_text, text_before_cursor):
"""Simplify a query by converting CTEs into table metadata objects
"""
"""Simplify a query by converting CTEs into table metadata objects"""

if not full_text:
return full_text, text_before_cursor, tuple()
Expand Down Expand Up @@ -46,13 +45,13 @@ def isolate_query_ctes(full_text, text_before_cursor):


def extract_ctes(sql):
""" Extract constant table expresseions from a query
"""Extract constant table expresseions from a query
Returns tuple (ctes, remainder_sql)
Returns tuple (ctes, remainder_sql)
ctes is a list of TableExpression namedtuples
remainder_sql is the text from the original query after the CTEs have
been stripped.
ctes is a list of TableExpression namedtuples
remainder_sql is the text from the original query after the CTEs have
been stripped.
"""

p = parse(sql)[0]
Expand Down
18 changes: 11 additions & 7 deletions pgcli/packages/parseutils/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ def extract_from_part(parsed, stop_at_punctuation=True):
yield item
elif item.ttype is Keyword or item.ttype is Keyword.DML:
item_val = item.value.upper()
if item_val in (
"COPY",
"FROM",
"INTO",
"UPDATE",
"TABLE",
) or item_val.endswith("JOIN"):
if (
item_val
in (
"COPY",
"FROM",
"INTO",
"UPDATE",
"TABLE",
)
or item_val.endswith("JOIN")
):
tbl_prefix_seen = True
# 'SELECT a, FROM abc' will detect FROM as part of the column list.
# So this check here is necessary.
Expand Down
2 changes: 1 addition & 1 deletion pgcli/packages/parseutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def last_word(text, include="alphanum_underscore"):


def find_prev_keyword(sql, n_skip=0):
""" Find the last sql keyword in an SQL statement
"""Find the last sql keyword in an SQL statement
Returns the value of the last keyword, and the text of the query with
everything after the last keyword stripped
Expand Down
19 changes: 8 additions & 11 deletions pgcli/pgcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def Candidate(


def generate_alias(tbl):
""" Generate a table alias, consisting of all upper-case letters in
"""Generate a table alias, consisting of all upper-case letters in
the table name, or, if there are no upper-case letters, the first letter +
all letters preceded by _
param tbl - unescaped name of the table to alias
Expand Down Expand Up @@ -172,7 +172,7 @@ def extend_schemata(self, schemata):
self.all_completions.update(schemata)

def extend_casing(self, words):
""" extend casing data
"""extend casing data
:return:
"""
Expand Down Expand Up @@ -491,14 +491,11 @@ def get_completions(self, document, complete_event, smart_completion=None):

def get_column_matches(self, suggestion, word_before_cursor):
tables = suggestion.table_refs
do_qualify = (
suggestion.qualifiable
and {
"always": True,
"never": False,
"if_more_than_one_table": len(tables) > 1,
}[self.qualify_columns]
)
do_qualify = suggestion.qualifiable and {
"always": True,
"never": False,
"if_more_than_one_table": len(tables) > 1,
}[self.qualify_columns]
qualify = lambda col, tbl: (
(tbl + "." + self.case(col)) if do_qualify else self.case(col)
)
Expand Down Expand Up @@ -572,7 +569,7 @@ def filter(col):
return self.find_matches(word_before_cursor, flat_cols(), meta="column")

def alias(self, tbl, tbls):
""" Generate a unique table alias
"""Generate a unique table alias
tbl - name of the table to alias, quoted if it needs to be
tbls - TableReference iterable of tables already in query
"""
Expand Down
6 changes: 3 additions & 3 deletions pgcli/pgexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

def _wait_select(conn):
"""
copy-pasted from psycopg2.extras.wait_select
the default implementation doesn't define a timeout in the select calls
copy-pasted from psycopg2.extras.wait_select
the default implementation doesn't define a timeout in the select calls
"""
while 1:
try:
Expand Down Expand Up @@ -538,7 +538,7 @@ def tables(self):
def views(self):
"""Yields (schema_name, view_name) tuples.
Includes both views and and materialized views
Includes both views and and materialized views
"""
for row in self._relations(kinds=["v", "m"]):
yield row
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ autopep8==1.3.3
click==6.7
twine==1.11.0
wheel==0.33.6
prompt_toolkit==3.0.5
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"pgspecial>=1.11.8",
"click >= 4.1",
"Pygments >= 2.0", # Pygments has to be Capitalcased. WTF?
"prompt_toolkit>=3.0.6,<4.0.0",
# We still need to use pt-2 unless pt-3 released on Fedora32
# see: https://github.com/dbcli/pgcli/pull/1197
"prompt_toolkit>=2.0.6,<4.0.0",
"psycopg2 >= 2.8",
"sqlparse >=0.3.0,<0.4",
"configobj >= 5.0.6",
Expand Down

0 comments on commit 7626d9a

Please sign in to comment.