mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-22 17:23:06 +00:00
Fix some flake8 errors
Mainly unused imports, unused variables, unnecessary f-strings, and regex literals missing the r prefix. I'm not adding it to the CI linter because it's too noisy, though. Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
parent
65b65b27b0
commit
5541fad063
@ -5,7 +5,7 @@
|
||||
import argparse
|
||||
import functools
|
||||
import sys
|
||||
from typing import Union, cast
|
||||
from typing import cast
|
||||
|
||||
from drgndoc.format import Formatter
|
||||
from drgndoc.namespace import Namespace, ResolvedNode
|
||||
@ -74,7 +74,7 @@ if __name__ == "__main__":
|
||||
|
||||
if args.header:
|
||||
output_file.write(
|
||||
f"""\
|
||||
"""\
|
||||
/*
|
||||
* Generated by drgndoc.docstrings -H.
|
||||
*
|
||||
@ -86,7 +86,7 @@ if __name__ == "__main__":
|
||||
"""
|
||||
)
|
||||
else:
|
||||
output_file.write(f"/* Generated by drgndoc.docstrings. */\n\n")
|
||||
output_file.write("/* Generated by drgndoc.docstrings. */\n\n")
|
||||
|
||||
def aux(resolved: ResolvedNode[Node], name: str) -> None:
|
||||
node = resolved.node
|
||||
|
@ -42,7 +42,7 @@ file for the C extension itself (drgndoc.docstrings).
|
||||
|
||||
import os.path
|
||||
import re
|
||||
from typing import Any, Dict, List, cast
|
||||
from typing import Any, Dict, cast
|
||||
|
||||
import docutils.nodes
|
||||
import docutils.parsers.rst.directives
|
||||
|
@ -2,7 +2,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import itertools
|
||||
from typing import Generic, Iterator, List, Mapping, Optional, Sequence, TypeVar, Union
|
||||
from typing import Generic, Iterator, List, Mapping, Sequence, TypeVar, Union
|
||||
|
||||
from drgndoc.parse import (
|
||||
Class,
|
||||
@ -14,7 +14,6 @@ from drgndoc.parse import (
|
||||
Node,
|
||||
Variable,
|
||||
)
|
||||
from drgndoc.util import dot_join
|
||||
|
||||
NodeT_co = TypeVar("NodeT_co", bound=Node, covariant=True)
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import ast
|
||||
import sys
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ useful for scripts or for implementing other helpers.
|
||||
|
||||
import enum
|
||||
import typing
|
||||
from typing import Container, Iterable, List, Tuple
|
||||
from typing import Container, Iterable
|
||||
|
||||
from drgn import Type
|
||||
|
||||
|
@ -15,7 +15,7 @@ from typing import Iterator, Tuple
|
||||
|
||||
from _drgn import _linux_helper_idr_find as idr_find
|
||||
from drgn import Object
|
||||
from drgn.helpers.linux.radixtree import radix_tree_for_each, radix_tree_lookup
|
||||
from drgn.helpers.linux.radixtree import radix_tree_for_each
|
||||
|
||||
__all__ = (
|
||||
"idr_find",
|
||||
|
@ -11,7 +11,7 @@ implemented.
|
||||
"""
|
||||
|
||||
import operator
|
||||
from typing import Any, Iterator, List, Optional, Union, overload
|
||||
from typing import Iterator, List, Optional, Union, overload
|
||||
|
||||
from _drgn import _linux_helper_read_vm
|
||||
from drgn import IntegerLike, Object, Program, cast
|
||||
|
@ -15,7 +15,6 @@ from typing import Iterator, Union
|
||||
from drgn import NULL, IntegerLike, Object, Program
|
||||
from drgn.helpers.linux.list import hlist_for_each_entry
|
||||
from drgn.helpers.linux.list_nulls import hlist_nulls_for_each_entry
|
||||
from drgn.helpers.linux.tcp import sk_tcpstate
|
||||
|
||||
__all__ = (
|
||||
"netdev_get_by_index",
|
||||
|
@ -16,8 +16,8 @@ from _drgn import (
|
||||
_linux_helper_find_task as find_task,
|
||||
_linux_helper_pid_task as pid_task,
|
||||
)
|
||||
from drgn import NULL, Object, Program, cast, container_of
|
||||
from drgn.helpers.linux.idr import idr_find, idr_for_each
|
||||
from drgn import Object, Program, cast, container_of
|
||||
from drgn.helpers.linux.idr import idr_for_each
|
||||
from drgn.helpers.linux.list import hlist_for_each_entry
|
||||
|
||||
__all__ = (
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from drgn.helpers.linux.fs import for_each_mount, inode_path
|
||||
from drgn.helpers.linux.list import list_for_each_entry
|
||||
|
@ -1,7 +1,6 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -63,7 +62,7 @@ out:
|
||||
def gen_constants(input_file, output_file):
|
||||
drgn_h = input_file.read()
|
||||
output_file.write(
|
||||
f"""\
|
||||
"""\
|
||||
/* Generated by libdrgn/build-aux/gen_constants.py. */
|
||||
|
||||
#include "drgnpy.h"
|
||||
|
@ -122,7 +122,7 @@ def gen_python_mapping_file(mapping_path):
|
||||
# For some reason, include-what-you-mean wants struct _typeobject, but
|
||||
# find-all-symbols only reports PyTypeObject. Add it manually.
|
||||
imp.write(
|
||||
f' {{"symbol": ["_typeobject", "private", "<Python.h>", "public"]}}, # From cpython/object.h\n'
|
||||
' {{"symbol": ["_typeobject", "private", "<Python.h>", "public"]}}, # From cpython/object.h\n'
|
||||
)
|
||||
|
||||
imp.write("]\n")
|
||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# setuptools must be imported before distutils (see pypa/setuptools#2230).
|
||||
import setuptools # isort: skip
|
||||
import setuptools # isort: skip # noqa: F401
|
||||
|
||||
import contextlib
|
||||
from distutils import log
|
||||
|
@ -2,7 +2,6 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import functools
|
||||
import types
|
||||
from typing import Any, NamedTuple, Optional
|
||||
import unittest
|
||||
|
||||
|
@ -51,9 +51,9 @@ class TestFs(LinuxHelperTestCase):
|
||||
with tempfile.TemporaryDirectory(prefix="drgn-tests-") as dir:
|
||||
path1 = os.fsencode(os.path.abspath(os.path.join(dir, "a")))
|
||||
path2 = os.fsencode(os.path.abspath(os.path.join(dir, "b")))
|
||||
with open(path1, "w") as f:
|
||||
with open(path1, "w"):
|
||||
os.link(path1, path2)
|
||||
with open(path2, "r") as f:
|
||||
with open(path2, "r"):
|
||||
inode = path_lookup(self.prog, path1).dentry.d_inode
|
||||
paths = list(inode_paths(inode))
|
||||
self.assertEqual(len(paths), 2)
|
||||
|
@ -7,7 +7,6 @@ from enum import auto
|
||||
import os
|
||||
|
||||
import _drgn
|
||||
import drgn
|
||||
|
||||
_drgn_pydll = ctypes.PyDLL(_drgn.__file__)
|
||||
_drgn_cdll = ctypes.CDLL(_drgn.__file__)
|
||||
|
@ -6,7 +6,6 @@ import operator
|
||||
import os.path
|
||||
import re
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import drgn
|
||||
from drgn import (
|
||||
@ -1025,22 +1024,25 @@ class TestTypes(TestCase):
|
||||
),
|
||||
]
|
||||
|
||||
point_type = lambda prog: prog.struct_type(
|
||||
"point",
|
||||
8,
|
||||
(
|
||||
TypeMember(prog.int_type("int", 4, True), "x"),
|
||||
TypeMember(prog.int_type("int", 4, True), "y", 32),
|
||||
),
|
||||
)
|
||||
other_point_type = lambda prog: prog.struct_type(
|
||||
"point",
|
||||
8,
|
||||
(
|
||||
TypeMember(prog.int_type("int", 4, True), "a"),
|
||||
TypeMember(prog.int_type("int", 4, True), "b", 32),
|
||||
),
|
||||
)
|
||||
def point_type(prog):
|
||||
return prog.struct_type(
|
||||
"point",
|
||||
8,
|
||||
(
|
||||
TypeMember(prog.int_type("int", 4, True), "x"),
|
||||
TypeMember(prog.int_type("int", 4, True), "y", 32),
|
||||
),
|
||||
)
|
||||
|
||||
def other_point_type(prog):
|
||||
return prog.struct_type(
|
||||
"point",
|
||||
8,
|
||||
(
|
||||
TypeMember(prog.int_type("int", 4, True), "a"),
|
||||
TypeMember(prog.int_type("int", 4, True), "b", 32),
|
||||
),
|
||||
)
|
||||
|
||||
prog = dwarf_program(dies)
|
||||
for dir in ["", "src", "usr/src", "/usr/src"]:
|
||||
|
@ -11,7 +11,6 @@ from drgn import (
|
||||
ObjectAbsentError,
|
||||
OutOfBoundsError,
|
||||
Qualifiers,
|
||||
Type,
|
||||
TypeMember,
|
||||
cast,
|
||||
reinterpret,
|
||||
|
@ -1,8 +1,6 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import operator
|
||||
|
||||
from drgn import (
|
||||
Language,
|
||||
Object,
|
||||
|
@ -2,13 +2,7 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
DESCRIPTION = """
|
||||
drgn script to list BPF programs or maps and their properties
|
||||
unavailable via kernel API.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from drgn.helpers import enum_type_to_class
|
||||
from drgn.helpers.linux import bpf_map_for_each, bpf_prog_for_each, hlist_for_each_entry
|
||||
@ -116,7 +110,7 @@ def list_bpf_maps(args):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description=DESCRIPTION, formatter_class=argparse.RawTextHelpFormatter
|
||||
description="drgn script to list BPF programs or maps and their properties unavailable via kernel API"
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand")
|
||||
|
@ -27,7 +27,7 @@ VMTEST_GITHUB_RELEASE = ("osandov", "drgn", "vmtest-assets")
|
||||
def available_kernel_releases(
|
||||
github_release: Dict[str, Any], arch: str
|
||||
) -> Dict[str, Dict[str, Any]]:
|
||||
pattern = re.compile(r"kernel-(.*)\." + re.escape(arch) + "\.tar\.zst")
|
||||
pattern = re.compile(r"kernel-(.*)\." + re.escape(arch) + r"\.tar\.zst")
|
||||
releases = {}
|
||||
for asset in github_release["assets"]:
|
||||
match = pattern.fullmatch(asset["name"])
|
||||
|
@ -87,7 +87,7 @@ async def fetch_kernel_tags(kernel_dir: Path, kernel_tags: Sequence[str]) -> Non
|
||||
mainline_tags = []
|
||||
stable_tags = []
|
||||
for tag in kernel_tags:
|
||||
if re.fullmatch("v[0-9]+\.[0-9]+\.[0-9]+", tag):
|
||||
if re.fullmatch(r"v[0-9]+\.[0-9]+\.[0-9]+", tag):
|
||||
stable_tags.append(tag)
|
||||
else:
|
||||
mainline_tags.append(tag)
|
||||
|
@ -162,7 +162,7 @@ class LostVMError(Exception):
|
||||
|
||||
def run_in_vm(command: str, kernel_dir: Path, build_dir: Path) -> int:
|
||||
match = re.search(
|
||||
"QEMU emulator version ([0-9]+(?:\.[0-9]+)*)",
|
||||
r"QEMU emulator version ([0-9]+(?:\.[0-9]+)*)",
|
||||
subprocess.check_output(
|
||||
["qemu-system-x86_64", "-version"], universal_newlines=True
|
||||
),
|
||||
@ -238,7 +238,7 @@ def run_in_vm(command: str, kernel_dir: Path, build_dir: Path) -> int:
|
||||
# fmt: on
|
||||
],
|
||||
env=env,
|
||||
) as qemu:
|
||||
):
|
||||
server_sock.settimeout(5)
|
||||
try:
|
||||
sock = server_sock.accept()[0]
|
||||
|
Loading…
Reference in New Issue
Block a user