Skip to content

Commit 473ff68

Browse files
authored
chore: add ruff linter (#532)
## Summary ## Checklist - [ ] Added Unit Tests - [x] Covered by existing CI - [ ] Integration tested - [ ] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Integrated a new linting tool into the development workflow for improved code quality. - **Refactor/Style** - Streamlined and reorganized code structure by reordering import statements and adjusting default parameters. - Enhanced error handling to provide clearer diagnostics without impacting functionality. - **Chores** - Updated configuration and build settings to standardize the codebase and CI processes. - Added a new configuration file for the Ruff linter, specifying linting settings and rules. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c6182fb commit 473ff68

File tree

144 files changed

+476
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+476
-526
lines changed

.github/image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ RUN apt install -y \
5656
rm -rf /var/lib/apt/lists/*
5757

5858
# Upgrade pip and install some common Python packages
59-
RUN pip3 install --break-system-packages pytest tox flake8
59+
RUN pip3 install --break-system-packages pytest tox flake8 ruff
6060

6161
RUN apt update && apt install -y build-essential git
6262
RUN mkdir -p /usr/lib/jvm && ln -s /usr/lib/jvm/java-17-openjdk-amd64/ /usr/lib/jvm/default-jvm

.github/workflows/test_python.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,22 @@ jobs:
4444
python3 -m venv chronon_py_env
4545
source chronon_py_env/bin/activate
4646
47-
- name: Run Chronon Python lint
47+
- name: Run Chronon Python lint (flake8)
4848
shell: bash
4949
run: |
5050
source chronon_py_env/bin/activate
5151
cd api/py/ai/chronon
5252
pip install importlib-metadata==4.11.4
5353
pip install flake8
5454
flake8 --extend-ignore=W605,Q000,F631 --exclude=cli
55+
56+
- name: Run Chronon Python lint (ruff)
57+
shell: bash
58+
run: |
59+
source chronon_py_env/bin/activate
60+
cd api/py
61+
pip install ruff
62+
ruff check .
5563
5664
- name: Run Chronon Python tests
5765
shell: bash

api/py/ai/chronon/cli/compile/compile_context.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
from dataclasses import dataclass
21
import os
2+
from dataclasses import dataclass
33
from typing import Any, Dict, List, Type
44

5+
import ai.chronon.cli.compile.parse_teams as teams
56
from ai.chronon.api.common.ttypes import ConfigType
67
from ai.chronon.api.ttypes import GroupBy, Join, StagingQuery, Team
7-
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
8+
from ai.chronon.cli.compile.conf_validator import ConfValidator
89
from ai.chronon.cli.compile.display.compile_status import CompileStatus
10+
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
911
from ai.chronon.cli.compile.serializer import file2thrift
10-
from ai.chronon.cli.compile.conf_validator import ConfValidator
11-
import ai.chronon.cli.compile.parse_teams as teams
12-
from ai.chronon.cli.logger import require, get_logger
12+
from ai.chronon.cli.logger import get_logger, require
1313
from ai.chronon.model import Model
1414

15-
1615
logger = get_logger()
1716

1817

@@ -129,7 +128,7 @@ def _parse_existing_confs(self, obj_class: type) -> Dict[str, object]:
129128
if not os.path.exists(output_dir):
130129
return result
131130

132-
for sub_root, sub_dirs, sub_files in os.walk(output_dir):
131+
for sub_root, _sub_dirs, sub_files in os.walk(output_dir):
133132

134133
for f in sub_files:
135134

api/py/ai/chronon/cli/compile/compiler.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
from dataclasses import dataclass
21
import os
32
import shutil
43
import traceback
5-
from typing import Dict, Any, List, Optional, Tuple
6-
7-
from ai.chronon.cli.compile.compile_context import CompileContext, ConfigInfo
4+
from dataclasses import dataclass
5+
from typing import Any, Dict, List, Optional, Tuple
86

9-
from ai.chronon.cli.compile.display.class_tracker import ClassTracker
107
import ai.chronon.cli.compile.display.compiled_obj
11-
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
128
import ai.chronon.cli.compile.parse_configs as parser
139
import ai.chronon.cli.logger as logger
14-
1510
from ai.chronon.api.common.ttypes import ConfigType
11+
from ai.chronon.cli.compile.compile_context import CompileContext, ConfigInfo
12+
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
1613

1714
logger = logger.get_logger()
1815

api/py/ai/chronon/cli/compile/conf_validator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@
1717

1818
import json
1919
import logging
20-
import os
2120
import re
22-
import ai.chronon.api.common.ttypes as common
23-
import glom
24-
21+
from collections import defaultdict
22+
from typing import Dict, List, Set
2523

24+
import ai.chronon.api.common.ttypes as common
2625
from ai.chronon.api.ttypes import (
2726
Accuracy,
2827
Aggregation,
28+
Derivation,
29+
ExternalPart,
2930
GroupBy,
3031
Join,
3132
Source,
32-
Derivation,
33-
ExternalPart,
3433
)
3534
from ai.chronon.group_by import get_output_col_names
3635
from ai.chronon.logger import get_logger
3736
from ai.chronon.repo.serializer import thrift_simple_json
38-
from collections import defaultdict
39-
from typing import List, Dict, Set
4037

4138
# Fields that indicate stutus of the entities.
4239
SKIPPED_FIELDS = frozenset(["metaData"])

api/py/ai/chronon/cli/compile/display/class_tracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import difflib
2-
from typing import Dict, List, Any
2+
from typing import Any, Dict, List
3+
34
from rich.text import Text
45

56
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
@@ -79,7 +80,7 @@ def to_status(self) -> Text:
7980
if self.files_to_obj:
8081
text.append(" Compiled ")
8182
text.append(f"{len(self.new_objs)} ", style="bold green")
82-
text.append(f"objects from ")
83+
text.append("objects from ")
8384
text.append(f"{len(self.files_to_obj)} ", style="bold green")
8485
text.append("files.\n")
8586

api/py/ai/chronon/cli/compile/display/compile_status.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Dict, List
1+
from collections import OrderedDict
2+
from typing import Dict
3+
24
from rich.live import Live
35
from rich.text import Text
4-
from rich.console import Console
5-
from collections import OrderedDict
66

7-
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
87
from ai.chronon.cli.compile.display.class_tracker import ClassTracker
8+
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
99

1010

1111
class CompileStatus:

api/py/ai/chronon/cli/compile/display/diff_result.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from dataclasses import dataclass
2-
from typing import List, Dict
1+
from typing import List
2+
33
from rich.text import Text
4-
import difflib
5-
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
64

75

86
class DiffResult:

api/py/ai/chronon/cli/compile/parse_configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from typing import List
55

66
from ai.chronon.cli.compile import parse_teams, serializer
7-
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
87
from ai.chronon.cli.compile.compile_context import CompileContext
8+
from ai.chronon.cli.compile.display.compiled_obj import CompiledObj
99
from ai.chronon.cli.logger import get_logger
1010

1111
logger = get_logger()

api/py/ai/chronon/cli/compile/parse_teams.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from copy import deepcopy
21
import importlib
32
import os
3+
from copy import deepcopy
4+
from typing import Any, Dict, List, Union
5+
46
from ai.chronon.api.common.ttypes import (
5-
ExecutionInfo,
67
ConfigProperties,
78
EnvironmentVariables,
9+
ExecutionInfo,
810
)
911
from ai.chronon.api.ttypes import Team
1012
from ai.chronon.cli.logger import get_logger, require
11-
from typing import Any, List, Dict, Union
1213

1314
logger = get_logger()
1415

0 commit comments

Comments
 (0)