Skip to content

Commit

Permalink
Switched pylint/black to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Schesch committed May 19, 2024
1 parent f927909 commit 33b5c2e
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 51 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
Expand Down
15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
args: ['--maxkb=20000']
Expand Down Expand Up @@ -44,12 +44,9 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/psf/black
rev: 23.11.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: black
- repo: https://github.com/PyCQA/pylint
rev: v3.0.1
hooks:
- id: pylint
args: ['--disable=R0801,E0401,W0718,W0719,W1510,C0103,W0621']
- id: ruff
args: [ --fix ]
- id: ruff-format
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ showvars:
@echo "PYTHON_FILES=${PYTHON_FILES}"

python-style:
black ${PYTHON_FILES}
pylint -f parseable --disable=W,invalid-name,c-extension-no-member,duplicate-code ${PYTHON_FILES}
ruff format ${PYTHON_FILES}
ruff check ${PYTHON_FILES} --fix

check-python-style:
black ${PYTHON_FILES} --check
pylint -f parseable --disable=W,invalid-name --disable=W,duplicate-code ${PYTHON_FILES}
ruff format ${PYTHON_FILES} --check
ruff check ${PYTHON_FILES}

# This target deletes files that are not committed to version control.
clean:
Expand Down
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ dependencies:
- matplotlib==3.8.4
- numpy==1.26.4
- pandas==2.2.2
- pylint==3.1.0
- ruff==0.4.4
- GitPython==3.1.43
- prettytable==3.10.0
- seaborn==0.13.2
- rich==13.7.1
- black==24.4.2
- psutil==5.9.8
- termplotlib==0.3.9
- loguru==0.7.2
3 changes: 2 additions & 1 deletion src/python/add_jacoco_gradle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Adds Jacoco plugin configuration to a Gradle build file. """
"""Adds Jacoco plugin configuration to a Gradle build file."""

import argparse


Expand Down
2 changes: 1 addition & 1 deletion src/python/add_jacoco_maven.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Adds Jacoco plugin configuration to a Maven pom.xml file. """
"""Adds Jacoco plugin configuration to a Maven pom.xml file."""

from typing import Any
import argparse
Expand Down
5 changes: 3 additions & 2 deletions src/python/cache_merger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Merge multiple caches into one. Usage:
python3 cache_merger.py <cache1> <cache2> ... <cacheN> --output_cache <output_cache>
"""Merge multiple caches into one. Usage:
python3 cache_merger.py <cache1> <cache2> ... <cacheN> --output_cache <output_cache>
"""

import shutil
import json
from argparse import ArgumentParser
Expand Down
2 changes: 1 addition & 1 deletion src/python/cache_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Contains all the functions related to the caches. The functions to interact with each
"""Contains all the functions related to the caches. The functions to interact with each
of the caches are in this file. Each cache is interacted with through the functions
of this file. The caches are all JSON files and are stored in the cache directory.
There will be 4 caches in total which are stored on disk after running the run.sh script:
Expand Down
3 changes: 2 additions & 1 deletion src/python/delete_adjacent_keys_from_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""" Delete the keys containing 'imports' in the JSON files in the given directory. """
"""Delete the keys containing 'imports' in the JSON files in the given directory."""

import os
import json

Expand Down
3 changes: 2 additions & 1 deletion src/python/delete_import_keys_from_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""" Delete the keys containing 'imports' in the JSON files in the given directory. """
"""Delete the keys containing 'imports' in the JSON files in the given directory."""

import os
import json

Expand Down
11 changes: 4 additions & 7 deletions src/python/latex_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
- output_dir: path to the directory where the LaTeX files will be saved
"""


