Skip to content

Commit

Permalink
Replace psycopg2-binary with pg8000 and black with ruff (#25)
Browse files Browse the repository at this point in the history
* Replace psycopg2-binary with pg8000

psycopg2 is licensed under LGPL that's not compatible with ASF -
https://www.apache.org/legal/resolved.html#category-x

* Replace black with ruff

black depends on pathspec that is licensed under MPL 2.0. Even though
MPL 2.0 can _maybe_ be included in an ASF project, I'd
prefer to simplify the discussion and just replace black with ruff that
is licensed as Apache 2.0, does not have any dependencies, and is
already used by other Apache projects.
  • Loading branch information
Gerrrr authored Oct 14, 2024
1 parent 5c0b480 commit bc748fc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ See the [poetry docs](https://python-poetry.org/docs) for more.

# Linting and formatting

Code-style is enforced using [black](https://black.readthedocs.io/) and [flake8](https://flake8.pycqa.org/); import optimisation is handled by [isort](https://pycqa.github.io/isort/) and [autoflake](https://pypi.org/project/autoflake/). Linting is automatically applied when tox runs tests; if linting fails, you can fix trivial problems with:
Code-style is enforced using [ruff](https://docs.astral.sh/ruff/) and [flake8](https://flake8.pycqa.org/); import optimisation is handled by [isort](https://pycqa.github.io/isort/) and [autoflake](https://pypi.org/project/autoflake/). Linting is automatically applied when tox runs tests; if linting fails, you can fix trivial problems with:

```
./toxw -e format
Expand Down
8 changes: 4 additions & 4 deletions hunter/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from typing import Dict

import psycopg2
import pg8000

from hunter.analysis import ChangePoint
from hunter.test_config import PostgresTestConfig
Expand All @@ -29,9 +29,9 @@ class Postgres:
def __init__(self, config: PostgresConfig):
self.__config = config

def __get_conn(self) -> psycopg2.extensions.connection:
def __get_conn(self) -> pg8000.dbapi.Connection:
if self.__conn is None:
self.__conn = psycopg2.connect(
self.__conn = pg8000.dbapi.Connection(
host=self.__config.hostname,
port=self.__config.port,
user=self.__config.username,
Expand All @@ -43,7 +43,7 @@ def __get_conn(self) -> psycopg2.extensions.connection:
def fetch_data(self, query: str):
cursor = self.__get_conn().cursor()
cursor.execute(query)
columns = [c.name for c in cursor.description]
columns = [c[0] for c in cursor.description]
return (columns, cursor.fetchall())

def insert_change_point(
Expand Down
99 changes: 40 additions & 59 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ expandvars = "^0.6.5"
numpy = "1.24"
python = ">=3.8,<3.13"
python-dateutil = "^2.8.1"
psycopg2-binary = "^2.9.3"
signal-processing-algorithms = "^1.3.2"
"ruamel.yaml" = "=0.17.21"
requests = "^2.25.1"
Expand All @@ -19,16 +18,17 @@ tabulate = "^0.8.7"
validators = "^0.18.2"
slack-sdk = "^3.4.2"
google-cloud-bigquery = "^3.25.0"
pg8000 = "^1.31.2"


[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
pytz = "2021.1"
tox = "^3.25.0"
black = "^22.3.0"
flake8 = "^4.0.1"
autoflake = "^1.4"
isort = "^5.10.1"
ruff = "^0.6.9"

[tool.pytest.ini_options]
filterwarnings = [
Expand All @@ -39,7 +39,7 @@ filterwarnings = [
[tool.poetry.scripts]
hunter = 'hunter.main:main'

[tool.black]
[tool.ruff]
line-length = 100

[tool.isort]
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ passenv =
SSH_AUTH_SOCK
setenv =
BUILD_DIR = {toxinidir}/build/{envname}
BLACK_OPTS =
RUFF_OPTS =
FLAKE8_OPTS = --count --show-source --statistics
AUTOFLAKE_OPTS = --exclude build --recursive --remove-all-unused-imports
POETRY_OPTS = -v
PYTEST_OPTS =

# Linting should be quiet and fast
lint: BLACK_OPTS = --quiet --fast
lint: RUFF_OPTS = --quiet --fast
lint: FLAKE8_OPTS =
lint: POETRY_OPTS = --quiet --no-root
commands_pre =
./poetryw install {env:POETRY_OPTS}
commands =
black {env:BLACK_OPTS} --check --diff .
ruff {env:RUFF_OPTS} check --diff .
autoflake {env:AUTOFLAKE_OPTS} --check .
isort --check --diff .
flake8 {env:FLAKE8_OPTS}
Expand All @@ -43,7 +43,7 @@ commands =
# environment
[testenv:format]
commands =
black .
ruff check --fix .
autoflake {env:AUTOFLAKE_OPTS} --in-place .
isort .

Expand Down

0 comments on commit bc748fc

Please sign in to comment.