Skip to content

Commit

Permalink
framework development
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Feb 9, 2024
1 parent ed9e9e0 commit 26f5f07
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ importlib-metadata = ">=4.8.0"
langchain = "^0.1.6"
poetry-dynamic-versioning = "^1.2.0"
langchain-openai = "^0.0.5"
tabulate = "^0.9.0"

[tool.poetry.group.dev.dependencies]
pytest = {version = ">=7.1.2"}
Expand Down
6 changes: 4 additions & 2 deletions src/codergpt/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Command line interface for CoderGPT."""

import logging
from pathlib import Path
from typing import TextIO, Union

import click

Expand Down Expand Up @@ -37,8 +39,8 @@ def main(verbose: int, quiet: bool):

@main.command()
@click.argument("path", type=click.Path(exists=True))
def inspect(path: str):
"""Inspect pckage to show file-language-map."""
def inspect(path: Union[str, Path, TextIO]):
"""Inspect package to show file-language-map."""
coder = CoderGPT()
coder.inspect_package(path=path)

Expand Down
2 changes: 2 additions & 0 deletions src/codergpt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
SRC = Path(__file__).resolve().parents[1]
PACKAGE_DIR = SRC / "codergpt"
EXTENSION_MAP_FILE = PACKAGE_DIR / "extensions.yaml"
LANGUAGE_MAP_KEY = "language-map"
INSPECTION_HEADERS = ["File", "Language"]
1 change: 1 addition & 0 deletions src/codergpt/explainer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Code explanation module."""
32 changes: 17 additions & 15 deletions src/codergpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import os
from pathlib import Path
from typing import Dict, Union
from typing import Union

import yaml
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from tabulate import tabulate

from codergpt.constants import EXTENSION_MAP_FILE
from codergpt.constants import EXTENSION_MAP_FILE, INSPECTION_HEADERS


class CoderGPT:
Expand Down Expand Up @@ -37,38 +38,39 @@ def __init__(self):
# }
# )

def inspect_package(self, path: Union[str, Path]) -> Dict[str, str]:
"""Inspecting the code and returning a mapping of files to their languages."""
def inspect_package(self, path: Union[str, Path]):
"""Inspecting the code and displaying a mapping of files to their languages in a table."""
print("Inspecting the code.")

with open(EXTENSION_MAP_FILE, "r") as file:
extension_to_language = yaml.safe_load(file)

# Initialize an empty dictionary to store the results
file_language_map = {}

# Convert path to Path object if it's a string
path = Path(path)

# Initialize an empty list to store the results
file_language_list = []

# Check if the path is a directory or a file
if path.is_dir():
# Iterate over all files in the directory and subdirectories
file_language_map = {
str(file): extension_to_language["language-map"].get(file.suffix)
for file in path.rglob("*.*")
if extension_to_language["language-map"].get(file.suffix) is not None
}
for file in path.rglob("*.*"):
language = extension_to_language["language-map"].get(file.suffix)
if language is not None:
file_language_list.append((str(file), language))

elif path.is_file():
# Get the language for the single file
language = extension_to_language["language-map"].get(path.suffix)
if language is not None:
file_language_map[str(path)] = language
file_language_list.append((str(path), language))

else:
print(f"The path {path} is neither a file nor a directory.")
return file_language_map
return file_language_map
return

# Display the results as a table
print(tabulate(file_language_list, headers=INSPECTION_HEADERS))


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions src/codergpt/optimizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Code optimization module."""
1 change: 1 addition & 0 deletions src/codergpt/test_writer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test writing module."""

0 comments on commit 26f5f07

Please sign in to comment.