Skip to content

Commit d1f819e

Browse files
author
vshepard
committed
fix lint, ruff
1 parent 5381a5f commit d1f819e

60 files changed

Lines changed: 1026 additions & 1579 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/source/conf.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#
@@ -14,6 +13,7 @@
1413
#
1514
import os
1615
import sys
16+
1717
import testgres
1818

1919
assert testgres.__path__ is not None
@@ -25,10 +25,10 @@
2525

2626
# -- Project information -----------------------------------------------------
2727

28-
project = u'testgres'
29-
package_name = u'testgres'
30-
copyright = u'2016-2026, Postgres Professional'
31-
author = u'Postgres Professional'
28+
project = 'testgres'
29+
package_name = 'testgres'
30+
copyright = '2016-2026, Postgres Professional'
31+
author = 'Postgres Professional'
3232

3333
# The full version, including alpha/beta/rc tags
3434
release = testgres.__version__
@@ -131,23 +131,23 @@
131131
# (source start file, target name, title,
132132
# author, documentclass [howto, manual, or own class]).
133133
latex_documents = [
134-
(master_doc, 'testgres.tex', u'testgres Documentation',
135-
u'Postgres Professional', 'manual'),
134+
(master_doc, 'testgres.tex', 'testgres Documentation',
135+
'Postgres Professional', 'manual'),
136136
]
137137

138138
# -- Options for manual page output ------------------------------------------
139139

140140
# One entry per manual page. List of tuples
141141
# (source start file, name, description, authors, manual section).
142-
man_pages = [(master_doc, 'testgres', u'testgres Documentation', [author], 1)]
142+
man_pages = [(master_doc, 'testgres', 'testgres Documentation', [author], 1)]
143143

144144
# -- Options for Texinfo output ----------------------------------------------
145145

