summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaixintao <laixintaoo@gmail.com>2020-09-14 11:55:44 +0800
committerGitHub <noreply@github.com>2020-09-14 11:55:44 +0800
commit7626d9a5f27a221d87f31dcb5bb8fc12024f6c58 (patch)
treecbcf8363bf3e8e57905d30f7b0426af77c958023
parent59ae65cbbf698d1608e7fd3d55b507f3599ac117 (diff)
parent13bd678ccd14e025406ed72490ab52f840ecffa2 (diff)
Merge pull request #1211 from dbcli/bugfix/behave
fix behave test, keep support for prompt-toolkit 2.x; lock prompt-toolkit==3.0.5 for test.
-rw-r--r--.travis.yml10
-rw-r--r--pgcli/main.py5
-rw-r--r--pgcli/packages/parseutils/ctes.py13
-rw-r--r--pgcli/packages/parseutils/tables.py18
-rw-r--r--pgcli/packages/parseutils/utils.py2
-rw-r--r--pgcli/pgcompleter.py19
-rw-r--r--pgcli/pgexecute.py6
-rw-r--r--requirements-dev.txt1
-rw-r--r--setup.py4
9 files changed, 40 insertions, 38 deletions
diff --git a/.travis.yml b/.travis.yml
index d56600b9..5f50abac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/pgcli/main.py b/pgcli/main.py
index a2821368..b1468985 100644
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -968,7 +968,7 @@ class PGCli(object):
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
@@ -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:
diff --git a/pgcli/packages/parseutils/ctes.py b/pgcli/packages/parseutils/ctes.py
index 75e4e40f..171d2002 100644
--- a/pgcli/packages/parseutils/ctes.py
+++ b/pgcli/packages/parseutils/ctes.py
@@ -14,8 +14,7 @@ TableExpression = namedtuple("TableExpression", "name columns start stop")
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()
@@ -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]
diff --git a/pgcli/packages/parseutils/tables.py b/pgcli/packages/parseutils/tables.py
index 55b65b00..0ec3e693 100644
--- a/pgcli/packages/parseutils/tables.py
+++ b/pgcli/packages/parseutils/tables.py
@@ -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.
diff --git a/pgcli/packages/parseutils/utils.py b/pgcli/packages/parseutils/utils.py
index 594cabfd..034c96e9 100644
--- a/pgcli/packages/parseutils/utils.py
+++ b/pgcli/packages/parseutils/utils.py
@@ -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
diff --git a/pgcli/pgcompleter.py b/pgcli/pgcompleter.py
index b2a57834..9c95a01c 100644
--- a/pgcli/pgcompleter.py
+++ b/pgcli/pgcompleter.py
@@ -62,7 +62,7 @@ normalize_ref = lambda ref: ref if ref[0] == '"' else '"' + ref.lower() + '"'
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
@@ -172,7 +172,7 @@ class PGCompleter(Completer):
self.all_completions.update(schemata)
def extend_casing(self, words):
- """ extend casing data
+ """extend casing data
:return:
"""
@@ -491,14 +491,11 @@ class PGCompleter(Completer):
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)
)
@@ -572,7 +569,7 @@ class PGCompleter(Completer):
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
"""
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index 6f7bd715..d34bf26d 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -31,8 +31,8 @@ _WAIT_SELECT_TIMEOUT = 1
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:
@@ -538,7 +538,7 @@ class PGExecute(object):
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
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 8347b5d1..80e8f437 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -11,3 +11,4 @@ autopep8==1.3.3
click==6.7
twine==1.11.0
wheel==0.33.6
+prompt_toolkit==3.0.5
diff --git a/setup.py b/setup.py
index 5a221d98..4e0696fd 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,9 @@ install_requirements = [
"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",