Skip to content

Commit

Permalink
feat: running black and isort over codebase
Browse files Browse the repository at this point in the history
This commit also introduce the github workflows to run pre-commit hooks
on push and pull requests.
  • Loading branch information
oriordan committed Apr 20, 2024
1 parent c69e31e commit 83b5b8e
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SRC_ACCESS_TOKEN = "Replace with your Sourcegraph access token here"
BINARY_PATH = "Replace with the path to the binary here"
BINARY_PATH = "Replace with the path to the binary here"
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint code

on: [push, pull_request]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-20.04
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ bin
__pycache__
codypy.egg-info/
tests/
.mypy_cache/
.mypy_cache/
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
pip install -r requirements.txt
```

1. Rename the provided `env.example` file to `.env` and set the `SRC_ACCESS_TOKEN` value to your API key and the path `BINARY_PATH` to where the cody agent binary should be downloaded and accessed. Use the following command in Linux to rename you file:
1. Rename the provided `env.example` file to `.env` and set the `SRC_ACCESS_TOKEN` value to your API key and the path `BINARY_PATH` to where the cody agent binary should be downloaded and accessed. Use the following command in Linux to rename you file:
```
mv env.example .env
```
Expand Down
8 changes: 5 additions & 3 deletions codypy/client_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ClientCapabilities(BaseModel):


class AgentSpecs(BaseModel):
name: str = 'cody-agent'
version: str = '0.0.5b'
name: str = "cody-agent"
version: str = "0.0.5b"
workspaceRootUri: str | None = None

# @deprecated Use `workspaceRootUri` instead.
Expand All @@ -61,7 +61,9 @@ class AgentSpecs(BaseModel):
#
# marketingTracking: TelemetryEventMarketingTrackingInput = None

def __init__(self, name='cody-agent', version='0.0.5b', workspaceRootUri="", **data):
def __init__(
self, name="cody-agent", version="0.0.5b", workspaceRootUri="", **data
):
super().__init__(
name=name, version=version, workspaceRootUri=workspaceRootUri, **data
)
Expand Down
12 changes: 6 additions & 6 deletions codypy/cody_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def new_chat(
self._cody_server._writer,
is_debugging,
)

self.chat_id = response

async def _lookup_repo_ids(
Expand Down Expand Up @@ -247,7 +247,7 @@ async def _lookup_repo_ids(
self._cody_server._writer,
is_debugging,
)

for repo in response["repos"]:
self.repos[repo["name"]] = repo
# Whatever we didn't find, add it to a cache with a None
Expand Down Expand Up @@ -328,9 +328,9 @@ async def get_models(
debug_method_map,
self._cody_server._reader,
self._cody_server._writer,
is_debugging
is_debugging,
)

return response

async def set_model(
Expand Down Expand Up @@ -364,7 +364,7 @@ async def set_model(
self._cody_server._writer,
is_debugging,
)

return response

async def chat(
Expand Down Expand Up @@ -410,7 +410,7 @@ async def chat(
self._cody_server._writer,
is_debugging,
)

(speaker, response) = await _show_last_message(result, is_debugging)
if speaker == "" or response == "":
print(f"{RED}--- Failed to submit chat message ---{RESET}")
Expand Down
7 changes: 5 additions & 2 deletions codypy/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,18 @@ async def request_response(
async for response in _handle_server_respones(reader):
if is_debugging and await _hasMethod(response):
recieved_method_name = response["method"]
if recieved_method_name in debug_method_map and debug_method_map[recieved_method_name]:
if (
recieved_method_name in debug_method_map
and debug_method_map[recieved_method_name]
):
print(f"Response: \n\n{response}\n")
if recieved_method_name not in debug_method_map:
print(f"Response: \n\n{response}\n")

if response and await _hasResult(response):
if is_debugging:
print(f"Result: \n\n{response}\n")

return response["result"]

return None
2 changes: 1 addition & 1 deletion codypy/server_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class CodyAgentSpecs(BaseModel):
authenticated: bool | None = None
codyEnabled: bool | None = None
codyVersion: str | None = None
authStatus: AuthStatus | None = None
authStatus: AuthStatus | None = None
8 changes: 5 additions & 3 deletions codypy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ async def _has_file(binary_path: str, cody_agent_bin: str) -> bool:
return os.path.isfile(joined_path_and_file)


async def _check_for_binary_file(binary_path: str, cody_name: str, version: str) -> bool:
async def _check_for_binary_file(
binary_path: str, cody_name: str, version: str
) -> bool:
"""
Checks if a binary file for the Cody agent exists at the specified path.
Expand Down Expand Up @@ -127,7 +129,7 @@ async def _download_binary_to_path(
with open(cody_binaray_path, "wb") as f:
f.write(r.content)
print(f"Downloaded {cody_agent} to {binary_path}")

# set permission to chmod +x for the downloaded file
os.chmod(cody_binaray_path, 0o755)
return True
Expand All @@ -136,4 +138,4 @@ async def _download_binary_to_path(
return False
except requests.exceptions.ConnectionError as err:
print(f"Error connecting to server: {err}")
return False
return False
12 changes: 6 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ async def main():
# Create a CodyServer instance and initialize it with the specified binary path and debugging mode.
print(f"{YELLOW}--- Create Server Connection ---{RESET}")
cody_server: CodyServer = await CodyServer.init(
binary_path=BINARY_PATH, version="0.0.5b", use_tcp = False, is_debugging=False
binary_path=BINARY_PATH, version="0.0.5b", use_tcp=False, is_debugging=False
)

# Create an AgentSpecs instance with the specified workspace root URI and extension configuration.
agent_specs = AgentSpecs(
workspaceRootUri="/home/prinova/CodeProjects/CodyAgentPy",
extensionConfiguration={
"accessToken": SRC_ACCESS_TOKEN,
"codebase": "", #"/home/prinova/CodeProjects/codypy", # github.com/sourcegraph/cody",
"codebase": "", # "/home/prinova/CodeProjects/codypy", # github.com/sourcegraph/cody",
"customConfiguration": {},
},
)
Expand Down Expand Up @@ -67,19 +67,19 @@ async def main():
contextFiles = [
{
"type": "file",
"uri" : {
"uri": {
"fsPath": "/home/prinova/CodeProjects/CodyAgentPy/main.py",
"path": "/home/prinova/CodeProjects/CodyAgentPy/main.py",
}
},
}
]

while True:
message: str = input(f"{GREEN}Human:{RESET} ")
response = await cody_agent.chat(
message=message,
enhanced_context=False, # Set to 'True' if you wish Cody to be codebase aware
contextFiles=contextFiles, # Set to the list of files you want to have context for. See the example above
enhanced_context=False, # Set to 'True' if you wish Cody to be codebase aware
contextFiles=contextFiles, # Set to the list of files you want to have context for. See the example above
is_debugging=False,
)
if response == "":
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[project]
name = "codypy"
description = "Python wrapper binding for Cody Agent"
authors = [{ name = "PriNova", email = "info@prinova.de" }]
readme = "README.md"
requires-python = ">=3.9"
keywords = ["cody", "cody-agent", "sourcegraph", "ai", "assistant"]
dependencies = [
"requests",
"python-dotenv",
"pydantic",
"pydantic_core",
]

[project.optional-dependencies]
dev = [
"black",
"isort",
"pylint",
"ruff",
]

[project.urls]
documentation = "https://github.com/PriNova/codypy/blob/main/README.md"
repository = "https://github.com/PriNova/codypy"

[tool.isort]
profile = "black"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests
python-dotenv
pydantic
pydantic_core
pydantic_core
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import find_packages, setup

# Read the contents of requirements.txt
with open('requirements.txt') as f:
with open("requirements.txt") as f:
requirements = f.read().splitlines()

setup(
Expand All @@ -15,8 +15,8 @@
url="https://github.com/PriNova/CodyAgentPy",
packages=find_packages(),
entry_points={
'console_scripts': [
'codypy-cli = cli:main',
"console_scripts": [
"codypy-cli = cli:main",
],
},
install_requires=requirements,
Expand Down

0 comments on commit 83b5b8e

Please sign in to comment.