Skip to content

Commit

Permalink
lint: Running black, isort, ruff 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 25, 2024
1 parent c6a602c commit b30301d
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 15 deletions.
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
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
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
3 changes: 0 additions & 3 deletions codypy/cody_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class CodyServer:

async def init(
binary_path: str,
version: str,
Expand Down Expand Up @@ -427,7 +426,6 @@ async def chat(
async def get_remote_repositories(
reader, writer, id: str, configs: Configs, debug_method_map
) -> Any:

return await request_response(
"chat/remoteRepos", id, debug_method_map, reader, writer, configs
)
Expand All @@ -436,7 +434,6 @@ async def get_remote_repositories(
async def receive_webviewmessage(
reader, writer, params, configs: Configs, debug_method_map
) -> Any:

return await request_response(
"webview/receiveMessage",
params,
Expand Down
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
9 changes: 5 additions & 4 deletions codypy/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import os
import platform

Expand Down Expand Up @@ -67,7 +66,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 +128,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 +137,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
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


async def main():

# debug_method_map: Dict[str, Any] = await get_debug_map()

# Create a CodyServer instance and initialize it
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"
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/codypy",
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 b30301d

Please sign in to comment.