Skip to content

Commit a637bf4

Browse files
authored
ci(dspy): Add Ruff linting workflow (#538)
* Add Ruff linting workflow * Update GitHub Actions workflows * Make ruff apply but not fail * Style fixes by Ruff * Combine Workflows * Add caching * Add import related rules * Automatic Style fixes * Try and fix caching * Fix import * Use natve python dep caching * Update actions/checkout to v4 * Use autofix in tests * Try to cache "install poetry" * Empty-Commit to test caching * Remove workflow deps * Rename action * Update workflow name * Fix Docker stop command and subprocess run check * Fix functional imports --------- Co-authored-by: isaacbmiller <isaacbmiller@users.noreply.github.com>
1 parent 71ac993 commit a637bf4

File tree

102 files changed

+428
-293
lines changed

Some content is hidden

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

102 files changed

+428
-293
lines changed

.github/workflows/run_tests.yml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Run Tests
1+
name: Fix, Test, and Build
22

33
on:
44
push:
@@ -10,38 +10,78 @@ env:
1010
POETRY_VERSION: "1.6.1"
1111

1212
jobs:
13+
fix:
14+
name: Apply Ruff Fix
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: actions/setup-python@v5
21+
- uses: chartboost/ruff-action@v1
22+
with:
23+
args: --fix-only
24+
- uses: stefanzweifel/git-auto-commit-action@v5
25+
with:
26+
commit_message: "Automatic Style fixes"
27+
1328
test:
14-
name: Test
29+
name: Run Tests
1530
runs-on: ubuntu-latest
1631
strategy:
1732
matrix:
1833
python-version: ["3.9"]
1934
steps:
20-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.head_ref }}
38+
- name: Load cached Poetry installation
39+
id: cached-poetry
40+
uses: actions/cache@v3
41+
with:
42+
path: ~/.local
43+
key: poetry-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}
44+
- name: Install Poetry
45+
if: steps.cached-poetry.outputs.cache-hit != 'true'
46+
uses: snok/install-poetry@v1
2147
- name: Set up python ${{ matrix.python-version }}
2248
uses: actions/setup-python@v5
2349
with:
2450
python-version: ${{ matrix.python-version }}
25-
- name: Install Poetry
26-
uses: snok/install-poetry@v1
51+
cache: "poetry"
2752
- name: Install dependencies
28-
run: poetry install
53+
run: poetry install --no-interaction --no-root
54+
- name: Run lint with tests
55+
uses: chartboost/ruff-action@v1
56+
with:
57+
args: --fix-only
2958
- name: Run tests with pytest
3059
run: poetry run pytest tests/
60+
3161
build_poetry:
3262
name: Build Poetry
3363
runs-on: ubuntu-latest
3464
strategy:
3565
matrix:
3666
python-version: ["3.9"]
3767
steps:
38-
- uses: actions/checkout@v3
68+
- uses: actions/checkout@v4
69+
with:
70+
ref: ${{ github.head_ref }}
71+
- name: Load cached Poetry installation
72+
id: cached-poetry
73+
uses: actions/cache@v3
74+
with:
75+
path: ~/.local
76+
key: poetry-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}
77+
- name: Install Poetry
78+
if: steps.cached-poetry.outputs.cache-hit != 'true'
79+
uses: snok/install-poetry@v1
3980
- name: Set up python ${{ matrix.python-version }}
4081
uses: actions/setup-python@v5
4182
with:
4283
python-version: ${{ matrix.python-version }}
43-
- name: Install Poetry
44-
uses: snok/install-poetry@v1
84+
cache: "poetry"
4585
- name: Build
4686
run: poetry build
4787
- name: Install built package
@@ -50,17 +90,30 @@ jobs:
5090
run: python -c "import dspy"
5191
- name: Test import dsp
5292
run: python -c "import dsp"
93+
5394
build_setup:
5495
name: Build Setup
5596
runs-on: ubuntu-latest
5697
strategy:
5798
matrix:
5899
python-version: ["3.9"]
59100
steps:
60-
- uses: actions/checkout@v3
101+
- uses: actions/checkout@v4
102+
with:
103+
ref: ${{ github.head_ref }}
104+
- name: Load cached Poetry installation
105+
id: cached-poetry
106+
uses: actions/cache@v3
107+
with:
108+
path: ~/.local
109+
key: poetry-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}
110+
- name: Install Poetry
111+
if: steps.cached-poetry.outputs.cache-hit != 'true'
112+
uses: snok/install-poetry@v1
61113
- name: Set up python ${{ matrix.python-version }}
62114
uses: actions/setup-python@v5
63115
with:
64116
python-version: ${{ matrix.python-version }}
117+
cache: "poetry"
65118
- name: Run setup.py build
66119
run: python setup.py build

dsp/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from .templates import *
44
from .utils import settings
55

6-
76
"""
87
TODO:
98

dsp/evaluation/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
import dsp
3-
import tqdm
42
import pandas as pd
3+
import tqdm
4+
5+
import dsp
56

67
try:
78
from IPython.display import display as ipython_display

dsp/modules/__init__.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
from .cache_utils import *
21
from .azure_openai import AzureOpenAI
3-
from .gpt3 import *
2+
from .bedrock import *
3+
from .cache_utils import *
4+
from .clarifai import *
5+
from .cohere import *
6+
from .colbertv2 import ColBERTv2
47
from .databricks import *
8+
from .google import *
9+
from .gpt3 import *
510
from .hf import HFModel
6-
from .colbertv2 import ColBERTv2
7-
from .sentence_vectorizer import *
8-
from .cohere import *
9-
from .sbert import *
10-
from .pyserini import *
11+
from .hf_client import Anyscale, HFClientTGI, Together
1112
from .ollama import *
12-
from .clarifai import *
13-
from .bedrock import *
14-
from .google import *
15-
16-
17-
from .hf_client import HFClientTGI
18-
from .hf_client import Anyscale
19-
from .hf_client import Together
13+
from .pyserini import *
14+
from .sbert import *
15+
from .sentence_vectorizer import *

dsp/modules/aws_lm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
from __future__ import annotations
66

7-
from abc import abstractmethod
7+
import json
88
import logging
9+
from abc import abstractmethod
910
from typing import Any, Literal
10-
import json
11+
1112
from dsp.modules.lm import LM
1213

1314
# Heuristic translating number of chars to tokens

dsp/modules/azurecognitivesearch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Union, Any
1+
from typing import Any, Union
22

33
from dsp.utils import dotdict
4+
45
try:
56
from azure.core.credentials import AzureKeyCredential
67
from azure.search.documents import SearchClient

dsp/modules/bedrock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import Any
43
import json
4+
from typing import Any
5+
56
from dsp.modules.aws_lm import AWSLM
67

78

dsp/modules/cache_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import os
2-
2+
from functools import wraps
33
from pathlib import Path
4+
45
from joblib import Memory
5-
from functools import wraps
66

77
from dsp.utils import dotdict
88

9-
109
cache_turn_on = True
1110

1211

dsp/modules/clarifai.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from dsp.modules.lm import LM
55

6+
67
class ClarifaiLLM(LM):
78
"""Integration to call models hosted in clarifai platform.
89

dsp/modules/cohere.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
from typing import Any, Optional
3+
34
import backoff
45

56
from dsp.modules.lm import LM

0 commit comments

Comments
 (0)