Skip to content

Commit

Permalink
Refactor codebase to improve readability and maintainability.
Browse files Browse the repository at this point in the history
  • Loading branch information
eli64s committed Jun 16, 2023
1 parent 18cf305 commit 2519108
Show file tree
Hide file tree
Showing 23 changed files with 534 additions and 461 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Makefile commands for README-AI
# Makefile

SHELL = /bin/bash
VENV := readmeai
VENV := readme_ai

.PHONY: help style clean conda venv mem_profile profile
.PHONY: help style clean conda venv profile snakeviz

# Help
help:
Expand All @@ -18,9 +18,12 @@ help:
# Style
.PHONY: style
style:
-autoflake --remove-all-unused-imports --in-place --recursive .
-autopep8 --in-place --recursive .
-black .
-flake8
-isort .
-yapf -i -r .

# Clean
.PHONY: clean
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@

## 🤖 Overview

README-AI is a powerful, user-friendly tool that automatically generates high-quality README files for your Git repositories using OpenAI's language model APIs. By simply providing the path or url to your project's codebase, this tool will craft a well-structured and comprehensive README that highlights your project's features, installation steps, usage instructions, and more.
README-AI is a powerful, user-friendly tool that generates extensive README markdown documents for your software and data projects. By simply providing a remote repository URL or directory path to your codebase, this tool will document your entire codebase, harnessing the capabilities of large language models via OpenAI's GPT APIs.

README-AI simplifies the process of writing and maintaining high-quality project documentation. My aim for this project is to provide a tool that supports developers, making software development more efficient and user-friendly. Ultimately, the goal of README-AI is to improve the adoption rate and usability of open-source projects, helping all skill levels better understand and use codebases, and allowing everyone to focus on tasks that matter most to you!

> ⚠️ **Note:**
>
Expand Down
20 changes: 11 additions & 9 deletions conf/conf.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# OpenAI API Configuration
# OpenAI API Settings
[api]
endpoint = "https://api.openai.com/v1/chat/completions"
engine = "gpt-3.5-turbo"
temperature = 1.2
tokens = 520
encoding = "cl100k_base"
rate_limit = 5
tokens = 600
tokens_max = 4000
temperature = 0.9

# Repository Configuration
# Repository
[git]
hosts = ["github.com", "gitlab.com"]
name = "README-AI"
Expand All @@ -18,7 +21,7 @@ dependency_files = "dependency_files.toml"
ignore_files = "ignore_files.toml"
language_names = "language_names.toml"
language_setup = "language_setup.toml"
readme = "README_AI.md"
readme = "readme_ai.md"

# Prompts
[prompts]
Expand All @@ -28,7 +31,7 @@ Aim for precision and conciseness in your explanation, ensuring a fine balance b
Limit your response to 3-4 sentences.
Thank you!
"""
features = """Please analyze the codebase located at {} and provide a list of important features. The following includes a list of the summaries of the files in the repository:
features = """Hello! Please analyze the codebase located at {} and provide a list of important features. The following includes a list of the summaries of the files in the repository:
\n{}\n
Please consider the codebase as a whole and highlight its key characteristics, design patterns, architectural decisions, and any other noteworthy elements.
Generate your response as a Markdown table with the following columns:
Expand Down Expand Up @@ -132,7 +135,7 @@ ending = """
> - [X] [📌 Task 1: Implement X]
> - [ ] [📌 Task 2: Refactor Y]
> - [ ] [📌 Task 3: Optimize Z]
> - [ ] ...
> - [ ] [📌 Task 4: Fix Bug A]
\n---
Expand All @@ -154,8 +157,7 @@ git commit -m 'Implemented new feature.'
```sh
git push origin new-feature-branch
```
7. Create a pull request to the original repository.
Open a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary.
7. Create a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary.
The project maintainers will review your changes and provide feedback or merge them into the main branch.
---
Expand Down
60 changes: 30 additions & 30 deletions docs/README_PyFlink.md

Large diffs are not rendered by default.

30 changes: 25 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Black formatting
# Autoflake
[tool.autoflake]
ignore_pass_statements = true
ignore-pass-after-docstring = true
remove_all_unused_imports = true
recursive = true

# Autopep8
[tool.autopep8]
max-line-length = 88

