Skip to content

Commit ca9dfb7

Browse files
sfc-gh-stakedasfc-gh-abhatnagar
authored andcommitted
SNOW-132325 SNOW-126369 SNOW-121544 adding pre-commit hooks to SQLAlchemy
1 parent 7b378ad commit ca9dfb7

23 files changed

+132
-82
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.svn
22
# Byte-compiled / optimized / DLL files
3+
.tox
34
__pycache__/
45
*.py[cod]
56
*$py.class

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
exclude: '^(.*egg.info.*|.*/parameters.py).*$'
2+
repos:
3+
- repo: https://github.com/asottile/seed-isort-config
4+
rev: v1.9.1
5+
hooks:
6+
- id: seed-isort-config
7+
# This work around is necessary until we break the monorepo apart
8+
entry: bash -c "cd Python/snowflake/sqlalchemy && seed-isort-config"
9+
- repo: https://github.com/pre-commit/mirrors-isort
10+
rev: v4.3.21
11+
hooks:
12+
- id: isort
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v2.2.3
15+
hooks:
16+
- id: trailing-whitespace
17+
- id: end-of-file-fixer
18+
- id: check-yaml
19+
- id: debug-statements
20+
- id: flake8
21+
entry: bash -c "cd Python/snowflake/sqlalchemy && flake8"
22+
additional_dependencies: ["flake8-bugbear == 19.3.0"]
23+
- repo: https://github.com/asottile/pyupgrade
24+
rev: v1.19.0
25+
hooks:
26+
- id: pyupgrade
27+
entry: bash -c "cd Python/snowflake/sqlalchemy && pyupgrade"

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ SQLAlchemy provides `the runtime inspection API <http://docs.sqlalchemy.org/en/l
252252
schema = inspector.default_schema_name
253253
for table_name in inspector.get_table_names(schema):
254254
column_metadata = inspector.get_columns(table_name, schema)
255-
primary_keys = inspector.get_primary_keys(table_name, schema)
255+
primary_keys = inspector.get_pk_constraint(table_name, schema)
256256
foreign_keys = inspector.get_foreign_keys(table_name, schema)
257257
...
258258

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ universal = 1
33

44
[flake8]
55
ignore=F821,W504,E501,E402,E122,E127,E126,E128,E131,E731,E125,E722
6-
exclude=build,test,setup,tool,.tox
6+
exclude=build,setup,tool,.tox,connector_python3
77
max-line-length = 120
88
show-source = true

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
try:
1414
from generated_version import VERSION
15-
except:
15+
except ImportError:
1616
from version import VERSION
1717
version = '.'.join([str(v) for v in VERSION if v is not None])
1818

snowdialect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def _get_schema_foreign_keys(self, connection, schema, **kw):
299299
foreign_key_map[name]['referred_columns'].append(self.normalize_name(row['pk_column_name']))
300300

301301
ans = {}
302-
for k, v in iteritems(foreign_key_map):
302+
for _, v in iteritems(foreign_key_map):
303303
if v['table_name'] not in ans:
304304
ans[v['table_name']] = []
305305
ans[v['table_name']].append({k2: v2 for k2, v2 in iteritems(v) if k2 != 'table_name'})
@@ -540,7 +540,7 @@ def get_view_definition(self, connection, view_name, schema=None, **kw):
540540
ret = cursor.fetchone()
541541
if ret:
542542
return ret[n2i['text']]
543-
except:
543+
except Exxception:
544544
pass
545545
return None
546546

sqlalchemy_python2

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Find the ``snowflake-sqlalchemy*.whl`` package in the ``./dist`` directory.
2121
Testing
2222
================================================================================
2323

24-
Create a virtualenv, with ``parameters.py`` in a test directory.
24+
Create a virtualenv, with ``parameters.py`` in a test directory.
2525

2626
.. code-block:: bash
2727

test/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
from logging import getLogger
1212

1313
import pytest
14-
from parameters import (CONNECTION_PARAMETERS)
15-
from sqlalchemy import create_engine
16-
1714
import snowflake.connector
18-
from snowflake.connector.compat import TO_UNICODE, IS_WINDOWS
15+
from parameters import CONNECTION_PARAMETERS
16+
from snowflake.connector.compat import IS_WINDOWS, TO_UNICODE
1917
from snowflake.sqlalchemy import URL, dialect
18+
from sqlalchemy import create_engine
2019

2120
if os.getenv('TRAVIS') == 'true':
2221
TEST_SCHEMA = 'TRAVIS_JOB_{0}'.format(os.getenv('TRAVIS_JOB_ID'))
@@ -65,10 +64,12 @@ def help():
6564
'port': '443',
6665
}
6766

67+
6868
@pytest.fixture(scope='session')
6969
def db_parameters():
7070
return get_db_parameters()
7171

72+
7273
def get_db_parameters():
7374
"""
7475
Sets the db connection parameters
@@ -167,7 +168,7 @@ def init_test_schema(request, db_parameters):
167168
protocol=ret['protocol']
168169
) as con:
169170
con.cursor().execute(
170-
"CREATE SCHEMA IF NOT EXISTS {0}".format(TEST_SCHEMA))
171+
"CREATE SCHEMA IF NOT EXISTS {}".format(TEST_SCHEMA))
171172

172173
def fin():
173174
ret1 = db_parameters

test/test_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
from sqlalchemy import Integer, String, and_, select
5-
from sqlalchemy.sql import column, table, quoted_name
5+
from sqlalchemy.sql import column, quoted_name, table
66
from sqlalchemy.testing import AssertsCompiledSQL
77

88
table1 = table(

0 commit comments

Comments
 (0)