146146
# Grouping the document tree into Texinfo files. List of tuples
147147
# (source start file, target name, title, author,
148148
# dir menu entry, description, category)
149149
texinfo_documents = [
150-
(master_doc, 'testgres', u'testgres Documentation', author, 'testgres',
150+
(master_doc, 'testgres', 'testgres Documentation', author, 'testgres',
151151
'One line description of project.', 'Miscellaneous'),
152152
]
153153

‎pyproject.toml‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,37 @@ build-backend = "setuptools.build_meta"
99
version = {attr = "testgres.__version__"}
1010

1111
[tool.flake8]
12-
extend-ignore = ["E501"]
12+
extend-ignore = ["E501", "E722"]
1313
exclude = [".git", "__pycache__", "env", "venv"]
1414

15+
[tool.ruff]
16+
target-version = "py37"
17+
exclude = [".git", "__pycache__", "env", "venv"]
18+
19+
[tool.ruff.lint]
20+
select = ["E", "F", "I", "UP", "RUF", "FA", "BLE", "PL"]
21+
ignore = [
22+
"E501", # line-too-long (kept unenforced, like flake8)
23+
# Subjective code-metric rules: satisfying them requires refactoring, not
24+
# a lint pass, so they are disabled on this legacy codebase.
25+
"PLR0911", # too-many-return-statements
26+
"PLR0912", # too-many-branches
27+
"PLR0913", # too-many-arguments
28+
"PLR0917", # too-many-positional-arguments (would force breaking API changes)
29+
"PLR0915", # too-many-statements
30+
"PLR2004", # magic-value-comparison
31+
# Patterns that are intentional throughout this codebase. Allowing them
32+
# project-wide keeps the code free of scattered `# noqa` directives.
33+
"BLE001", # broad `except Exception` (wrap-and-reraise / best-effort cleanup)
34+
"PLC0415", # lazy and platform-conditional imports
35+
"PLW0603", # module-level caches and test-session globals via `global`
36+
"RUF003", # non-ASCII (Russian) characters in comments
37+
]
38+
39+
[tool.ruff.lint.per-file-ignores]
40+
# Mutable fixture data kept on the test class is an expected pytest pattern.
41+
"tests/**" = ["RUF012"]
42+
1543
# Pytest settings
1644
[tool.pytest.ini_options]
1745

‎src/__init__.py‎

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,96 @@
1+
from testgres.operations.local_ops import LocalOperations
2+
from testgres.operations.os_ops import ConnectionParams, OsOperations
3+
from testgres.operations.remote_ops import RemoteOperations
4+
15
from .api import get_new_node, get_remote_node
26
from .backup import NodeBackup
3-
4-
from .config import \
5-
TestgresConfig, \
6-
configure_testgres, \
7-
scoped_config, \
8-
push_config, \
9-
pop_config
10-
11-
from .connection import \
12-
NodeConnection, \
13-
DatabaseError, \
14-
InternalError, \
15-
ProgrammingError, \
16-
OperationalError
17-
18-
from .exceptions import \
19-
TestgresException, \
20-
ExecUtilException, \
21-
QueryException, \
22-
QueryTimeoutException, \
23-
TimeoutException, \
24-
CatchUpException, \
25-
StartNodeException, \
26-
InitNodeException, \
27-
BackupException, \
28-
InvalidOperationException
29-
30-
from .enums import \
31-
XLogMethod, \
32-
IsolationLevel, \
33-
NodeStatus, \
34-
ProcessType, \
35-
DumpFormat
36-
37-
from .node import PostgresNode
38-
from .node import PortManager
7+
from .config import (
8+
TestgresConfig,
9+
configure_testgres,
10+
pop_config,
11+
push_config,
12+
scoped_config,
13+
testgres_config,
14+
)
15+
from .connection import (
16+
DatabaseError,
17+
InternalError,
18+
NodeConnection,
19+
OperationalError,
20+
ProgrammingError,
21+
)
22+
from .enums import DumpFormat, IsolationLevel, NodeStatus, ProcessType, XLogMethod
23+
from .exceptions import (
24+
BackupException,
25+
CatchUpException,
26+
ExecUtilException,
27+
InitNodeException,
28+
InvalidOperationException,
29+
QueryException,
30+
QueryTimeoutException,
31+
StartNodeException,
32+
TestgresException,
33+
TimeoutException,
34+
)
35+
from .node import PortManager, PostgresNode
3936
from .node_app import NodeApp
40-
41-
from .utils import \
42-
reserve_port, \
43-
release_port, \
44-
get_bin_path, \
45-
get_bin_dir, \
46-
get_pg_config, \
47-
get_pg_version, \
48-
parse_pg_version
49-
50-
from .standby import \
51-
First, \
52-
Any
53-
54-
from .config import testgres_config
55-
56-
from testgres.operations.os_ops import OsOperations, ConnectionParams
57-
from testgres.operations.local_ops import LocalOperations
58-
from testgres.operations.remote_ops import RemoteOperations
37+
from .standby import Any, First
38+
from .utils import (
39+
get_bin_dir,
40+
get_bin_path,
41+
get_pg_config,
42+
get_pg_version,
43+
parse_pg_version,
44+
release_port,
45+
reserve_port,
46+
)
5947

6048
__version__ = "1.15.2"
6149

6250
__all__ = [
63-
"get_new_node",
64-
"get_remote_node",
65-
"NodeBackup", "testgres_config",
66-
"TestgresConfig", "configure_testgres", "scoped_config", "push_config", "pop_config",
67-
"NodeConnection", "DatabaseError", "InternalError", "ProgrammingError", "OperationalError",
68-
"TestgresException", "ExecUtilException", "QueryException",
69-
"QueryTimeoutException",
70-
"TimeoutException", "CatchUpException", "StartNodeException", "InitNodeException", "BackupException", "InvalidOperationException",
71-
"XLogMethod", "IsolationLevel", "NodeStatus", "ProcessType", "DumpFormat",
51+
"Any",
52+
"BackupException",
53+
"CatchUpException",
54+
"ConnectionParams",
55+
"DatabaseError",
56+
"DumpFormat",
57+
"ExecUtilException",
58+
"First",
59+
"InitNodeException",
60+
"InternalError",
61+
"InvalidOperationException",
62+
"IsolationLevel",
63+
"LocalOperations",
7264
"NodeApp",
73-
"PostgresNode",
65+
"NodeBackup",
66+
"NodeConnection",
67+
"NodeStatus",
68+
"OperationalError",
69+
"OsOperations",
7470
"PortManager",
75-
"reserve_port", "release_port", "get_bin_path", "get_bin_dir", "get_pg_config", "get_pg_version", "parse_pg_version",
76-
"First", "Any",
77-
"OsOperations", "LocalOperations", "RemoteOperations", "ConnectionParams"
71+
"PostgresNode",
72+
"ProcessType",
73+
"ProgrammingError",
74+
"QueryException",
75+
"QueryTimeoutException",
76+
"RemoteOperations",
77+
"StartNodeException",
78+
"TestgresConfig",
79+
"TestgresException",
80+
"TimeoutException",
81+
"XLogMethod",
82+
"configure_testgres",
83+
"get_bin_dir",
84+
"get_bin_path",
85+
"get_new_node",
86+
"get_pg_config",
87+
"get_pg_version",
88+
"get_remote_node",
89+
"parse_pg_version",
90+
"pop_config",
91+
"push_config",
92+
"release_port",
93+
"reserve_port",
94+
"scoped_config",
95+
"testgres_config"
7896
]

‎src/api.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
"""
32
Testing framework for PostgreSQL and its extensions
43
@@ -30,11 +29,11 @@
3029
PostgresNode(name='...', port=..., base_dir='...')
3130
[(3,)]
3231
"""
33-
from .node import PostgresNode
34-
from testgres.operations.remote_ops import ConnectionParams
35-
from testgres.operations.remote_ops import RemoteOperations
32+
from __future__ import annotations
33+
34+
from testgres.operations.remote_ops import ConnectionParams, RemoteOperations
3635

37-
import typing
36+
from .node import PostgresNode
3837

3938

4039
def get_new_node(name=None, base_dir=None, **kwargs):
@@ -46,7 +45,7 @@ def get_new_node(name=None, base_dir=None, **kwargs):
4645
return PostgresNode(name=name, base_dir=base_dir, **kwargs)
4746

4847

49-
def get_remote_node(name=None, conn_params: typing.Optional[ConnectionParams] = None):
48+
def get_remote_node(name=None, conn_params: ConnectionParams | None = None):
5049
"""
5150
Simply a wrapper around :class:`.PostgresNode` constructor for remote node.
5251
See :meth:`.PostgresNode.__init__` for details.

‎src/backup.py‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
# coding: utf-8
21

32
from six import raise_from
3+
from testgres.operations.os_ops import OsOperations
44

5+
from .consts import BACKUP_LOG_FILE, DATA_DIR, PG_CONF_FILE, TMP_BACKUP, TMP_NODE
56
from .enums import XLogMethod
6-
7-
from .consts import \
8-
DATA_DIR, \
9-
TMP_NODE, \
10-
TMP_BACKUP, \
11-
PG_CONF_FILE, \
12-
BACKUP_LOG_FILE
13-
147
from .exceptions import BackupException
15-
16-
from testgres.operations.os_ops import OsOperations
17-
18-
from .utils import \
19-
get_bin_path2, \
20-
execute_utility2, \
21-
clean_on_error
8+
from .utils import clean_on_error, execute_utility2, get_bin_path2
229

2310

24-
class NodeBackup(object):
11+
class NodeBackup:
2512
"""
2613
Smart object responsible for backups
2714
"""
@@ -60,7 +47,7 @@ def __init__(self,
6047
try:
6148
xlog_method = XLogMethod(xlog_method)
6249
except ValueError:
63-
msg = 'Invalid xlog_method "{}"'.format(xlog_method)
50+
msg = f'Invalid xlog_method "{xlog_method}"'
6451
raise BackupException(msg)
6552

6653
# Set default arguments
@@ -185,7 +172,7 @@ def spawn_replica(self, name=None, destroy=True, slot=None):
185172
# Assign it a master and a recovery file (private magic)
186173
node._assign_master(self.original_node)
187174
node._create_recovery_conf(username=self.username, slot=slot)
188-
except: # noqa: E722
175+
except:
189176
# TODO: Pass 'final=True' ?
190177
node.cleanup(release_resources=True)
191178
raise

‎src/cache.py‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
# coding: utf-8
21

32
from six import raise_from
3+
from testgres.operations.local_ops import LocalOperations
4+
from testgres.operations.os_ops import OsOperations
45

56
from .config import testgres_config
6-
77
from .consts import XLOG_CONTROL_FILE
8-
98
from .defaults import generate_system_id
10-
11-
from .exceptions import \
12-
InitNodeException, \
13-
ExecUtilException
14-
15-
from .utils import \
16-
get_bin_path2, \
17-
execute_utility2
18-
19-
from testgres.operations.local_ops import LocalOperations
20-
from testgres.operations.os_ops import OsOperations
9+
from .exceptions import ExecUtilException, InitNodeException
10+
from .utils import execute_utility2, get_bin_path2
2111

2212

2313
def cached_initdb(data_dir, logfile=None, params=None, os_ops: OsOperations = None, bin_path=None, cached=True):

0 commit comments

Comments
 (0)