Skip to content

Commit

Permalink
Format imports with isort
Browse files Browse the repository at this point in the history
Signed-off-by: Omar Sandoval <osandov@osandov.com>
  • Loading branch information
osandov committed Aug 20, 2020
1 parent 8c7c80e commit 4e770fb
Show file tree
Hide file tree
Showing 51 changed files with 49 additions and 92 deletions.
8 changes: 6 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ drgn assumes some `implementation-defined behavior
Python
^^^^^^

Python code in drgn is formatted with `black <https://github.com/psf/black>`_.
Code should be compatible with Python 3.6 and newer.
Python code in drgn should be compatible with Python 3.6 and newer.

Python code should be formatted with `black <https://github.com/psf/black>`_
and `isort <https://github.com/timothycrosley/isort>`_::

$ isort . && black .

Type hints should be provided for all interfaces (including helpers and the C
extension).
Expand Down
1 change: 0 additions & 1 deletion docs/exts/drgndoc/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from drgndoc.parse import Class, DocumentedNode, Node, parse_paths
from drgndoc.util import dot_join


escapes = []
for c in range(256):
if c == 0:
Expand Down
8 changes: 4 additions & 4 deletions docs/exts/drgndoc/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@
file for the C extension itself (drgndoc.docstrings).
"""

import os.path
import re
from typing import Any, Dict, List, cast

import docutils.nodes
import docutils.parsers.rst.directives
import docutils.statemachine
import os.path
import re
import sphinx.addnodes
import sphinx.application
import sphinx.environment
import sphinx.util.docutils
import sphinx.util.logging
import sphinx.util.nodes
from typing import Any, Dict, List, cast

from drgndoc.format import Formatter
from drgndoc.namespace import Namespace, ResolvedNode
Expand All @@ -66,7 +67,6 @@
)
from drgndoc.util import dot_join


logger = sphinx.util.logging.getLogger(__name__)


Expand Down
12 changes: 1 addition & 11 deletions docs/exts/drgndoc/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
# SPDX-License-Identifier: GPL-3.0+

import itertools
from typing import (
Generic,
Iterator,
List,
Mapping,
Optional,
Sequence,
TypeVar,
Union,
)
from typing import Generic, Iterator, List, Mapping, Optional, Sequence, TypeVar, Union

from drgndoc.parse import (
Class,
Expand All @@ -25,7 +16,6 @@
)
from drgndoc.util import dot_join


NodeT_co = TypeVar("NodeT_co", bound=Node, covariant=True)


Expand Down
3 changes: 1 addition & 2 deletions docs/exts/setuptools_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
from __future__ import unicode_literals

import os
import sys
import subprocess

import sys

if "check_output" not in dir(subprocess):
import subprocess32 as subprocess
Expand Down
3 changes: 1 addition & 2 deletions drgn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
import types

from _drgn import (
NULL,
Architecture,
FaultError,
FindObjectFlags,
IntegerLike,
Language,
MissingDebugInfoError,
NULL,
Object,
OutOfBoundsError,
Path,
Expand Down Expand Up @@ -96,7 +96,6 @@
void_type,
)


__all__ = (
"Architecture",
"FaultError",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import importlib
import pkgutil


__all__ = []
for _module_info in pkgutil.iter_modules(
__path__, # type: ignore[name-defined] # python/mypy#1422
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
_linux_helper_pgtable_l5_enabled as pgtable_l5_enabled,
)


__all__ = (
"kaslr_offset",
"pgtable_l5_enabled",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/bpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from drgn.helpers.linux.idr import idr_for_each
from drgn.helpers.linux.list import list_for_each_entry


__all__ = (
"bpf_map_for_each",
"bpf_prog_for_each",
Expand Down
3 changes: 1 addition & 2 deletions drgn/helpers/linux/idr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

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 import _linux_helper_idr_find as idr_find


__all__ = (
"idr_find",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from drgn import NULL, Object, Type, container_of


__all__ = (
"hlist_empty",
"hlist_for_each",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/list_nulls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from drgn import Object, container_of


__all__ = (
"hlist_nulls_empty",
"hlist_nulls_for_each_entry",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from _drgn import _linux_helper_read_vm
from drgn import IntegerLike, Object, Program, cast


__all__ = (
"access_process_vm",
"access_remote_vm",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from drgn.helpers.linux.list_nulls import hlist_nulls_for_each_entry
from drgn.helpers.linux.tcp import sk_tcpstate


__all__ = (
"sk_fullsock",
"sk_nulls_for_each",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/percpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from drgn import IntegerLike, Object
from drgn.helpers.linux.cpumask import for_each_online_cpu


__all__ = (
"per_cpu_ptr",
"percpu_counter_sum",
Expand Down
6 changes: 3 additions & 3 deletions drgn/helpers/linux/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

from typing import Iterator, Union

from drgn import NULL, Object, Program, cast, container_of
from drgn.helpers.linux.idr import idr_find, idr_for_each
from drgn.helpers.linux.list import hlist_for_each_entry
from _drgn import (
_linux_helper_find_pid as find_pid,
_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.helpers.linux.list import hlist_for_each_entry

__all__ = (
"find_pid",
Expand Down
3 changes: 1 addition & 2 deletions drgn/helpers/linux/radixtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

from typing import Iterator, Tuple

from drgn import Object, cast
from _drgn import _linux_helper_radix_tree_lookup as radix_tree_lookup

from drgn import Object, cast

__all__ = (
"radix_tree_for_each",
Expand Down
3 changes: 1 addition & 2 deletions drgn/helpers/linux/rbtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

from typing import Callable, Iterator, TypeVar

from drgn import Object, NULL, container_of

from drgn import NULL, Object, container_of

__all__ = (
"RB_EMPTY_NODE",
Expand Down
1 change: 0 additions & 1 deletion drgn/helpers/linux/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

from _drgn import _linux_helper_task_state_to_char as task_state_to_char


__all__ = ("task_state_to_char",)
2 changes: 1 addition & 1 deletion drgn/helpers/linux/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import operator
from typing import Iterator, Union

from drgn import IntegerLike, NULL, Object, Program
from drgn import NULL, IntegerLike, Object, Program
from drgn.helpers.linux.list import hlist_for_each_entry

__all__ = (
Expand Down
3 changes: 2 additions & 1 deletion drgn/internal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import importlib
import os
import os.path
import pkg_resources
import runpy
import shutil
import sys
from typing import Any, Dict

import pkg_resources

import drgn


Expand Down
3 changes: 1 addition & 2 deletions drgn/internal/rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"""Improved readline completer"""

import builtins
import re
import keyword
import re
import readline
from typing import Any, Dict, List, Optional


_EXPR_RE = re.compile(
r"""
(
Expand Down
4 changes: 1 addition & 3 deletions examples/linux/cgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

"""List the paths of all descendants of a cgroup v2"""

from contextlib import contextmanager
import os
import sys

from contextlib import contextmanager

from drgn import cast
from drgn.helpers import enum_type_to_class
from drgn.helpers.linux import (
Expand All @@ -18,7 +17,6 @@
find_task,
)


BpfAttachType = enum_type_to_class(
prog.type("enum bpf_attach_type"),
"BpfAttachType",
Expand Down
4 changes: 2 additions & 2 deletions examples/linux/fs_inodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

"""List the paths of all inodes cached in a given filesystem"""

from drgn.helpers.linux.fs import for_each_mount, inode_path
from drgn.helpers.linux.list import list_for_each_entry
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

if len(sys.argv) == 1:
path = "/"
Expand Down
1 change: 0 additions & 1 deletion examples/linux/lsmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from drgn.helpers.linux.list import list_for_each_entry


print("Module Size Used by")
for mod in list_for_each_entry("struct module", prog["modules"].address_of_(), "list"):
name = mod.name.string_().decode()
Expand Down
1 change: 0 additions & 1 deletion examples/linux/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from drgn.helpers.linux.pid import for_each_task


print("PID COMM")
for task in for_each_task(prog):
pid = task.pid.value_()
Expand Down
1 change: 0 additions & 1 deletion examples/linux/tcp_sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
sock_cgroup_ptr,
)


TcpState = enum_type_to_class(
prog["TCP_ESTABLISHED"].type_,
"TcpState",
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.isort]
profile = "black"
known_first_party = ["drgn", "_drgn", "drgndoc", "vmtest"]
combine_as_imports = true
force_sort_within_sections = true
1 change: 0 additions & 1 deletion scripts/generate_dwarf_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import keyword
import re


prefixes = [
"DW_AT",
"DW_ATE",
Expand Down
1 change: 0 additions & 1 deletion scripts/generate_primitive_type_spellings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import itertools
import sys


SPELLINGS = [
("DRGN_C_TYPE_VOID", ["void"]),
("DRGN_C_TYPE_CHAR", ["char"]),
Expand Down
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0+

# setuptools must be imported before distutils (see pypa/setuptools#2230).
from setuptools import setup, find_packages, Command
import setuptools # isort: skip

import contextlib
from distutils import log
Expand All @@ -14,13 +14,15 @@
import os
import os.path
import re
import shlex
import subprocess
import sys

import pkg_resources
from setuptools import Command, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.egg_info import egg_info as _egg_info
from setuptools.extension import Extension
import shlex
import subprocess
import sys

from util import nproc, out_of_date

Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
union_type,
)


DEFAULT_LANGUAGE = Language.C


Expand Down
Loading

0 comments on commit 4e770fb

Please sign in to comment.