Skip to content

Commit d961ae9

Browse files
authored
Add format checks (#26)
Add format checks and formatted files
1 parent db25279 commit d961ae9

110 files changed

Lines changed: 1474 additions & 2045 deletions

File tree

Some content is hidden

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

.github/workflows/format.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Check Format
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
types: [ opened, synchronize, reopened, ready_for_review ]
9+
10+
jobs:
11+
check-format:
12+
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
id: setup-python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.9'
24+
25+
- name: Install Poetry
26+
uses: snok/install-poetry@v1
27+
with:
28+
virtualenvs-create: true
29+
virtualenvs-in-project: true
30+
virtualenvs-path: .venv
31+
installer-parallel: true
32+
33+
- name: Load cached venv
34+
id: cached-poetry-deps
35+
uses: actions/cache@v4
36+
with:
37+
path: .venv
38+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock', '**/pyproject.toml') }}
39+
40+
- name: Install dependencies
41+
if: steps.cached-poetry-deps.outputs.cache-hit != 'true'
42+
run: make setup-dev
43+
44+
- name: Check formatting (black, isort)
45+
run: make check-format

check.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ CODE_PATHS = grasp tests tasks
88
# Define paths for JSON files
99
JSON_PATHS = $(shell find grasp -name "*.json")
1010

11+
# Minimum acceptable pylint score (0.0 - 10.0). CI will fail if below this.
12+
PYLINT_FAIL_UNDER ?= 8.0
13+
1114
########################################################################################################################
1215
# LINT
1316
########################################################################################################################
@@ -32,7 +35,7 @@ lint-flake8: ## Run flake8 in a controlled environment
3235
.PHONY: lint-pylint-local
3336
lint-pylint-local: ## Analyze the code with pylint using poetry
3437
@echo "Analyzing code with pylint"
35-
poetry run pylint --jobs 0 $(CODE_PATHS)
38+
poetry run pylint --jobs 0 --fail-under=$(PYLINT_FAIL_UNDER) $(CODE_PATHS)
3639

3740
.PHONY: lint-pylint
3841
lint-pylint: ## Run pylint in a controlled environment

grasp/__init__.py

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
"""
77

88
import logging
9-
from typing import Union, Dict, Any
9+
from typing import Any, Dict, Union
1010

11-
from .workflow import Workflow, create_graph
1211
from .configuration import ConfigLoader, load_config
1312
from .exceptions import (
14-
GraSPError,
15-
ValidationError,
16-
ExecutionError,
1713
ConfigurationError,
18-
NodeError,
1914
DataError,
15+
ExecutionError,
16+
GraSPError,
2017
ModelError,
18+
NodeError,
2119
TimeoutError,
20+
ValidationError,
2221
)
2322
from .models import ModelConfigBuilder
23+
from .workflow import Workflow, create_graph
2424

2525
try:
2626
from .core.base_task_executor import BaseTaskExecutor, DefaultTaskExecutor
27-
from .core.judge_task_executor import JudgeQualityTaskExecutor
28-
from .core.resumable_execution import ResumableExecutionManager
2927
from .core.dataset.dataset_processor import DatasetProcessor
3028
from .core.graph.graph_config import GraphConfig
31-
from .core.graph.grasp_state import GraspState
3229
from .core.graph.grasp_message import GraspMessage
30+
from .core.graph.grasp_state import GraspState
31+
from .core.judge_task_executor import JudgeQualityTaskExecutor
32+
from .core.resumable_execution import ResumableExecutionManager
3333

3434
CORE_AVAILABLE = True
3535
except ImportError as e:
@@ -39,11 +39,11 @@
3939
try:
4040
from .core.dataset.dataset_config import (
4141
DataSourceConfig,
42-
OutputConfig,
4342
DataSourceType,
43+
OutputConfig,
4444
OutputType,
45-
TransformConfig,
4645
ShardConfig,
46+
TransformConfig,
4747
)
4848
from .core.dataset.file_handler import FileHandler
4949
from .core.dataset.huggingface_handler import HuggingFaceHandler
@@ -54,9 +54,9 @@
5454

5555
# Node modules
5656
try:
57-
from .core.graph.nodes.base_node import BaseNode, NodeType, NodeState
58-
from .core.graph.nodes.llm_node import LLMNode as CoreLLMNode
5957
from .core.graph.nodes.agent_node import AgentNode as CoreAgentNode
58+
from .core.graph.nodes.base_node import BaseNode, NodeState, NodeType
59+
from .core.graph.nodes.llm_node import LLMNode as CoreLLMNode
6060
from .core.graph.nodes.multi_llm_node import MultiLLMNode as CoreMultiLLMNode
6161
from .core.graph.nodes.weighted_sampler_node import (
6262
WeightedSamplerNode as CoreWeightedSamplerNode,
@@ -69,10 +69,10 @@
6969
# Model factory modules
7070
try:
7171
from .core.models.model_factory import ModelFactory
72+
from .core.models.structured_output.schemas_factory import SimpleResponse
7273
from .core.models.structured_output.structured_output_config import (
7374
StructuredOutputConfig,
7475
)
75-
from .core.models.structured_output.schemas_factory import SimpleResponse
7676

7777
MODELS_AVAILABLE = True
7878
except ImportError:
@@ -81,12 +81,12 @@
8181
# Utility modules
8282
try:
8383
from . import utils
84-
from .utils import constants
8584
from .logger.logger_config import (
8685
logger,
87-
set_external_logger,
8886
reset_to_internal_logger,
87+
set_external_logger,
8988
)
89+
from .utils import constants
9090

9191
UTILS_AVAILABLE = True
9292
except ImportError:
@@ -95,12 +95,12 @@
9595
# Import node builders
9696
try:
9797
from .nodes import (
98-
LLMNodeBuilder,
9998
AgentNodeBuilder,
100-
MultiLLMNodeBuilder,
10199
LambdaNodeBuilder,
102-
WeightedSamplerNodeBuilder,
100+
LLMNodeBuilder,
101+
MultiLLMNodeBuilder,
103102
SubgraphNodeBuilder,
103+
WeightedSamplerNodeBuilder,
104104
)
105105

106106
NODE_BUILDERS_AVAILABLE = True
@@ -110,10 +110,10 @@
110110
# Import data utilities
111111
try:
112112
from .data import (
113-
DataSource,
114113
DataSink,
115-
DataSourceFactory,
116114
DataSinkFactory,
115+
DataSource,
116+
DataSourceFactory,
117117
from_file,
118118
from_huggingface,
119119
to_file,
@@ -161,12 +161,7 @@ def quick_multi_llm(
161161
models: Dict[str, str], prompt: str, data_source: str, output: str = "output.json"
162162
):
163163
"""Quick multi-LLM workflow creation."""
164-
return (
165-
Workflow("quick_multi_llm")
166-
.source(data_source)
167-
.multi_llm(models, prompt)
168-
.sink(output)
169-
)
164+
return Workflow("quick_multi_llm").source(data_source).multi_llm(models, prompt).sink(output)
170165

171166

172167
def execute_task(task_name: str, **kwargs):
@@ -203,17 +198,14 @@ def create_chat_workflow(name: str, conversation_type: str = "multiturn") -> Wor
203198
return workflow
204199

205200

206-
def create_structured_schema(
207-
fields: Dict[str, str], name: str = "CustomSchema"
208-
) -> Dict[str, Any]:
201+
def create_structured_schema(fields: Dict[str, str], name: str = "CustomSchema") -> Dict[str, Any]:
209202
"""Create structured output schema configuration."""
210203
return {
211204
"enabled": True,
212205
"schema": {
213206
"name": name,
214207
"fields": {
215-
field_name: {"type": field_type}
216-
for field_name, field_type in fields.items()
208+
field_name: {"type": field_type} for field_name, field_type in fields.items()
217209
},
218210
},
219211
}
@@ -224,9 +216,7 @@ def pydantic_schema(model_class: str) -> Dict[str, Any]:
224216
return {"enabled": True, "schema": model_class}
225217

226218

227-
def create_processor_config(
228-
processor: Union[str, callable], **params
229-
) -> Dict[str, Any]:
219+
def create_processor_config(processor: Union[str, callable], **params) -> Dict[str, Any]:
230220
"""Create processor configuration."""
231221
if callable(processor):
232222
processor_path = f"{processor.__module__}.{processor.__name__}"
@@ -240,9 +230,7 @@ def create_processor_config(
240230
return config
241231

242232

243-
def create_transformation_config(
244-
transform: Union[str, callable], **params
245-
) -> Dict[str, Any]:
233+
def create_transformation_config(transform: Union[str, callable], **params) -> Dict[str, Any]:
246234
"""Create data transformation configuration."""
247235
if callable(transform):
248236
transform_path = f"{transform.__module__}.{transform.__name__}"

grasp/configuration/loader.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
2-
import yaml
3-
from typing import Union, Any
42
from pathlib import Path
3+
from typing import Any, Union
4+
5+
import yaml
56

67
try:
7-
from grasp.utils import utils
8-
from grasp.core.graph.graph_config import GraphConfig
98
from grasp.core.dataset.dataset_config import DataSourceConfig, OutputConfig
9+
from grasp.core.graph.graph_config import GraphConfig
10+
from grasp.utils import utils
1011

1112
UTILS_AVAILABLE = True
1213
except ImportError:
@@ -24,15 +25,11 @@ def load(self, config_path: Union[str, Path, dict[str, Any]]) -> dict[str, Any]:
2425
config_path = Path(config_path)
2526
if not config_path.exists():
2627
if UTILS_AVAILABLE:
27-
task_config_path = utils.get_file_in_task_dir(
28-
config_path.stem, "graph_config.yaml"
29-
)
28+
task_config_path = utils.get_file_in_task_dir(config_path.stem, "graph_config.yaml")
3029
if os.path.exists(task_config_path):
3130
config_path = Path(task_config_path)
3231
else:
33-
raise FileNotFoundError(
34-
f"Configuration file not found: {config_path}"
35-
)
32+
raise FileNotFoundError(f"Configuration file not found: {config_path}")
3633
else:
3734
raise FileNotFoundError(f"Configuration file not found: {config_path}")
3835

0 commit comments

Comments
 (0)