Skip to content

Commit

Permalink
chore: add pylint hook (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Dec 23, 2021
1 parent 6bd9c80 commit 14579e4
Show file tree
Hide file tree
Showing 76 changed files with 666 additions and 832 deletions.
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile = black
known_first_party = shillelagh
131 changes: 89 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,95 @@
exclude: '^docs/conf.py'

repos:
- repo: https://github.com/ambv/black
rev: 21.6b0
hooks:
- id: black
language_version: python3.9
exclude: ^templates/
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
exclude: ^templates/
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910' # Use the sha / tag you want to point at
hooks:
- id: mypy
exclude: ^templates/
additional_dependencies:
- types-requests
- types-freezegun
- types-python-dateutil
- types-pkg_resources
- types-PyYAML
- types-tabulate
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
exclude: ^templates/
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0
hooks:
- id: reorder-python-imports
exclude: ^templates/
args: [--application-directories=.:src]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: debug-statements
exclude: ^templates/
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-ast
exclude: ^templates/
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
exclude: ^templates/
- id: end-of-file-fixer
- id: requirements-txt-fixer
exclude: ^templates/
- id: mixed-line-ending
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows

## If you want to avoid flake8 errors due to unused vars or imports:
# - repo: https://github.com/myint/autoflake.git
# rev: v1.4
# hooks:
# - id: autoflake
# args: [
# --in-place,
# --remove-all-unused-imports,
# --remove-unused-variables,
# ]

- repo: https://github.com/pycqa/isort
rev: 5.7.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3
exclude: ^templates/

## If like to embrace black styles even in the docs:
# - repo: https://github.com/asottile/blacken-docs
# rev: v1.9.1
# hooks:
# - id: blacken-docs
# additional_dependencies: [black]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
exclude: ^templates/
## You can add flake8 plugins via `additional_dependencies`:
# additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910' # Use the sha / tag you want to point at
hooks:
- id: mypy
exclude: ^templates/
additional_dependencies:
- types-requests
- types-freezegun
- types-python-dateutil
- types-pkg_resources
- types-PyYAML
- types-tabulate
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
#- repo: https://github.com/asottile/reorder_python_imports
# rev: v2.5.0
# hooks:
# - id: reorder-python-imports
# args: [--application-directories=.:src]
- repo: https://github.com/hadialqattan/pycln
rev: v1.0.3 # Possible releases: https://github.com/hadialqattan/pycln/tags
hooks:
- id: pycln
args: [--config=pyproject.toml]
exclude: ^templates/
- id: pycln
args: [--config=pyproject.toml]
exclude: ^templates/
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
exclude: ^templates/
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[MESSAGES CONTROL]
disable =
duplicate-code

[MASTER]
ignore=templates,docs
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ clean:

spellcheck:
codespell -S "*.json" src/shillelagh docs/*rst tests templates

requirements.txt:
pip-compile --no-annotate
14 changes: 7 additions & 7 deletions docs/adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The Google Sheets adapter has a custom SQLAlchemy dialect, ``gsheets://``. When
engine = create_engine("gsheets://", service_account_file="/path/to/credentials.json")
The dialect also exposes the list of sheets that the user has via the ``get_table_names``
The dialect also exposes the list of sheets that the user has via the ``get_table_names``

.. code-block:: python
Expand Down Expand Up @@ -156,7 +156,7 @@ CSV (comma separated values) are supported (`an example <https://github.com/beto
.. code-block:: sql
SELECT * FROM "/path/to/file.csv";
The adapter supports full DML, so you can also ``INSERT``, ``UPDATE``, or ``DELETE`` rows from the CSV file. Deleted rows are marked for deletion, modified and inserted rows are appended at the end of the file, and garbage collection is applied when the connection is closed.


Expand All @@ -172,7 +172,7 @@ The `Socrata Open Data API <https://dev.socrata.com/>`_ is a simple API used by
WHERE location = 'US'
ORDER BY date DESC
LIMIT 10
The adapter is currently read-only.

WeatherAPI
Expand Down Expand Up @@ -225,16 +225,16 @@ Shillelagh has support for Pandas dataframes, inspired by `DuckDB <https://duckd
import pandas as pd
from shillelagh.backends.apsw.db import connect
connection = connect(":memory:")
cursor = connection.cursor()
mydf = pd.DataFrame({"a": [1, 2, 3]})
sql = "SELECT SUM(a) FROM mydf"
for row in cursor.execute(sql):
print(row)
Datasette
=========

Expand Down
12 changes: 6 additions & 6 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The first step is to create a class based on ``shillelagh.adapter.base.Adapter``
from shillelagh.adapters.base import Adapter
class WeatherAPI(Adapter):
"""
An adapter to historical data from https://www.weatherapi.com/.
"""
Expand Down Expand Up @@ -407,25 +407,25 @@ The ``shilellagh.fields`` module has implementation of common representations. F
class IntBoolean(Field[int, bool]):
"""
A boolean.
This field is used in adapters that represent booleans as an
integer. SQLite, eg, has no boolean type, using 1 and 0 to
represent true and false, respectively.
"""
type = "BOOLEAN"
db_api_type = "NUMBER"
def parse(self, value: Optional[int]) -> Optional[bool]:
if value is None:
return None
return bool(value)
def format(self, value: Optional[bool]) -> Optional[int]:
if value is None:
return None
return 1 if value else 0
def quote(self, value: Optional[int]) -> str:
if value is None:
return "NULL"
Expand Down
10 changes: 5 additions & 5 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ The DB API 2.0 specification defines standard mechanisms to create database conn
query = "CREATE TABLE a_table (A int, B string)"
cursor.execute(query)
query = "INSERT INTO a_table VALUES (?, ?)"
cursor.execute(query, (1, "one"))
cursor.execute(query, (2, "two"))
query = "SELECT * FROM a_table"
for row in cursor.execute(query):
print(row)
print(row)
You can use a file instead of ``:memory:``:

Expand Down Expand Up @@ -120,7 +120,7 @@ The SQLAlchemy engine can be configured in the same way as the :ref:`dbapi2` ``c
Alternatively, Shillelagh also comes with a custom Google Sheets dialect for SQLAlchemy. See :ref:`gsheets` for more details.


Command-line utility
====================

Expand Down Expand Up @@ -153,7 +153,7 @@ The command-line utility can be configured through a YAML file stored in ``~/.co
subject: [email protected]
weatherapi:
api_key: XXX
Custom functions
================

Expand Down Expand Up @@ -198,4 +198,4 @@ Sometimes it's useful to identify the version of Shillelagh that's running on a
sql> SELECT VERSION();
VERSION()
-----------
1.0.0
1.0.0
39 changes: 21 additions & 18 deletions examples/csvfile.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
"""
A simple example showing the CSV adapter.
"""
from shillelagh.backends.apsw.db import connect

if __name__ == "__main__":
connection = connect(":memory:")
cursor = connection.cursor()

sql = '''SELECT * FROM "test.csv"'''
print(sql)
for row in cursor.execute(sql):
SQL = '''SELECT * FROM "test.csv"'''
print(SQL)
for row in cursor.execute(SQL):
print(row)
print("==")

sql = """SELECT * FROM "test.csv" WHERE "index" > 11"""
print(sql)
for row in cursor.execute(sql):
SQL = """SELECT * FROM "test.csv" WHERE "index" > 11"""
print(SQL)
for row in cursor.execute(SQL):
print(row)
print("==")

sql = """INSERT INTO "test.csv" ("index", temperature, site) VALUES (14, 10.1, 'New_Site')"""
print(sql)
cursor.execute(sql)
SQL = """INSERT INTO "test.csv" ("index", temperature, site) VALUES (14, 10.1, 'New_Site')"""
print(SQL)
cursor.execute(SQL)

sql = """SELECT * FROM "test.csv" WHERE "index" > 11"""
print(sql)
for row in cursor.execute(sql):
SQL = """SELECT * FROM "test.csv" WHERE "index" > 11"""
print(SQL)
for row in cursor.execute(SQL):
print(row)
print("==")

sql = """DELETE FROM "test.csv" WHERE site = 'New_Site'"""
print(sql)
cursor.execute(sql)
sql = '''SELECT * FROM "test.csv"'''
print(sql)
for row in cursor.execute(sql):
SQL = """DELETE FROM "test.csv" WHERE site = 'New_Site'"""
print(SQL)
cursor.execute(SQL)
SQL = '''SELECT * FROM "test.csv"'''
print(SQL)
for row in cursor.execute(SQL):
print(row)
print("==")
16 changes: 9 additions & 7 deletions examples/dataframe.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
"""
A simple example showing the Pandas adapter.
"""
import pandas as pd

from shillelagh.backends.apsw.db import connect


if __name__ == "__main__":
connection = connect(":memory:")
cursor = connection.cursor()

mydf = pd.DataFrame({"a": [1, 2, 3]})

sql = "SELECT SUM(a) FROM mydf"
for row in cursor.execute(sql):
SQL = "SELECT SUM(a) FROM mydf"
for row in cursor.execute(SQL):
print(row)

sql = "UPDATE mydf SET a = a + 1"
cursor.execute(sql)
SQL = "UPDATE mydf SET a = a + 1"
cursor.execute(SQL)

sql = "SELECT SUM(a) FROM mydf"
for row in cursor.execute(sql):
SQL = "SELECT SUM(a) FROM mydf"
for row in cursor.execute(SQL):
print(row)
8 changes: 5 additions & 3 deletions examples/datasette.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
A simple example showing the Datasette adapter.
"""
from shillelagh.backends.apsw.db import connect


if __name__ == "__main__":
connection = connect(":memory:")
cursor = connection.cursor()

sql = """
SQL = """
SELECT "Latitude" AS "Latitude",
"Longitude" AS "Longitude",
COUNT(*) AS count
Expand All @@ -19,5 +21,5 @@
LIMIT 1000
OFFSET 0;
"""
for row in cursor.execute(sql):
for row in cursor.execute(SQL):
print(row)
Loading

0 comments on commit 14579e4

Please sign in to comment.