From 432b0f609b1db8a61db5b7c04ced32e38a34f4d5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 29 Sep 2023 16:52:00 +0300 Subject: [PATCH 1/3] Convert flake8 configuration to ruff --- ruff.toml | 15 +++++++++++++++ tox.ini | 3 --- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 ruff.toml delete mode 100644 tox.ini diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..a4e94465b --- /dev/null +++ b/ruff.toml @@ -0,0 +1,15 @@ +ignore = [ + "E501", # line too long + "E402", + "F401", + "F403", + # "W503", + # "W504", +] +line-length = 120 +select = [ + "E", + "F", + "W", +] + diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 5554a882a..000000000 --- a/tox.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 120 -ignore = F401,E402,F403,W503,W504 From d312db9de4c2b8fe5a8fce5c62c945891b2c4a0c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 29 Sep 2023 16:54:18 +0300 Subject: [PATCH 2/3] Run ruff via pre-commit and GHA --- .github/workflows/lint.yml | 13 +++++++++++++ .pre-commit-config.yaml | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..1d1b545b5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,13 @@ +name: pre-commit +on: + pull_request: + branches: [main] + push: + branches: [main] +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..c043020c7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.291 + hooks: + - id: ruff + args: + - --fix From aed373d8d3e94fc32b7b3231b4ab80e10044afab Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 29 Sep 2023 16:54:43 +0300 Subject: [PATCH 3/3] Apply ruff autofixes --- aarch64_linux/build_aarch64_wheel.py | 2 +- analytics/cubinsizes.py | 5 +++-- analytics/download_count_wheels.py | 2 +- analytics/duplicates_analyze.py | 2 +- analytics/s3_test_stats_analyze.py | 8 ++++---- manywheel/build_scripts/ssl-check.py | 2 +- test/smoke_test/smoke_test.py | 17 ++++++++--------- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/aarch64_linux/build_aarch64_wheel.py b/aarch64_linux/build_aarch64_wheel.py index 5595dc94a..abf2713bd 100755 --- a/aarch64_linux/build_aarch64_wheel.py +++ b/aarch64_linux/build_aarch64_wheel.py @@ -301,7 +301,7 @@ def build_torchvision(host: RemoteHost, *, # Remove .so files to force static linking host.run_cmd("rm miniforge3/lib/libpng.so miniforge3/lib/libpng16.so miniforge3/lib/libjpeg.so") # And patch setup.py to include libz dependency for libpng - host.run_cmd(['sed -i -e \'s/image_link_flags\.append("png")/image_link_flags += ["png", "z"]/\' vision/setup.py']) + host.run_cmd(['sed -i -e \'s/image_link_flags\\.append("png")/image_link_flags += ["png", "z"]/\' vision/setup.py']) build_vars = "" if branch == "nightly": diff --git a/analytics/cubinsizes.py b/analytics/cubinsizes.py index 33875057a..5702f5810 100755 --- a/analytics/cubinsizes.py +++ b/analytics/cubinsizes.py @@ -12,7 +12,7 @@ try: from elftools.elf.elffile import ELFFile except ModuleNotFoundError: - print(f'elftools module not found, trying to install it from pip') + print('elftools module not found, trying to install it from pip') from pip._internal import main as pip_main try: pip_main(["install", "pyelftools", "--user"]) @@ -106,7 +106,8 @@ def main(): if os.path.splitext(fname)[1] == '.a': with ArFileCtx(fname): for fname in os.listdir("."): - if not fname.endswith(".o"): continue + if not fname.endswith(".o"): + continue for section_name in section_names: elf_sizes = compute_cubin_sizes(fname, section_name) dict_add(results[section_name], elf_sizes) diff --git a/analytics/download_count_wheels.py b/analytics/download_count_wheels.py index f515ddb0a..23c8834bd 100644 --- a/analytics/download_count_wheels.py +++ b/analytics/download_count_wheels.py @@ -140,7 +140,7 @@ def output_results(bytes_cache: dict) -> None: def download_logs(log_directory: str, since: float): dt_now = datetime.now(timezone.utc) dt_end = datetime(dt_now.year, dt_now.month, dt_now.day, tzinfo=timezone.utc) - dt_start = dt_end - timedelta(days=1, hours=1) # Add 1 hour padding to account for potentially missed logs due to timing + dt_start = dt_end - timedelta(days=1, hours=1) # Add 1 hour padding to account for potentially missed logs due to timing for key in tqdm(BUCKET.objects.filter(Prefix='cflogs')): remote_fname = key.key local_fname = os.path.join(log_directory, remote_fname) diff --git a/analytics/duplicates_analyze.py b/analytics/duplicates_analyze.py index 8fdc3af22..dff1881f4 100755 --- a/analytics/duplicates_analyze.py +++ b/analytics/duplicates_analyze.py @@ -81,7 +81,7 @@ def print_symbols_overlap(libname1: str, libname2: str) -> None: sym1 = get_defined_symbols(libname1, verbose=True) sym2 = get_defined_symbols(libname2, verbose=True) sym1_size = sum(sym1.values()) - sym2_size = sum(sym2.values()) + sum(sym2.values()) sym_overlap = set(sym1.keys()).intersection(set(sym2.keys())) overlap_size = sum(sym1[s] for s in sym_overlap) if overlap_size == 0: diff --git a/analytics/s3_test_stats_analyze.py b/analytics/s3_test_stats_analyze.py index 74b4f6de8..d8512c503 100644 --- a/analytics/s3_test_stats_analyze.py +++ b/analytics/s3_test_stats_analyze.py @@ -33,7 +33,7 @@ def _get_latests_git_commit_sha_list(lookback: int): def _json_to_df(data: Dict[str, Any], granularity: str) -> pd.DataFrame: reformed_data = list() for fname, fdata in data['files'].items(): - if granularity == 'file': + if granularity == 'file': reformed_data.append({ "job": data['job'], "sha": data['sha'], @@ -42,7 +42,7 @@ def _json_to_df(data: Dict[str, Any], granularity: str) -> pd.DataFrame: }) else: for sname, sdata in fdata['suites'].items(): - if granularity == 'suite': + if granularity == 'suite': reformed_data.append({ "job": data['job'], "sha": data['sha'], @@ -140,8 +140,8 @@ def main(): dataframe = parse_and_export_stats(f'{cache_folder}/test_time/', granularity) dataframe.to_pickle(output) - + if __name__ == "__main__": main() - + diff --git a/manywheel/build_scripts/ssl-check.py b/manywheel/build_scripts/ssl-check.py index b91927173..4b7ce37b7 100644 --- a/manywheel/build_scripts/ssl-check.py +++ b/manywheel/build_scripts/ssl-check.py @@ -30,4 +30,4 @@ print("...it DIDN'T!!!!!11!!1one!") sys.exit(1) except EXC: - print("...it did, yay.") \ No newline at end of file + print("...it did, yay.") diff --git a/test/smoke_test/smoke_test.py b/test/smoke_test/smoke_test.py index 375ff45be..c0fbd03b9 100644 --- a/test/smoke_test/smoke_test.py +++ b/test/smoke_test/smoke_test.py @@ -69,8 +69,7 @@ def check_nightly_binaries_date(package: str) -> None: from datetime import datetime, timedelta format_dt = '%Y%m%d' - torch_str = torch.__version__ - date_t_str = re.findall("dev\d+", torch.__version__) + date_t_str = re.findall(r"dev\d+", torch.__version__) date_t_delta = datetime.now() - datetime.strptime(date_t_str[0][3:], format_dt) if date_t_delta.days >= NIGHTLY_ALLOWED_DELTA: raise RuntimeError( @@ -81,7 +80,7 @@ def check_nightly_binaries_date(package: str) -> None: for module in MODULES: imported_module = importlib.import_module(module["name"]) module_version = imported_module.__version__ - date_m_str = re.findall("dev\d+", module_version) + date_m_str = re.findall(r"dev\d+", module_version) date_m_delta = datetime.now() - datetime.strptime(date_m_str[0][3:], format_dt) print(f"Nightly date check for {module['name']} version {module_version}") if date_m_delta.days > NIGHTLY_ALLOWED_DELTA: @@ -102,7 +101,7 @@ def test_cuda_runtime_errors_captured() -> None: else: raise e if(cuda_exception_missed): - raise RuntimeError( f"Expected CUDA RuntimeError but have not received!") + raise RuntimeError( "Expected CUDA RuntimeError but have not received!") def smoke_test_cuda(package: str, runtime_error_check: str) -> None: if not torch.cuda.is_available() and is_cuda_system: @@ -145,27 +144,27 @@ def smoke_test_conv2d() -> None: print("Testing smoke_test_conv2d") # With square kernels and equal stride - m = nn.Conv2d(16, 33, 3, stride=2) + nn.Conv2d(16, 33, 3, stride=2) # non-square kernels and unequal stride and with padding - m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2)) + nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2)) # non-square kernels and unequal stride and with padding and dilation basic_conv = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1)) input = torch.randn(20, 16, 50, 100) - output = basic_conv(input) + basic_conv(input) if is_cuda_system: print("Testing smoke_test_conv2d with cuda") conv = nn.Conv2d(3, 3, 3).cuda() x = torch.randn(1, 3, 24, 24).cuda() with torch.cuda.amp.autocast(): - out = conv(x) + conv(x) supported_dtypes = [torch.float16, torch.float32, torch.float64] for dtype in supported_dtypes: print(f"Testing smoke_test_conv2d with cuda for {dtype}") conv = basic_conv.to(dtype).cuda() input = torch.randn(20, 16, 50, 100, device="cuda").type(dtype) - output = conv(input) + conv(input) def smoke_test_linalg() -> None: print("Testing smoke_test_linalg")