Skip to content

Commit

Permalink
Replace flake8 and pydocstyle with ruff - closes #735
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed May 17, 2023
1 parent eeb7809 commit 4e47f3e
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 124 deletions.
19 changes: 3 additions & 16 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@ on:

jobs:
lint:
uses: fizyk/actions-reuse/.github/workflows/linters-python.yml@v1.7.1
uses: fizyk/actions-reuse/.github/workflows/linters-python.yml@v2.0.0
with:
pipenv: true
pipenv-install-options: "--skip-lock"
mypy: true
pycodestyle: false
flake8:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Run flake8 checker
uses: fizyk/actions-reuse/.github/actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
pipenv-install-options: "--skip-lock"
command: flake8 pytest_postgresql/ tests/
ruff: true
black: true


# imports:
Expand Down
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ towncrier = "==22.12"
pytest-cov = "==4.0.0"
pytest-xdist = "==3.3.0"
mock = "==5.0.2"
pydocstyle = {version = "==6.3.0", extras = ["toml"]}
black = "==23.3.0"
mypy = "==1.3.0"
pyflakes = "==2.5.0"
mccabe = "==0.7.0"
flake8 = "==5.0.4"
types-setuptools = "==67.7.0.2"
pycodestyle = "==2.9.0"
tbump = "==6.9.0"
ruff = "==0.0.267"
52 changes: 24 additions & 28 deletions Pipfile.lock

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

1 change: 1 addition & 0 deletions newsfragments/735.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaced flake8 and pydocstyle with ruff, turned on isort rules
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ line-length = 100
target-version = ['py39']
include = '.*\.pyi?$'

[tool.pydocstyle]
ignore = "D203,D212"
[tool.ruff]
# Decrease the maximum line length to 79 characters.
line-length = 100
select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"D", # pydocstyle
]

[tool.towncrier]
directory = "newsfragments"
Expand Down
11 changes: 4 additions & 7 deletions pytest_postgresql/compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
psycopg compatibility module.
"""psycopg compatibility module.
It should be possible to import pytest-postgresql without errors when psycopg is not
installed (while tests using it will error or be skipped). So import psycopg only here
and check if it's available.
"""
from typing import Any, TYPE_CHECKING

from typing import TYPE_CHECKING, Any

__all__ = ("psycopg", "cursor", "connection", "check_for_psycopg")

Expand All @@ -21,13 +19,12 @@
connection = Any

else:
from psycopg import Cursor as cursor
from psycopg import Connection as connection
from psycopg import Cursor as cursor


def check_for_psycopg() -> None:
"""
Check whether psycopg was imported.
"""Check whether psycopg was imported.
Raises ImportError if not.
"""
Expand Down
2 changes: 1 addition & 1 deletion pytest_postgresql/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Plugin's configuration."""
from typing import Optional, TypedDict, Any, List
from typing import Any, List, Optional, TypedDict

from pytest import FixtureRequest

Expand Down
13 changes: 5 additions & 8 deletions pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import subprocess
import tempfile
import time
from typing import TypeVar, Optional, Any
from typing import Any, Optional, TypeVar

from pkg_resources import parse_version
from mirakuru import TCPExecutor
from mirakuru.exceptions import ProcessFinishedWithError
from pkg_resources import parse_version

_LOCALE = "C.UTF-8"

Expand All @@ -44,8 +44,7 @@ class PostgreSQLUnsupported(Exception):


class PostgreSQLExecutor(TCPExecutor):
"""
PostgreSQL executor running on pg_ctl.
"""PostgreSQL executor running on pg_ctl.
Based over an `pg_ctl program
<http://www.postgresql.org/docs/current/static/app-pg-ctl.html>`_
Expand Down Expand Up @@ -80,8 +79,7 @@ def __init__(
options: str = "",
postgres_options: str = "",
):
"""
Initialize PostgreSQLExecutor executor.
"""Initialize PostgreSQLExecutor executor.
:param executable: pg_ctl location
:param host: host under which process is accessible
Expand Down Expand Up @@ -153,8 +151,7 @@ def clean_directory(self) -> None:
self._directory_initialised = False

def init_directory(self) -> None:
"""
Initialize postgresql data directory.
"""Initialize postgresql data directory.
See `Initialize postgresql data directory
<www.postgresql.org/docs/9.5/static/app-initdb.html>`_
Expand Down
8 changes: 3 additions & 5 deletions pytest_postgresql/executor_noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-dbfixtures. If not, see <http://www.gnu.org/licenses/>.
"""PostgreSQL Noop executor providing connection details for postgres client."""
from typing import Union, Optional, Any
from typing import Any, Optional, Union

from pkg_resources import parse_version

from pytest_postgresql.compat import check_for_psycopg, psycopg


