Skip to content

Commit 3d41cb8

Browse files
author
Oto Šťáva
committed
Merge branch 'manager-nits' into '6.0'
manager: nits, cleanups, fixes See merge request knot/knot-resolver!1496
2 parents 0757d39 + 94031a5 commit 3d41cb8

Some content is hidden

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

54 files changed

+30
-4965
lines changed

manager/.python-version

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
3.7.17
2-
3.8.17
3-
3.9.17
1+
3.11.7
42
3.10.12
5-
3.11.4
3+
3.9.17
4+
3.8.17
5+
3.7.17
File renamed without changes.

manager/knot_resolver_manager/cli/command.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_socket_from_config(config: Path, optional_file: bool) -> Optional[Socket
5858
)
5959
return None
6060
except ValueError as e:
61-
raise DataValidationError(*e.args)
61+
raise DataValidationError(*e.args) from e
6262
except OSError as e:
6363
if not optional_file:
6464
raise e

manager/knot_resolver_manager/compat/asyncio.py

-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
#
33
# pylint: disable=no-member
44

5-
# We disable pyright checks because it can't find method that don't exist in this Python version
6-
# so the reported error is correct, but due to the version checking conditions, it never happens.
7-
# Due to backporting, we are also using private methods and non-existent members of classes
8-
#
9-
# pyright: reportUnknownMemberType=false
10-
# pyright: reportUnknownVariableType=false
11-
# pyright: reportGeneralTypeIssues=false
12-
# pyright: reportPrivateUsage=false
13-
145
import asyncio
156
import functools
167
import logging

manager/knot_resolver_manager/datamodel/config_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def render_lua(self) -> str:
159159
# FIXME the `cwd` argument is used only for configuring control socket path
160160
# it should be removed and relative path used instead as soon as issue
161161
# https://gitlab.nic.cz/knot/knot-resolver/-/issues/720 is fixed
162-
return MAIN_TEMPLATE.render(cfg=self, cwd=os.getcwd()) # pyright: reportUnknownMemberType=false
162+
return MAIN_TEMPLATE.render(cfg=self, cwd=os.getcwd())
163163

164164

165165
def get_rundir_without_validation(data: Dict[str, Any]) -> Dir:

manager/knot_resolver_manager/datamodel/types/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ def __init__(self, source_value: Any, object_path: str = "/") -> None:
147147
super().__init__(source_value, object_path)
148148
try:
149149
punycode = self._value.encode("idna").decode("utf-8") if self._value != "." else "."
150-
except ValueError:
150+
except ValueError as e:
151151
raise ValueError(
152152
f"conversion of '{self._value}' to IDN punycode representation failed",
153153
object_path,
154-
)
154+
) from e
155155

156156
if type(self)._re.match(punycode):
157157
self._punycode = punycode

manager/knot_resolver_manager/kresd_controller/supervisord/config_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SupervisordKresID(KresID):
3232

3333
@staticmethod
3434
def from_string(val: str) -> "SupervisordKresID":
35-
if val == "cache-gc" or val == "cache-gc:cache-gc":
35+
if val in ("cache-gc", "cache-gc:cache-gc"):
3636
# the double name is checked because thats how we read it from supervisord
3737
return SupervisordKresID.new(SubprocessType.GC, 0)
3838
else:
@@ -170,7 +170,7 @@ async def write_config_file(config: KresConfig) -> None:
170170
template = await read_resource(__package__, "supervisord.conf.j2")
171171
assert template is not None
172172
template = template.decode("utf8")
173-
config_string = Template(template).render( # pyright: reportUnknownMemberType=false
173+
config_string = Template(template).render(
174174
gc=ProcessTypeConfig.create_gc_config(config),
175175
kresd=ProcessTypeConfig.create_kresd_config(config),
176176
manager=ProcessTypeConfig.create_manager_config(config),

manager/knot_resolver_manager/server.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def _set_working_directory(config_raw: Dict[str, Any]) -> None:
432432
try:
433433
rundir = get_rundir_without_validation(config_raw)
434434
except ValueError as e:
435-
raise DataValidationError(str(e), "/rundir")
435+
raise DataValidationError(str(e), "/rundir") from e
436436

437437
logger.debug(f"Changing working directory to '{rundir.to_path().absolute()}'.")
438438
os.chdir(rundir.to_path())
@@ -457,12 +457,12 @@ def _lock_working_directory(attempt: int = 0) -> None:
457457
raise KresManagerException(
458458
"Another manager is running in the same working directory."
459459
f" PID file is located at {os.getcwd()}/{PID_FILE_NAME}"
460-
)
460+
) from e
461461
else:
462462
raise KresManagerException(
463463
"Another manager is running in the same working directory."
464464
f" PID file is located at {os.getcwd()}/{PID_FILE_NAME}"
465-
)
465+
) from e
466466

