Skip to content

Commit

Permalink
add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipa Silva committed Aug 23, 2024
1 parent d69c6b3 commit aee6648
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 46 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,3 @@ cython_debug/

.vscode/
polyglot_data/

19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 # Use the ref you want to point at
hooks:
- id: check-added-large-files
args: ["--maxkb=1024"] # throw an error if we try to commit a 1MB or greater file
- id: check-case-conflict # so we don't rename files that will break case insensitive filesystems
- id: check-merge-conflict # don't accidentally commit files with incomplete merges
- id: end-of-file-fixer # makes all files end in a newline
- id: mixed-line-ending # fixes mixed line endings automatically
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.2
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ help:
@python -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)

api:
fastapi dev labs/api/main.py
fastapi dev labs/api/main.py
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ services:


volumes:
db-data: { }
db-data: { }
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:
- pip:
- python-dotenv
- awscli
- -e .
- -e .
57 changes: 31 additions & 26 deletions labs/fnmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
The function translate(PATTERN) returns a regular expression
corresponding to PATTERN. (It does not compile it.)
"""

import os
import os.path
import posixpath
import re
#import functools
# import functools

__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]


def fnmatch(name, pat):
"""Test whether FILENAME matches PATTERN.
Expand All @@ -36,16 +38,18 @@ def fnmatch(name, pat):
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)

#@functools.lru_cache(maxsize=256, typed=True)

# @functools.lru_cache(maxsize=256, typed=True)
def _compile_pattern(pat):
if isinstance(pat, bytes):
pat_str = str(pat, 'ISO-8859-1')
pat_str = str(pat, "ISO-8859-1")
res_str = translate(pat_str)
res = bytes(res_str, 'ISO-8859-1')
res = bytes(res_str, "ISO-8859-1")
else:
res = translate(pat)
return re.compile(res).match


def filter(names, pat):
"""Return the subset of the list NAMES that match PAT."""
result = []
Expand All @@ -62,6 +66,7 @@ def filter(names, pat):
result.append(name)
return result


def fnmatchcase(name, pat):
"""Test whether FILENAME matches PATTERN, including case.
Expand All @@ -79,33 +84,33 @@ def translate(pat):
"""

i, n = 0, len(pat)
res = ''
res = ""
while i < n:
c = pat[i]
i = i+1
if c == '*':
res = res + '.*'
elif c == '?':
res = res + '.'
elif c == '[':
i = i + 1
if c == "*":
res = res + ".*"
elif c == "?":
res = res + "."
elif c == "[":
j = i
if j < n and pat[j] == '!':
j = j+1
if j < n and pat[j] == ']':
j = j+1
while j < n and pat[j] != ']':
j = j+1
if j < n and pat[j] == "!":
j = j + 1
if j < n and pat[j] == "]":
j = j + 1
while j < n and pat[j] != "]":
j = j + 1
if j >= n:
res = res + '\\['
res = res + "\\["
else:
stuff = pat[i:j].replace('\\','\\\\')
i = j+1
if stuff[0] == '!':
stuff = '^' + stuff[1:]
elif stuff[0] == '^':
stuff = '\\' + stuff
res = '%s[%s]' % (res, stuff)
stuff = pat[i:j].replace("\\", "\\\\")
i = j + 1
if stuff[0] == "!":
stuff = "^" + stuff[1:]
elif stuff[0] == "^":
stuff = "\\" + stuff
res = "%s[%s]" % (res, stuff)
else:
res = res + re.escape(c)
# Original patterns is undefined, see http://bugs.python.org/issue21464
return '(?ms)' + res + '\Z'
return "(?ms)" + res + "\Z"
2 changes: 0 additions & 2 deletions labs/github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class GithubRequests:
"""Class to handle Github API requests"""

def __init__(self, github_token, repo_owner, repo_name, user_name=None):

self.github_token = github_token
self.repo_owner = repo_owner
self.repo_name = repo_name
Expand Down Expand Up @@ -142,7 +141,6 @@ def commit_changes(self, message, branch_name, files):

tree_items = []
for file_path in files:

file_name = file_path.replace(f"{self.directory_dir}/", "")
# Step 3: Read the file content and encode it in Base64
with open(file_path, "rb") as file:
Expand Down
2 changes: 1 addition & 1 deletion labs/nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import spacy

