Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: Running black, isort, ruff over codebase #5

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 your 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 your file:
```
mv env.example .env
```
Expand All @@ -71,7 +71,7 @@ You are now ready to use codypy!

## Usage as a library

1. Required to set the 'BINARY_PATH' where to download or use the agent binary
1. Required to set the 'BINARY_PATH' where to download or use the agent binary
1. Required to set the 'SRC_ACCESS_TOKEN' env to the API Token from your Sourcegraph account.
1. Set your workspace path in the 'workspaceRootUri' property to your local GitHub repository.
1. Run the example script using `python main.py`.
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
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"
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/codypy",
packages=find_packages(),
entry_points={
'console_scripts': [
'codypy-cli = cli:main',
"console_scripts": [
"codypy-cli = cli:main",
],
},
install_requires=requirements,
Expand Down