467467
# now we know that we are the only manager running in this directory
468468

manager/knot_resolver_manager/utils/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def f(*nargs: Any, **nkwargs: Any) -> Optional[T]:
2222
try:
2323
return func(*nargs, **nkwargs)
2424
except BaseException as e:
25-
if isinstance(e, exceptions): # pyright: reportUnnecessaryIsInstance=false
25+
if isinstance(e, exceptions):
2626
return default
2727
else:
28-
raise e # pyright: reportGeneralTypeIssues=false
28+
raise e
2929

3030
return f
3131

manager/knot_resolver_manager/utils/modeling/base_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def _assign_default(self, obj: Any, name: str, python_type: Any, object_path: st
521521
try:
522522
default = self._create_default(getattr(cls, name, None))
523523
except ValueError as e:
524-
raise DataValidationError(str(e), f"{object_path}/{name}")
524+
raise DataValidationError(str(e), f"{object_path}/{name}") from e
525525

526526
value = self.map_object(python_type, default, object_path=f"{object_path}/{name}")
527527
setattr(obj, name, value)

manager/knot_resolver_manager/utils/modeling/json_pointer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def resolve(
6969
try:
7070
token = int(token)
7171
current = current[token]
72-
except ValueError:
72+
except ValueError as e:
7373
raise ValueError(
7474
f"invalid JSON pointer: list '{current_ptr}' require numbers as keys, instead got '{token}'"
75-
)
75+
) from e
7676

7777
elif isinstance(current, dict):
7878
current = current.get(token, None)

manager/knot_resolver_manager/utils/modeling/parsing.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def construct_mapping(self, node: Union[MappingNode, Any], deep: bool = False) -
3939
node.start_mark,
4040
f"found unacceptable key ({exc})",
4141
key_node.start_mark,
42-
)
42+
) from exc
4343

4444
# check for duplicate keys
4545
if key in mapping:
@@ -92,4 +92,8 @@ def try_to_parse(data: str) -> Any:
9292
try:
9393
return parse_yaml(data)
9494
except yaml.YAMLError as ye:
95-
raise DataParsingError(f"failed to parse data, JSON: {je}, YAML: {ye}")
95+
# We do not raise-from here because there are two possible causes
96+
# and we may not know which one is the actual one.
97+
raise DataParsingError( # pylint: disable=raise-missing-from
98+
f"failed to parse data, JSON: {je}, YAML: {ye}"
99+
)

manager/pyproject.toml