# Do not remove this import as it is used for self.nlp.add_pipe("spacytextblob")
from spacytextblob.spacytextblob import SpacyTextBlob
from spacytextblob.spacytextblob import SpacyTextBlob # noqa: F401
from spacy.lang.en.stop_words import STOP_WORDS as stop_words_en
from spacy.lang.pt.stop_words import STOP_WORDS as stop_words_pt
from string import punctuation
Expand Down
8 changes: 0 additions & 8 deletions labs/test/test_GithubRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@


class TestGithubRequests:

# Listing issues with default parameters returns open issues assigned to the user
def test_list_issues_default_parameters(self, mocker):

mock_get = mocker.patch("requests.get")

sample_response = [
Expand Down Expand Up @@ -40,7 +38,6 @@ def test_list_issues_default_parameters(self, mocker):
)

def test_list_issues_http_failure(self, mocker):

mock_response = mocker.Mock()
mock_response.raise_for_status.side_effect = (
requests.exceptions.RequestException("HTTP Error")
Expand All @@ -56,7 +53,6 @@ def test_list_issues_http_failure(self, mocker):
assert issues == []

def test_get_issue_returns_correct_details(self, mocker):

mock_get = mocker.patch("requests.get")

sample_response = {"id": 1, "title": "Sample Issue", "state": "open"}
Expand All @@ -81,7 +77,6 @@ def test_get_issue_returns_correct_details(self, mocker):
)

def test_handle_http_request_failure_get_issue(self, mocker):

mock_response = mocker.Mock()
mock_response.raise_for_status.side_effect = (
requests.exceptions.RequestException("Mocked Request Exception")
Expand All @@ -97,7 +92,6 @@ def test_handle_http_request_failure_get_issue(self, mocker):
assert issue is None

def test_change_issue_status(self, mocker):

mock_response = mocker.Mock()
mock_response.json.return_value = {"status": "closed"}
mocker.patch("requests.patch", return_value=mock_response)
Expand All @@ -111,7 +105,6 @@ def test_change_issue_status(self, mocker):
assert response == {"status": "closed"}

def test_commit_changes_successfully(self, mocker):

mock_response_get = mocker.Mock()
mock_response_get.status_code = 200
mock_response_get.json.return_value = {
Expand Down Expand Up @@ -158,7 +151,6 @@ def test_commit_changes_successfully(self, mocker):
assert result == {"sha": "fake_update_sha"}

def test_create_pull_request_default_parameters(self, mocker):

mock_response = mocker.Mock()
expected_json = {"id": 123, "title": "New Pull Request"}
mock_response.json.return_value = expected_json
Expand Down
3 changes: 0 additions & 3 deletions labs/test/test_middleman.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestCallLlmWithContext:

# Successfully calls the LLM with the provided context and returns the expected output
@patch("middleman_functions.find_similar_embeddings")
@patch.object(RequestLiteLLM, "completion_without_proxy")
Expand All @@ -15,7 +14,6 @@ class TestCallLlmWithContext:
def test_successful_llm_call_with_context(
self, mocked_agent, mocked_vectorized, mocked_completion, mocked_embeddings
):

# Mocking dependencies
mocked_embeddings.return_value = [["file1", "/path/to/file1", "content1"]]
mocked_completion.return_value = (
Expand All @@ -35,7 +33,6 @@ def test_successful_llm_call_with_context(
# Ensure the GithubModel is instantiated correctly with the correct parameters

def test_empty_summary(self):

github = GithubModel(github_token="token", repo_owner="owner", repo_name="repo")
issue_summary = ""
litellm_api_key = "fake_api_key"
Expand Down
4 changes: 3 additions & 1 deletion middleman_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def call_llm_with_context(github: GithubModel, issue_summary, litellm_api_key):
raise ValueError("issue_summary cannot be empty")
litellm_requests = RequestLiteLLM(litellm_api_key)
destination = f"/tmp/{github.repo_owner}/{github.repo_name}"
vectorize_to_db(f"https://github.com/{github.repo_owner}/{github.repo_name}", None, destination)
vectorize_to_db(
f"https://github.com/{github.repo_owner}/{github.repo_name}", None, destination
)
# find_similar_embeddings narrows down codebase to files that matter for the issue at hand.
context = find_similar_embeddings(issue_summary)
prompt = f"""
Expand Down
Loading

0 comments on commit aee6648

Please sign in to comment.