Skip to content

Commit

Permalink
Repository file clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
eli64s committed Jan 9, 2024
1 parent 0b70158 commit 2eeb526
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 74 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "readmeai"
version = "0.4.995"
version = "0.4.996"
description = "🎈 Automated README file generator, powered by GPT language model APIs"
authors = ["Eli <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions readmeai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from readmeai.core.preprocess import FileData, process_repository
from readmeai.exceptions import ReadmeGenerationError
from readmeai.markdown.builder import build_readme_md
from readmeai.services.git_utilities import clone_repo_to_temp_dir
from readmeai.services.git_utils import clone_to_temporary_directory

logger = Logger(__name__)

Expand All @@ -36,7 +36,7 @@ async def readme_agent(conf: AppConfig, conf_helper: ConfigHelper) -> None:

try:
with tempfile.TemporaryDirectory() as temp_dir:
await clone_repo_to_temp_dir(repo_url, temp_dir)
await clone_to_temporary_directory(repo_url, temp_dir)
(
file_context,
dependencies,
Expand Down
18 changes: 5 additions & 13 deletions readmeai/markdown/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from readmeai.config.settings import AppConfig
from readmeai.core.factory import FileHandler
from readmeai.core.utils import get_resource_path
from readmeai.services.git_utilities import GitService
from readmeai.services.git_utils import GitService


def _read_badge_file(file_path: str) -> Dict[str, str]:
Expand Down Expand Up @@ -47,9 +47,7 @@ def format_badges(badges: list[str]) -> str:
if badges is None or len_icons == 0:
return ""

badges_per_line = (
len_icons if len_icons < 9 else (len_icons // 2) + (len_icons % 2)
)
badges_per_line = len_icons if len_icons < 9 else (len_icons // 2) + (len_icons % 2)

lines = []
for i in range(0, len_icons, badges_per_line):
Expand All @@ -60,9 +58,7 @@ def format_badges(badges: list[str]) -> str:
]
)
lines.append(
f"{line}\n\t<br>"
if i + badges_per_line < len_icons
else f"{line}\n"
f"{line}\n\t<br>" if i + badges_per_line < len_icons else f"{line}\n"
)

return "\n\t".join(lines)
Expand All @@ -79,9 +75,7 @@ def shields_icons(

metadata_badges = build_metadata_badges(conf, full_name, git_host)

dependency_badges = build_dependency_badges(
deps, badge_set, conf.md.badge_style
)
dependency_badges = build_dependency_badges(deps, badge_set, conf.md.badge_style)
dependency_badges = conf.md.badges_software.format(
align=conf.md.align, badges=dependency_badges
)
Expand Down Expand Up @@ -111,9 +105,7 @@ def skill_icons(conf: AppConfig, deps: list) -> str:
"""
deps.extend(["md"])
icons_dict = _read_badge_file(conf.files.skill_icons)
icons_list = [
icon for icon in icons_dict["icons"]["names"] if icon in deps
]
icons_list = [icon for icon in icons_dict["icons"]["names"] if icon in deps]
skill_icons = ",".join(icons_list)
# per_line = (len(skill_icons) + 2) // 2
# icon_names = f"{icon_names}" # &perline={per_line}"
Expand Down
2 changes: 1 addition & 1 deletion readmeai/markdown/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Tuple

from readmeai.core.logger import Logger
from readmeai.services.git_utilities import fetch_git_file_url
from readmeai.services.git_utils import fetch_git_file_url

logger = Logger(__name__)

Expand Down
12 changes: 6 additions & 6 deletions readmeai/parsers/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def parse(self, content: str) -> List[str]:
dependencies.extend(matches)
# Clean and return unique dependencies
return list(set(dep.strip() for dep in dependencies))
except re.error as excinfo:
self.log_error(f"Error parsing CMakeLists.txt: {str(excinfo)}")
except re.error as exc:
self.log_error(f"Error parsing CMakeLists.txt: {str(exc)}")
return []


Expand All @@ -46,8 +46,8 @@ def parse(self, content: str) -> List[str]:
dep for match in matches for dep in filter(None, match.split())
]
return package_names
except re.error as excinfo:
self.log_error(f"Error parsing Makefile.am: {str(excinfo)}")
except re.error as exc:
self.log_error(f"Error parsing Makefile.am: {str(exc)}")
return []


Expand All @@ -59,6 +59,6 @@ def parse(self, content: str) -> List[str]:
try:
regex = re.compile(r"AC_CHECK_LIB\([^)]+\s+([^)]+)\)")
return regex.findall(content)
except re.error as excinfo:
self.log_error(f"Error parsing configure.ac: {str(excinfo)}")
except re.error as exc:
self.log_error(f"Error parsing configure.ac: {str(exc)}")
return []
2 changes: 1 addition & 1 deletion readmeai/services/git_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import aiohttp

from readmeai.core.logger import Logger
from readmeai.services.git_utilities import fetch_git_api_url
from readmeai.services.git_utils import fetch_git_api_url

logger = Logger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
import shutil
from pathlib import Path

import git

from readmeai.config.settings import GitService
from readmeai.core.logger import Logger
from readmeai.exceptions import GitCloneError

logger = Logger(__name__)

import git

from readmeai.exceptions import GitCloneError


async def clone_repo_to_temp_dir(repo_source: str, temp_dir: str) -> str:
async def clone_to_temporary_directory(repo_source: str, temp_dir: str) -> str:
"""Clone the repository to a temporary directory."""
try:
repo_path = Path(repo_source)

if repo_path.is_file():
raise GitCloneError(repo_source, "Path is a file, not directory.")

if repo_path.is_dir():
elif repo_path.is_dir():
shutil.copytree(repo_path, temp_dir, dirs_exist_ok=True)
else:
git.Repo.clone_from(repo_source, temp_dir, depth=1, single_branch=True)
Expand Down
3 changes: 2 additions & 1 deletion scripts/run_batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ for index in "${!repositories[@]}"; do
alignment=${align[$RANDOM % ${#align[@]}]}
rand_choice=$((RANDOM % 2))

cmd="python3 -m readmeai.cli.commands -o \"$filename\" -r \"$repo\""
#cmd="python3 -m readmeai.cli.commands -o \"$filename\" -r \"$repo\""
cmd="readmeai -o \"$filename\" -r \"$repo\""

if [ "$random_badge" != "default" ]; then
cmd+=" -b \"$random_badge\""
Expand Down
12 changes: 7 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from readmeai.main import readme_agent


@patch("readmeai.main.clone_repo_to_temp_dir")
@patch("readmeai.main.clone_to_temporary_directory")
@patch("readmeai.main.process_repository")
@patch("readmeai.main.ModelHandler")
@patch("readmeai.main.build_readme_md")
Expand All @@ -16,15 +16,15 @@ async def test_readme_agent_normal_flow(
mock_build_readme_md,
mock_model_handler,
mock_process_repository,
mock_clone_repo_to_temp_dir,
mock_clone_to_temporary_directory,
mock_config,
mock_config_helper,
mock_dependencies,
mock_summaries,
tmp_path,
):
"""Test the readme_agent function."""
mock_clone_repo_to_temp_dir.return_value = tmp_path
mock_clone_to_temporary_directory.return_value = tmp_path
mock_process_repository.return_value = (
[Mock(), Mock(), Mock()],
mock_dependencies,
Expand All @@ -39,7 +39,7 @@ async def test_readme_agent_normal_flow(

await readme_agent(mock_config, mock_config_helper)

mock_clone_repo_to_temp_dir.assert_called_once()
mock_clone_to_temporary_directory.assert_called_once()
mock_process_repository.assert_called_once()
mock_model_handler.assert_called_once()
mock_build_readme_md.assert_called_once()
Expand All @@ -48,7 +48,9 @@ async def test_readme_agent_normal_flow(
@pytest.mark.asyncio
async def test_readme_agent_error_handling():
"""Test the readme_agent function."""
with patch("readmeai.services.git_utilities.clone_repo_to_temp_dir") as clone_mock:
with patch(
"readmeai.services.git_utils.clone_to_temporary_directory"
) as clone_mock:
clone_mock.side_effect = Exception("Failed to clone repo")
conf = Mock()
conf_helper = Mock()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_markdown/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
group_summaries_by_folder,
is_valid_tuple_summary,
)
from readmeai.services import git_utilities
from readmeai.services import git_utils


def test_construct_markdown_table(mock_config):
Expand All @@ -32,7 +32,7 @@ def test_create_hyperlink(mock_config):
module = f"readmeai/{file_name}"
full_name = mock_config.git.full_name
repo_url = mock_config.git.repository
repo_file_url = git_utilities.fetch_git_file_url(module, full_name, repo_url)
repo_file_url = git_utils.fetch_git_file_url(module, full_name, repo_url)
hyperlink = create_hyperlink(
file_name,
full_name,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_services/test_git_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def test_git_api_request_success():
repo_owner = "example-owner"
full_name = f"{repo_owner}/{repo_name}"
with patch(
"readmeai.services.git_utilities.fetch_git_api_url",
"readmeai.services.git_utils.fetch_git_api_url",
return_value="api_url",
), patch(
"readmeai.services.git_metadata._fetch_git_metadata",
Expand Down
Loading

0 comments on commit 2eeb526

Please sign in to comment.