+4-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = [
1010
# See currently open issue about building C extensions here:
1111
# https://github.com/python-poetry/poetry/issues/2740
1212
[tool.poetry.build]
13-
script = "build.py"
13+
script = "build_c_extensions.py"
1414
generate-setup-file = true
1515

1616
[tool.poetry.dependencies]
@@ -64,7 +64,7 @@ run-debug = { cmd = "scripts/run-debug", help = "Run the manager under debugger"
6464
docs = { cmd = "scripts/docs", help = "Create HTML documentation" }
6565
test = { shell = "env PYTHONPATH=. pytest --junitxml=unit.junit.xml --cov=knot_resolver_manager --show-capture=all tests/unit/", help = "Run tests" }
6666
check = { cmd = "scripts/codecheck", help = "Run static code analysis" }
67-
format = { shell = "black knot_resolver_manager/ tests/ scripts/ build.py; isort -rc .", help = "Run code formatter" }
67+
format = { shell = "black knot_resolver_manager/ tests/ scripts/ build_c_extensions.py; isort -rc .", help = "Run code formatter" }
6868
fixdeps = { shell = "poetry install; npm install; npm update", help = "Install/update dependencies according to configuration files"}
6969
commit = { shell = "scripts/commit", help = "Invoke every single check before commiting" }
7070
container = { cmd = "scripts/container.py", help = "Manage containers" }
@@ -129,22 +129,16 @@ disable= [
129129
"missing-docstring",
130130
"no-else-return",
131131
"no-self-use",
132-
"raise-missing-from",
133132
"too-few-public-methods",
134133
"unused-import", # checked by flake8,
135-
"bad-continuation", # conflicts with black
136-
"consider-using-in", # pyright can't see through in expressions,
137134
"too-many-return-statements", # would prevent us from using recursive tree traversals
138135
"logging-fstring-interpolation", # see https://github.com/PyCQA/pylint/issues/1788
139136
"no-else-raise", # not helpful for readability, when we want explicit branches
140137
"raising-bad-type", # handled by type checker
141138
"too-many-arguments", # sure, but how can we change the signatures to take less arguments? artificially create objects with arguments? That's stupid...
142-
"no-member", # checked by pyright
143-
"import-error", # checked by pyright (and pylint does not do it properly)
144-
"unsupported-delete-operation", # checked by pyright
145-
"unsubscriptable-object", # checked by pyright
146-
"unsupported-membership-test", # checked by pyright
147139
"invalid-overridden-method", # hopefully checked by type checkers
140+
"no-member", # pylint does not do it properly
141+
"import-error", # pylint does not do it properly
148142
]
149143

150144
[tool.pylint.SIMILARITIES]
@@ -156,14 +150,6 @@ ignore-imports = "yes"
156150
[tool.pylint.DESIGN]
157151
max-parents = "10"
158152

159-
[tool.pyright]
160-
include = [
161-
"knot_resolver_manager",
162-
"tests"
163-
]
164-
exclude = []
165-
typeCheckingMode = "strict"
166-
167153
[tool.mypy]
168154
python_version = "3.7"
169155
# strict = true

manager/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
'entry_points': entry_points,
4747
'python_requires': '>=3.7,<4.0',
4848
}
49-
from build import *
49+
from build_c_extensions import *
5050
build(setup_kwargs)
5151

5252
setup(**setup_kwargs)

manager/tests/packaging/dependencies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
dummy.__dict__["setup"] = lambda *args, **kwargs: None
1313
dummy.__dict__["build"] = lambda *args, **kwargs: None
1414
sys.modules["setuptools"] = dummy
15-
sys.modules["build"] = dummy
15+
sys.modules["build_c_extensions"] = dummy
1616

1717
# load install_requires array from setup.py
1818
spec = importlib.util.spec_from_file_location("setup", sys.argv[1] if len(sys.argv) == 2 else "manager/setup.py")

manager/typings/READMEmd

-8
This file was deleted.

manager/typings/pytest/__init__.pyi

-36
This file was deleted.

manager/typings/pytest/__main__.pyi

-9
This file was deleted.

manager/typings/supervisor/__init__.pyi

-3
This file was deleted.

manager/typings/supervisor/childutils.pyi

-51
This file was deleted.

manager/typings/supervisor/compat.pyi

-39
This file was deleted.

manager/typings/supervisor/confecho.pyi

-6
This file was deleted.

0 commit comments

Comments
 (0)