class NoopExecutor:
"""
Nooperator executor.
"""Nooperator executor.
This executor actually does nothing more than provide connection details
for existing PostgreSQL server. I.E. one already started either on machine
Expand All @@ -41,8 +40,7 @@ def __init__(
dbname: str,
password: Optional[str] = None,
):
"""
Initialize nooperator executor mock.
"""Initialize nooperator executor mock.
:param host: Postgresql hostname
:param port: Postgresql port
Expand Down
4 changes: 2 additions & 2 deletions pytest_postgresql/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# along with pytest-dbfixtures. If not, see <http://www.gnu.org/licenses/>.
"""Fixture factories for postgresql fixtures."""

from pytest_postgresql.factories.process import postgresql_proc
from pytest_postgresql.factories.noprocess import postgresql_noproc
from pytest_postgresql.factories.client import postgresql
from pytest_postgresql.factories.noprocess import postgresql_noproc
from pytest_postgresql.factories.process import postgresql_proc

__all__ = ("postgresql_proc", "postgresql_noproc", "postgresql")
10 changes: 4 additions & 6 deletions pytest_postgresql/factories/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-dbfixtures. If not, see <http://www.gnu.org/licenses/>.
"""Fixture factory for postgresql client."""
from typing import List, Optional, Callable, Union, Iterator
from typing import Callable, Iterator, List, Optional, Union

import pytest
from pytest import FixtureRequest

from pytest_postgresql.compat import connection, check_for_psycopg, psycopg
from pytest_postgresql.compat import check_for_psycopg, connection, psycopg
from pytest_postgresql.executor import PostgreSQLExecutor
from pytest_postgresql.executor_noop import NoopExecutor
from pytest_postgresql.janitor import DatabaseJanitor
Expand All @@ -33,8 +33,7 @@ def postgresql(
load: Optional[List[Union[Callable, str]]] = None,
isolation_level: "Optional[psycopg.IsolationLevel]" = None,
) -> Callable[[FixtureRequest], Iterator[connection]]:
"""
Return connection fixture factory for PostgreSQL.
"""Return connection fixture factory for PostgreSQL.
:param process_fixture_name: name of the process fixture
:param dbname: database name
Expand All @@ -47,8 +46,7 @@ def postgresql(

@pytest.fixture
def postgresql_factory(request: FixtureRequest) -> Iterator[connection]:
"""
Fixture factory for PostgreSQL.
"""Fixture factory for PostgreSQL.
:param request: fixture request object
:returns: postgresql client
Expand Down
8 changes: 3 additions & 5 deletions pytest_postgresql/factories/noprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with pytest-dbfixtures. If not, see <http://www.gnu.org/licenses/>.
"""Fixture factory for existing postgresql server."""
import os
from typing import Union, Callable, List, Iterator, Optional
from typing import Callable, Iterator, List, Optional, Union

import pytest
from pytest import FixtureRequest
Expand All @@ -44,8 +44,7 @@ def postgresql_noproc(
options: str = "",
load: Optional[List[Union[Callable, str]]] = None,
) -> Callable[[FixtureRequest], Iterator[NoopExecutor]]:
"""
Postgresql noprocess factory.
"""Postgresql noprocess factory.
:param host: hostname
:param port: exact port (e.g. '8000', 8000)
Expand All @@ -59,8 +58,7 @@ def postgresql_noproc(

@pytest.fixture(scope="session")
def postgresql_noproc_fixture(request: FixtureRequest) -> Iterator[NoopExecutor]:
"""
Noop Process fixture for PostgreSQL.
"""Noop Process fixture for PostgreSQL.
:param request: fixture request object
:returns: tcp executor-like object
Expand Down
10 changes: 4 additions & 6 deletions pytest_postgresql/factories/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import os.path
import platform
import subprocess
from typing import Union, Callable, List, Iterator, Optional, Tuple, Set
from typing import Callable, Iterator, List, Optional, Set, Tuple, Union
from warnings import warn

import pytest
from pytest import FixtureRequest, TempPathFactory
from port_for import get_port
from pytest import FixtureRequest, TempPathFactory

from pytest_postgresql.config import get_config
from pytest_postgresql.executor import PostgreSQLExecutor
Expand Down Expand Up @@ -57,8 +57,7 @@ def postgresql_proc(
postgres_options: Optional[str] = None,
load: Optional[List[Union[Callable, str]]] = None,
) -> Callable[[FixtureRequest, TempPathFactory], Iterator[PostgreSQLExecutor]]:
"""
Postgresql process factory.
"""Postgresql process factory.
:param executable: path to postgresql_ctl
:param host: hostname
Expand All @@ -85,8 +84,7 @@ def postgresql_proc(
def postgresql_proc_fixture(
request: FixtureRequest, tmp_path_factory: TempPathFactory
) -> Iterator[PostgreSQLExecutor]:
"""
Process fixture for PostgreSQL.
"""Process fixture for PostgreSQL.
:param request: fixture request object
:param tmp_path_factory: temporary path object (fixture)
Expand Down
Loading

0 comments on commit 4e47f3e

Please sign in to comment.