Skip to content

Commit

Permalink
Rework usage of pyupgrade
Browse files Browse the repository at this point in the history
fixes #167

* Add pyupgrade as dev dependency
* Add pyupgrade task(s) to noxfile
* Update commit hooks to use nox targets
* Add pyupgrade to verification step
* Bump version to 3.1.8
  • Loading branch information
Nicoretti authored Aug 4, 2022
1 parent c1684b8 commit cc49684
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
44 changes: 41 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,47 @@ repos:
language: system
entry: python scripts/version_check.py --fix sqlalchemy_exasol/version.py

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
- repo: local
hooks:
- id: isort
name: isort
types: [python]
pass_filenames: false
language: system
entry: poetry run python -m nox -s isort

- repo: local
hooks:
- id: pyupgrade
args: ['--py38-plus']
name: pyupgrade
types: [python]
pass_filenames: false
language: system
entry: poetry run python -m nox -s pyupgrade

- repo: local
hooks:
- id: code-format
name: code-format
types: [python]
pass_filenames: false
language: system
entry: poetry run python -m nox -s code-format

- repo: local
hooks:
- id: type-check
name: type-check
types: [python]
pass_filenames: false
language: system
entry: poetry run python -m nox -s type-check

- repo: local
hooks:
- id: lint
name: lint
types: [python]
pass_filenames: false
language: system
entry: poetry run python -m nox -s lint
36 changes: 32 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import sys
from argparse import ArgumentParser
Expand All @@ -12,11 +14,9 @@
sys.path.append(f"{SCRIPTS}")

from typing import (
Dict,
Iterable,
Iterator,
MutableMapping,
Tuple,
)

import nox
Expand Down Expand Up @@ -84,7 +84,7 @@ def transaction(connection: Connection, sql_statements: Iterable[str]) -> None:


@contextmanager
def environment(env_vars: Dict[str, str]) -> Iterator[MutableMapping[str, str]]:
def environment(env_vars: dict[str, str]) -> Iterator[MutableMapping[str, str]]:
_env = os.environ.copy()
os.environ.update(env_vars)
yield os.environ
Expand All @@ -104,7 +104,7 @@ def temporary_odbc_config(config: str) -> Iterator[Path]:


@contextmanager
def odbcconfig() -> Iterator[Tuple[Path, MutableMapping[str, str]]]:
def odbcconfig() -> Iterator[tuple[Path, MutableMapping[str, str]]]:
with temporary_odbc_config(
ODBCINST_INI_TEMPLATE.format(driver=Settings.ODBC_DRIVER)
) as cfg:
Expand All @@ -113,8 +113,28 @@ def odbcconfig() -> Iterator[Tuple[Path, MutableMapping[str, str]]]:
yield cfg, env


def _python_files(path: Path) -> Iterator[Path]:
files = filter(lambda path: "dist" not in path.parts, PROJECT_ROOT.glob("**/*.py"))
files = filter(lambda path: ".eggs" not in path.parts, files)
files = filter(lambda path: "venv" not in path.parts, files)
return files


@nox.session(python=False)
def fix(session: Session) -> None:
def apply_pyupgrade_fixes(session: Session) -> None:
files = [f"{path}" for path in _python_files(PROJECT_ROOT)]
session.run(
"poetry",
"run",
"python",
"-m",
"pyupgrade",
"--py38-plus",
"--exit-zero-even-if-changed",
*files,
)

session.run(
"poetry",
"run",
Expand All @@ -123,10 +143,17 @@ def fix(session: Session) -> None:
"--fix",
f"{Settings.VERSION_FILE}",
)
apply_pyupgrade_fixes(session)
session.run("poetry", "run", "python", "-m", "isort", "-v", f"{PROJECT_ROOT}")
session.run("poetry", "run", "python", "-m", "black", f"{PROJECT_ROOT}")


@nox.session(python=False)
def pyupgrade(session: Session) -> None:
files = [f"{path}" for path in _python_files(PROJECT_ROOT)]
session.run("poetry", "run", "python", "-m", "pyupgrade", "--py38-plus", *files)


@nox.session(name="code-format", python=False)
def code_format(session: Session) -> None:
session.run(
Expand Down Expand Up @@ -195,6 +222,7 @@ def is_version_in_sync() -> bool:
f"poetry: {version_from_poetry()}."
)
session.notify("isort")
session.notify("pyupgrade")
session.notify("code-format")
session.notify("type-check")
session.notify("lint")
Expand Down
23 changes: 22 additions & 1 deletion poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "sqlalchemy_exasol"
version = "3.1.7"
version = "3.1.8"
description = "EXASOL dialect for SQLAlchemy"
readme = "README.rst"
authors = [
Expand Down Expand Up @@ -75,6 +75,7 @@ black = "^22.6.0"
isort = "^5.10.1"
pylint = "^2.14.5"
mypy = "^0.971"
pyupgrade = "^2.37.3"

[tool.poetry.extras]
turbodbc = ["turbodbc"]
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_exasol/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

MAJOR = 3
MINOR = 1
PATCH = 7
PATCH = 8

VERSION = f"{MAJOR}.{MINOR}.{PATCH}"

0 comments on commit cc49684

Please sign in to comment.