Skip to content

Commit

Permalink
Use Ruff to sort imports (#3230)
Browse files Browse the repository at this point in the history
* Update pyproject.tomls for import sorting

* Update files after running pre-commit

* Move ruff config to pyproject.toml

---------

Co-authored-by: Ashwin Srinath <[email protected]>
  • Loading branch information
shwina and shwina authored Jan 2, 2025
1 parent 9200801 commit 2bdcb7b
Show file tree
Hide file tree
Showing 70 changed files with 213 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/actions/workflow-build/build-workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
import re
import struct
import sys
import yaml

import yaml

matrix_yaml = None

Expand Down
7 changes: 2 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
exclude: "^docs/tools/"
- id: ruff-format
exclude: "^docs/tools/"
- id: ruff # linter
- id: ruff-format # formatter
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
15 changes: 8 additions & 7 deletions benchmarks/scripts/analyze.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env python3

import argparse
import functools
import itertools
import json
import math
import os
import re
import json

import cccl
import math
import argparse
import itertools
import functools
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import mannwhitneyu
from scipy.stats.mstats import hdquantiles

Expand Down Expand Up @@ -330,8 +331,8 @@ def coverage(args):
def parallel_coordinates_plot(df, title):
# Parallel coordinates plot adaptation of https://stackoverflow.com/a/69411450
import matplotlib.cm as cm
from matplotlib.path import Path
import matplotlib.patches as patches
from matplotlib.path import Path

# Variables (the first variable must be categoric):
my_vars = df.columns.tolist()
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/scripts/cccl/bench/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .config import * # noqa: F403
from .storage import * # noqa: F403
from .bench import Bench # noqa: F401
from .cmake import CMake # noqa: F401
from .config import * # noqa: F403
from .score import * # noqa: F403
from .search import * # noqa: F403
from .storage import * # noqa: F403
13 changes: 7 additions & 6 deletions benchmarks/scripts/cccl/bench/bench.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import os
import itertools
import json
import time
import fpzip
import os
import signal
import itertools
import subprocess
import time

import fpzip
import numpy as np

from .cmake import CMake
from .config import BasePoint, Config
from .storage import Storage, get_bench_table_name
from .score import compute_axes_ids, compute_weight_matrices, get_workload_weight
from .logger import Logger
from .score import compute_axes_ids, compute_weight_matrices, get_workload_weight
from .storage import Storage, get_bench_table_name


def first_val(my_dict):
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/scripts/cccl/bench/cmake.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import time
import signal
import subprocess
import time

from .build import Build
from .config import Config
from .storage import Storage
from .logger import Logger
from .storage import Storage


def create_builds_table(conn):
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/scripts/cccl/bench/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
import random
import sys


def randomized_cartesian_product(list_of_lists):
Expand Down
1 change: 1 addition & 0 deletions benchmarks/scripts/cccl/bench/score.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math

import numpy as np


Expand Down
7 changes: 4 additions & 3 deletions benchmarks/scripts/cccl/bench/search.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import re
import argparse
import re

import numpy as np

from .bench import Bench, BaseBench
from .bench import BaseBench, Bench
from .cmake import CMake
from .config import Config
from .storage import Storage
from .cmake import CMake


def list_benches(algnames):
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/scripts/cccl/bench/storage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import fpzip
import sqlite3

import fpzip
import numpy as np
import pandas as pd


db_name = "cccl_meta_bench.db"


Expand Down
4 changes: 2 additions & 2 deletions benchmarks/scripts/compare.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

import argparse
import os

import cccl
import argparse
import numpy as np
import pandas as pd

from colorama import Fore


Expand Down
3 changes: 2 additions & 1 deletion benchmarks/scripts/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3

import math
import os
import sys
import math

import cccl.bench


Expand Down
1 change: 0 additions & 1 deletion benchmarks/scripts/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cccl.bench as bench


# TODO:
# - driver version
# - host compiler + version
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/scripts/sol.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3

import argparse
import os

import cccl
import argparse
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt


def is_finite(x):
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/scripts/verify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

import sys
import argparse
import sys

import cccl.bench


Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/test/support/filesystem_dynamic_test_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import os
import socket
import sys

# Ensure that this is being run on a specific platform
assert (
Expand Down
3 changes: 2 additions & 1 deletion libcudacxx/test/utils/libcudacxx/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#
# ===----------------------------------------------------------------------===##

import platform
import os
import platform

import libcudacxx.util


Expand Down
5 changes: 3 additions & 2 deletions libcudacxx/test/utils/libcudacxx/sym_check/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import ast
import distutils.spawn
import sys
import re
import libcudacxx.util
import sys
from pprint import pformat

import libcudacxx.util


def read_syms_from_list(slist):
"""
Expand Down
9 changes: 4 additions & 5 deletions libcudacxx/test/utils/libcudacxx/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
#
# ===----------------------------------------------------------------------===##

import ctypes
import os
import platform
import pipes
import platform
import re
import shlex
import shutil
import sys
import ctypes

import libcudacxx.util
from libcudacxx.compiler import CXXCompiler
from libcudacxx.test.target_info import make_target_info

# The wildcard import is to support `eval(exec_str)` in
# `Configuration.configure_executor()` below.
from libcudacxx.test.executor import * # noqa: F403
from libcudacxx.test.executor import LocalExecutor, NoopExecutor

import libcudacxx.util
from libcudacxx.test.target_info import make_target_info


def loadSiteConfig(lit_config, config, param_name, env_name):
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/test/utils/libcudacxx/test/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#
# ===----------------------------------------------------------------------===##

import platform
import os
import platform

from libcudacxx.test import tracing
from libcudacxx.util import executeCommand
Expand Down
7 changes: 4 additions & 3 deletions libcudacxx/test/utils/libcudacxx/test/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

import lit.Test # pylint: disable=import-error
import lit.TestRunner # pylint: disable=import-error
from lit.TestRunner import ParserKind, IntegratedTestKeywordParser
# pylint: disable=import-error
from lit.TestRunner import IntegratedTestKeywordParser, ParserKind

from libcudacxx.test.executor import LocalExecutor as LocalExecutor
import libcudacxx.util

# pylint: disable=import-error
from libcudacxx.test.executor import LocalExecutor as LocalExecutor


class LibcxxTestFormat(object):
"""
Expand Down
1 change: 1 addition & 0 deletions libcudacxx/test/utils/libcudacxx/test/googlebenchmark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import

import os
import subprocess
import sys
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/test/utils/libcudacxx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#
# ===----------------------------------------------------------------------===##

from contextlib import contextmanager
import errno
import os
import platform
Expand All @@ -15,6 +14,7 @@
import sys
import tempfile
import threading
from contextlib import contextmanager


# FIXME: Most of these functions are cribbed from LIT
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

[tool.ruff]
target-version = "py310"
fix = true
show-fixes = true
exclude = ["docs/tools"]

[tool.ruff.lint]
extend-select = ["I"]

[tool.codespell]
# To run codespell interactively and fix errors that pre-commit reports, try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

from cuda.cooperative.experimental import block
from cuda.cooperative.experimental import warp
from cuda.cooperative.experimental import block, warp
from cuda.cooperative.experimental._types import StatefulFunction

__all__ = ["block", "warp", "StatefulFunction"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import hashlib
import json
import os
import pickle
import json
import hashlib

_ENABLE_CACHE = "CCCL_ENABLE_CACHE" in os.environ
if _ENABLE_CACHE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import tempfile
import re
import tempfile
from collections import namedtuple

version = namedtuple("version", ("major", "minor"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import functools
import importlib.resources as pkg_resources
import os
import shutil

from cuda.bindings import nvrtc
from cuda.cooperative.experimental._caching import disk_cache
from cuda.cooperative.experimental._common import check_in, version
import importlib.resources as pkg_resources
import functools


def CHECK_NVRTC(err, prog):
Expand Down
Loading

0 comments on commit 2bdcb7b

Please sign in to comment.