import os
import argparse
from pathlib import Path
Expand Down Expand Up @@ -186,9 +185,7 @@ def build_table1(
return table


def build_table2( # pylint: disable=too-many-locals
main: pd.DataFrame, merge_tools: List[str], feature
) -> str:
def build_table2(main: pd.DataFrame, merge_tools: List[str], feature) -> str:
"""Build a table with the results of the merge tools.
Args:
main: DataFrame containing the results of the merge tools for the main branch
Expand Down Expand Up @@ -261,7 +258,7 @@ def build_table2( # pylint: disable=too-many-locals
return table2


def main(): # pylint: disable=too-many-locals,too-many-branches,too-many-statements
def main():
"""Main function"""
parser = argparse.ArgumentParser()
parser.add_argument("--run_name", type=str, default="combined")
Expand Down Expand Up @@ -485,7 +482,7 @@ def merge_two_states(
results = []
for cost_factor in np.linspace(1, max_cost_intersection, 1000):
score = unhandled[idx] * 1 + incorrect[idx] * cost_factor
score = score / ((unhandled[idx] + incorrect[idx] + correct[idx]))
score = score / (unhandled[idx] + incorrect[idx] + correct[idx])
score = 1 - score
results.append(score)
line_style = [(idx, (1, 1)), "--", "-."][idx % 3]
Expand Down Expand Up @@ -524,7 +521,7 @@ def merge_two_states(
results = []
for cost_factor in np.linspace(1, max_cost_intersection, 1000):
score = unhandled[-1] * 1 + incorrect[-1] * cost_factor
score = score / ((unhandled[-1] + incorrect[-1] + correct[-1]))
score = score / (unhandled[-1] + incorrect[-1] + correct[-1])
score = 1 - score
results.append(score)
# print(results)
Expand Down
6 changes: 3 additions & 3 deletions src/python/merge_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Analyze the merges i.e. check if the parents pass tests and statistics between merges.
"""Analyze the merges i.e. check if the parents pass tests and statistics between merges.
usage: python3 merge_analyzer.py --repos_head_passes_csv <path_to_repos_head_passes.csv>
--merges_path <path_to_merges>
--output_dir <output_dir>
Expand Down Expand Up @@ -149,8 +149,8 @@ def diff_merge_analyzer(
return cache_data


def merge_analyzer( # pylint: disable=too-many-locals,too-many-statements
args: Tuple[str, pd.Series, Path]
def merge_analyzer(
args: Tuple[str, pd.Series, Path],
) -> pd.Series:
"""
Merges two branches and returns the result.
Expand Down
2 changes: 1 addition & 1 deletion src/python/merge_runtime_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)


def main(): # pylint: disable=too-many-locals,too-many-statements
def main():
"""Main function"""
logger.info("merge_timer: Start")
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion src/python/merge_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def build_arguments(
]


def main(): # pylint: disable=too-many-locals,too-many-statements
def main():
"""Main function"""
logger.info("merge_tester: Start")
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion src/python/merges_sampler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Samples n_merges for each repository.
"""Samples n_merges for each repository.
usage: python3 merges_sampler.py --repos_head_passes_csv <path_to_repos_head_passes.csv>
--merges_path <path_to_merges>
--output_dir <output_dir>
Expand Down
4 changes: 2 additions & 2 deletions src/python/replay_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
replay_merge.py --idx INDEX
where INDEX is, for example, 38-192 .
"""

import argparse
import os
import sys
Expand Down Expand Up @@ -56,7 +57,6 @@ def delete_workdirs(results_df: pd.DataFrame) -> None:
logger.info("Workdirs deleted")


# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-statements
def merge_replay(
merge_idx: str,
repo_slug: str,
Expand Down Expand Up @@ -228,7 +228,7 @@ def merge_replay(
]
assert repo.local_repo_path.exists()

if ( # pylint: disable=too-many-boolean-expressions
if (
merge_result
not in (
MERGE_STATE.Git_checkout_failed,
Expand Down
14 changes: 7 additions & 7 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def repo_test(wcopy_dir: Path, timeout: int) -> Tuple[TEST_STATE, str]:
str(wcopy_dir),
]
try:
p = subprocess.run( # pylint: disable=consider-using-with
p = subprocess.run(
command,
capture_output=True,
timeout=timeout,
Expand All @@ -179,10 +179,10 @@ def repo_test(wcopy_dir: Path, timeout: int) -> Tuple[TEST_STATE, str]:
return TEST_STATE.Tests_failed, explanation


class Repository: # pylint: disable=too-many-instance-attributes
class Repository:
"""A class that represents a repository."""

def __init__( # pylint: disable=too-many-arguments
def __init__(
self,
repo_slug: str,
cache_directory: Path = Path(""),
Expand Down Expand Up @@ -294,7 +294,7 @@ def checkout(self, commit: str, use_cache: bool = True) -> Tuple[bool, str]:
set_in_cache(commit, cache_entry, self.repo_slug, self.sha_cache_directory)
return True, explanation

def _merge_and_test( # pylint: disable=too-many-arguments
def _merge_and_test(
self,
tool: MERGE_TOOL,
left_commit: str,
Expand Down Expand Up @@ -348,7 +348,7 @@ def _merge_and_test( # pylint: disable=too-many-arguments
test_coverage,
)

def merge_and_test( # pylint: disable=too-many-arguments
def merge_and_test(
self,
tool: MERGE_TOOL,
left_commit: str,
Expand Down Expand Up @@ -438,7 +438,7 @@ def create_branch(
self.repo.git.checkout("-b", branch_name, force=True)
return tree_fingerprint, explanation

def merge( # pylint: disable=too-many-locals,too-many-arguments
def merge(
self,
tool: MERGE_TOOL,
left_commit: str,
Expand Down Expand Up @@ -509,7 +509,7 @@ def merge( # pylint: disable=too-many-locals,too-many-arguments
RIGHT_BRANCH_NAME,
]
try:
p = subprocess.run( # pylint: disable=consider-using-with
p = subprocess.run(
command,
capture_output=True,
timeout=timeout if timeout > 0 else None,
Expand Down
1 change: 1 addition & 0 deletions src/python/test_repo_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Cache_dir is the directory where the cache will be stored.
Output: the rows of the input for which the commit at head hash passes tests.
"""

import multiprocessing
import os
import argparse
Expand Down
9 changes: 4 additions & 5 deletions src/scripts/merge_tools/resolve-conflicts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python # pylint: skip-file
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# This is a helper script for `resolve-adjacent-conflicts` and
Expand Down Expand Up @@ -39,7 +39,7 @@
debug = False


def main(): # pylint: disable=too-many-locals
def main():
"""The main entry point."""
arg_parser = ArgumentParser()
arg_parser.add_argument("filename")
Expand Down Expand Up @@ -114,7 +114,7 @@ def main(): # pylint: disable=too-many-locals
sys.exit(0)


def looking_at_conflict( # pylint: disable=too-many-return-statements
def looking_at_conflict(
filename: str, start_index: int, lines: List[str]
) -> Union[None, Tuple[List[str], List[str], List[str], int]]:
"""Tests whether the following text starts a conflict.
Expand Down Expand Up @@ -185,7 +185,7 @@ def looking_at_conflict( # pylint: disable=too-many-return-statements
return (base, parent1, parent2, index - start_index)


def merge( # pylint: disable=too-many-arguments
def merge(
base: List[str],
parent1: List[str],
parent2: List[str],
Expand Down Expand Up @@ -296,7 +296,6 @@ def merge_base_is_prefix_or_suffix(
"""
base_len = len(base)
parent1_len = len(parent1)
parent2_len = len(parent2)
if base_len < parent1_len:
if parent1[:base_len] == base:
debug_print("startswith", parent1, base)
Expand Down
2 changes: 1 addition & 1 deletion test/check_equal_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def remove_run_time(df):
raise ValueError(
f'goal_df.columns contains "run_time": {goal_df.columns}'
)
if not col in actual_df:
if col not in actual_df:
print(f"Column {col} is not in actual_df")
print(goal_df[col])
different_columns.append(col)
Expand Down

0 comments on commit 33b5c2e

Please sign in to comment.