# Black
[tool.black]
line-length = 79
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
Expand All @@ -21,12 +32,14 @@ exclude = '''

# Flake8
[flake8]
max-line-length = 79
max-line-length = 88


# iSort
[tool.isort]
profile = "black"
line_length = 79
line_length = 88
lines_after_imports = 2
multi_line_output = 3
include_trailing_comma = true
virtual_env = "conda"
Expand All @@ -37,10 +50,17 @@ testpaths = ["tests"]
python_files = "test_*.py"
addopts = "--strict-markers --disable-pytest-warnings"

# Pytest coverage
# Pytest Coverage
[tool.coverage.run]
omit = [
"tests/*",
"setup.py",
"*/__init__.py"
]

# Yapf
[tool.yapf]
based_on_style = "google"
column_limit = 88
indent_width = 4
dedent_closing_brackets = true
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
packages=find_namespace_packages(),
install_requires=required_packages,
extras_require={
"dev": docs_packages
+ style_packages
+ test_packages
+ ["pre-commit==2.15.0"],
"dev": docs_packages + style_packages + test_packages + ["pre-commit==2.15.0"],
"test": test_packages,
},
classifiers=[
Expand Down
21 changes: 6 additions & 15 deletions src/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def get_badges(svg_icons: dict, dependencies: list) -> str:
if str(dependency).lower() in svg_icons
]
# Sort badges by hex value (from light to dark color)
badges.sort(
key=lambda badge: int(badge[1], 16) if badge[1] else 0, reverse=True
)
badges.sort(key=lambda badge: int(badge[1], 16) if badge[1] else 0, reverse=True)
badges = [badge[0] for badge in badges]

return format_badges(badges)
Expand All @@ -94,7 +92,7 @@ def format_badges(badges: list) -> str:
line = "\n".join(
[
f'<img src="{badge}" alt="{badge.split("/badge/")[1].split("-")[0]}" />'
for badge in badges[i : i + badges_per_line]
for badge in badges[i:i + badges_per_line]
]
)
badge_lines.append(line)
Expand All @@ -105,12 +103,8 @@ def format_badges(badges: list) -> str:
def create_markdown_tables(summaries: tuple) -> pd.DataFrame:
"""Formats the generated code summaries into a DataFrame."""
summary_df = pd.DataFrame(summaries, columns=["Module", "Summary"])
summary_df["Directory"] = summary_df["Module"].apply(
lambda x: str(Path(x).parent)
)
summary_df["File"] = summary_df["Module"].apply(
lambda x: str(Path(x).name)
)
summary_df["Directory"] = summary_df["Module"].apply(lambda x: str(Path(x).parent))
summary_df["File"] = summary_df["Module"].apply(lambda x: str(Path(x).name))
return summary_df


Expand All @@ -123,8 +117,7 @@ def create_setup_guide(

summary_df["Language"] = summary_df["Module"].apply(
lambda x: Path(x).suffix[1:]
if Path(x).suffix[1:] not in conf_helper.ignore_files
else None
if Path(x).suffix[1:] not in conf_helper.ignore_files else None
)

top_language = summary_df["Language"].value_counts().idxmax()
Expand All @@ -147,9 +140,7 @@ def create_setup_guide(
def create_tables(df: pd.DataFrame, dropdown: str) -> str:
"""Creates Markdown tables for each sub-directory in the project."""
df["Sub-Directory"] = df["Module"].apply(
lambda x: str(x).split("/")[-2].capitalize()
if "/" in str(x)
else "Root"
lambda x: str(x).split("/")[-2].capitalize() if "/" in str(x) else "Root"
)
tables = []
for sub_dir_name, group in df.groupby("Sub-Directory"):
Expand Down
10 changes: 5 additions & 5 deletions src/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Configuration constants for the application."""
"""Data classes to store README-AI configuration constants."""

from dataclasses import dataclass, field
from pathlib import Path
Expand All @@ -8,9 +8,6 @@
import dacite

from factory import FileHandler
from logger import Logger

LOGGER = Logger("readmeai_logger")


@dataclass
Expand All @@ -19,8 +16,11 @@ class ApiConfig:

endpoint: str
engine: str
temperature: float
encoding: str
rate_limit: int
tokens: int
tokens_max: int
temperature: float


@dataclass
Expand Down
21 changes: 17 additions & 4 deletions src/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ class WriteFileError(Exception):


class FileHandler:

def __init__(self):
self.file_actions = {
"md": {"read": self.read_markdown, "write": self.write_markdown},
"toml": {"read": self.read_toml, "write": self.write_toml},
"json": {"read": self.read_json, "write": self.write_json},
"yaml": {"read": self.read_yaml, "write": self.write_yaml},
"md": {
"read": self.read_markdown,
"write": self.write_markdown
},
"toml": {
"read": self.read_toml,
"write": self.write_toml
},
"json": {
"read": self.read_json,
"write": self.write_json
},
"yaml": {
"read": self.read_yaml,
"write": self.write_yaml
},
}
self.cache = {}

Expand Down
12 changes: 8 additions & 4 deletions src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ def _configure_logger(self):
logger.configure(
handlers=[
{
"sink": sys.stderr,
"level": self.level,
"colorize": True,
"format": "<level>{time:YYYY-MM-DD HH:mm:ss}</level> | <level>{level}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - {message}",
"sink":
sys.stderr,
"level":
self.level,
"colorize":
True,
"format":
"<level>{time:YYYY-MM-DD HH:mm:ss}</level> | <level>{level}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan>:{message}",
}
]
)
Expand Down
Loading

0 comments on commit 2519108

Please sign in to comment.