From 291c492d848ca645e3dc241d8b7785ef08539960 Mon Sep 17 00:00:00 2001 From: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:36:08 +0100 Subject: [PATCH 1/2] Refactor module names to avoid function/module name clashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Renamed: - `clone.py` → `repository_clone.py` - `ingest.py` → `repository_ingest.py` - `ingest_from_query.py` → `query_ingestion.py` - `parse_query.py` → `query_parser.py` - Updated import statements accordingly in package `__init__.py` --- src/gitingest/__init__.py | 8 ++--- src/gitingest/cli.py | 4 +-- ...ngest_from_query.py => query_ingestion.py} | 0 .../{parse_query.py => query_parser.py} | 0 .../{clone.py => repository_clone.py} | 0 .../{ingest.py => repository_ingest.py} | 6 ++-- src/{process_query.py => query_processor.py} | 6 ++-- src/routers/dynamic.py | 2 +- src/routers/index.py | 2 +- ...test_ingest.py => test_query_ingestion.py} | 4 +-- ...st_parse_query.py => test_query_parser.py} | 4 +-- ...test_clone.py => test_repository_clone.py} | 30 +++++++++---------- 12 files changed, 33 insertions(+), 33 deletions(-) rename src/gitingest/{ingest_from_query.py => query_ingestion.py} (100%) rename src/gitingest/{parse_query.py => query_parser.py} (100%) rename src/gitingest/{clone.py => repository_clone.py} (100%) rename src/gitingest/{ingest.py => repository_ingest.py} (95%) rename src/{process_query.py => query_processor.py} (97%) rename tests/{test_ingest.py => test_query_ingestion.py} (94%) rename tests/{test_parse_query.py => test_query_parser.py} (98%) rename tests/{test_clone.py => test_repository_clone.py} (83%) diff --git a/src/gitingest/__init__.py b/src/gitingest/__init__.py index 7af7bd8..c592350 100644 --- a/src/gitingest/__init__.py +++ b/src/gitingest/__init__.py @@ -1,8 +1,8 @@ """ Gitingest: A package for ingesting data from git repositories. """ -from gitingest.clone import clone_repo -from gitingest.ingest import ingest -from gitingest.ingest_from_query import run_ingest_query -from gitingest.parse_query import parse_query +from gitingest.query_ingestion import run_ingest_query +from gitingest.query_parser import parse_query +from gitingest.repository_clone import clone_repo +from gitingest.repository_ingest import ingest __all__ = ["run_ingest_query", "clone_repo", "parse_query", "ingest"] diff --git a/src/gitingest/cli.py b/src/gitingest/cli.py index 6a4b470..ada231a 100644 --- a/src/gitingest/cli.py +++ b/src/gitingest/cli.py @@ -4,8 +4,8 @@ import click -from gitingest.ingest import ingest -from gitingest.ingest_from_query import MAX_FILE_SIZE +from gitingest.query_ingestion import MAX_FILE_SIZE +from gitingest.repository_ingest import ingest @click.command() diff --git a/src/gitingest/ingest_from_query.py b/src/gitingest/query_ingestion.py similarity index 100% rename from src/gitingest/ingest_from_query.py rename to src/gitingest/query_ingestion.py diff --git a/src/gitingest/parse_query.py b/src/gitingest/query_parser.py similarity index 100% rename from src/gitingest/parse_query.py rename to src/gitingest/query_parser.py diff --git a/src/gitingest/clone.py b/src/gitingest/repository_clone.py similarity index 100% rename from src/gitingest/clone.py rename to src/gitingest/repository_clone.py diff --git a/src/gitingest/ingest.py b/src/gitingest/repository_ingest.py similarity index 95% rename from src/gitingest/ingest.py rename to src/gitingest/repository_ingest.py index 311fffd..e2cecaa 100644 --- a/src/gitingest/ingest.py +++ b/src/gitingest/repository_ingest.py @@ -5,9 +5,9 @@ import shutil from config import TMP_BASE_PATH -from gitingest.clone import CloneConfig, clone_repo -from gitingest.ingest_from_query import run_ingest_query -from gitingest.parse_query import parse_query +from gitingest.query_ingestion import run_ingest_query +from gitingest.query_parser import parse_query +from gitingest.repository_clone import CloneConfig, clone_repo def ingest( diff --git a/src/process_query.py b/src/query_processor.py similarity index 97% rename from src/process_query.py rename to src/query_processor.py index c67f251..f6c7df8 100644 --- a/src/process_query.py +++ b/src/query_processor.py @@ -7,9 +7,9 @@ from starlette.templating import _TemplateResponse from config import EXAMPLE_REPOS, MAX_DISPLAY_SIZE -from gitingest.clone import CloneConfig, clone_repo -from gitingest.ingest_from_query import run_ingest_query -from gitingest.parse_query import parse_query +from gitingest.query_ingestion import run_ingest_query +from gitingest.query_parser import parse_query +from gitingest.repository_clone import CloneConfig, clone_repo from server_utils import Colors, log_slider_to_size templates = Jinja2Templates(directory="templates") diff --git a/src/routers/dynamic.py b/src/routers/dynamic.py index 54d9184..add89c4 100644 --- a/src/routers/dynamic.py +++ b/src/routers/dynamic.py @@ -4,7 +4,7 @@ from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates -from process_query import process_query +from query_processor import process_query from server_utils import limiter router = APIRouter() diff --git a/src/routers/index.py b/src/routers/index.py index a0b8235..70a3f6d 100644 --- a/src/routers/index.py +++ b/src/routers/index.py @@ -5,7 +5,7 @@ from fastapi.templating import Jinja2Templates from config import EXAMPLE_REPOS -from process_query import process_query +from query_processor import process_query from server_utils import limiter router = APIRouter() diff --git a/tests/test_ingest.py b/tests/test_query_ingestion.py similarity index 94% rename from tests/test_ingest.py rename to tests/test_query_ingestion.py index beb60a7..48edbc2 100644 --- a/tests/test_ingest.py +++ b/tests/test_query_ingestion.py @@ -1,10 +1,10 @@ -""" Tests for the ingest_from_query module """ +""" Tests for the query_ingestion module """ from pathlib import Path from typing import Any from unittest.mock import patch -from gitingest.ingest_from_query import _extract_files_content, _read_file_content, _scan_directory +from gitingest.query_ingestion import _extract_files_content, _read_file_content, _scan_directory def test_scan_directory(temp_directory: Path, sample_query: dict[str, Any]) -> None: diff --git a/tests/test_parse_query.py b/tests/test_query_parser.py similarity index 98% rename from tests/test_parse_query.py rename to tests/test_query_parser.py index ecca306..97a829d 100644 --- a/tests/test_parse_query.py +++ b/tests/test_query_parser.py @@ -1,11 +1,11 @@ -""" Tests for the parse_query module. """ +""" Tests for the query_parser module. """ from pathlib import Path import pytest from gitingest.ignore_patterns import DEFAULT_IGNORE_PATTERNS -from gitingest.parse_query import _parse_patterns, _parse_url, parse_query +from gitingest.query_parser import _parse_patterns, _parse_url, parse_query def test_parse_url_valid_https() -> None: diff --git a/tests/test_clone.py b/tests/test_repository_clone.py similarity index 83% rename from tests/test_clone.py rename to tests/test_repository_clone.py index 67f59a8..892bd04 100644 --- a/tests/test_clone.py +++ b/tests/test_repository_clone.py @@ -1,10 +1,10 @@ -""" Tests for the clone module. """ +""" Tests for the repository_clone module. """ from unittest.mock import AsyncMock, patch import pytest -from gitingest.clone import CloneConfig, _check_repo_exists, clone_repo +from gitingest.repository_clone import CloneConfig, _check_repo_exists, clone_repo @pytest.mark.asyncio @@ -20,8 +20,8 @@ async def test_clone_repo_with_commit() -> None: branch="main", ) - with patch("gitingest.clone._check_repo_exists", return_value=True) as mock_check: - with patch("gitingest.clone._run_git_command", new_callable=AsyncMock) as mock_exec: + with patch("gitingest.repository_clone._check_repo_exists", return_value=True) as mock_check: + with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec: mock_process = AsyncMock() mock_process.communicate.return_value = (b"output", b"error") mock_exec.return_value = mock_process @@ -38,8 +38,8 @@ async def test_clone_repo_without_commit() -> None: """ query = CloneConfig(url="https://github.com/user/repo", local_path="/tmp/repo", commit=None, branch="main") - with patch("gitingest.clone._check_repo_exists", return_value=True) as mock_check: - with patch("gitingest.clone._run_git_command", new_callable=AsyncMock) as mock_exec: + with patch("gitingest.repository_clone._check_repo_exists", return_value=True) as mock_check: + with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec: mock_process = AsyncMock() mock_process.communicate.return_value = (b"output", b"error") mock_exec.return_value = mock_process @@ -61,7 +61,7 @@ async def test_clone_repo_nonexistent_repository() -> None: commit=None, branch="main", ) - with patch("gitingest.clone._check_repo_exists", return_value=False) as mock_check: + with patch("gitingest.repository_clone._check_repo_exists", return_value=False) as mock_check: with pytest.raises(ValueError, match="Repository not found"): await clone_repo(clone_config) mock_check.assert_called_once_with(clone_config.url) @@ -133,8 +133,8 @@ async def test_clone_repo_with_custom_branch() -> None: local_path="/tmp/repo", branch="feature-branch", ) - with patch("gitingest.clone._check_repo_exists", return_value=True): - with patch("gitingest.clone._run_git_command", new_callable=AsyncMock) as mock_exec: + with patch("gitingest.repository_clone._check_repo_exists", return_value=True): + with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec: await clone_repo(clone_config) mock_exec.assert_called_once_with( "git", @@ -158,8 +158,8 @@ async def test_git_command_failure() -> None: url="https://github.com/user/repo", local_path="/tmp/repo", ) - with patch("gitingest.clone._check_repo_exists", return_value=True): - with patch("gitingest.clone._run_git_command", side_effect=RuntimeError("Git command failed")): + with patch("gitingest.repository_clone._check_repo_exists", return_value=True): + with patch("gitingest.repository_clone._run_git_command", side_effect=RuntimeError("Git command failed")): with pytest.raises(RuntimeError, match="Git command failed"): await clone_repo(clone_config) @@ -174,8 +174,8 @@ async def test_clone_repo_default_shallow_clone() -> None: url="https://github.com/user/repo", local_path="/tmp/repo", ) - with patch("gitingest.clone._check_repo_exists", return_value=True): - with patch("gitingest.clone._run_git_command", new_callable=AsyncMock) as mock_exec: + with patch("gitingest.repository_clone._check_repo_exists", return_value=True): + with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec: await clone_repo(clone_config) mock_exec.assert_called_once_with( "git", "clone", "--depth=1", "--single-branch", clone_config.url, clone_config.local_path @@ -193,8 +193,8 @@ async def test_clone_repo_commit_without_branch() -> None: local_path="/tmp/repo", commit="a" * 40, # Simulating a valid commit hash ) - with patch("gitingest.clone._check_repo_exists", return_value=True): - with patch("gitingest.clone._run_git_command", new_callable=AsyncMock) as mock_exec: + with patch("gitingest.repository_clone._check_repo_exists", return_value=True): + with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec: await clone_repo(clone_config) assert mock_exec.call_count == 2 # Clone and checkout calls mock_exec.assert_any_call("git", "clone", "--single-branch", clone_config.url, clone_config.local_path) From 174f2ccdbfe13bba7511db48f450b4ccc11dbded Mon Sep 17 00:00:00 2001 From: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com> Date: Thu, 9 Jan 2025 00:06:29 +0100 Subject: [PATCH 2/2] rebase --- tests/test_query_ingestion.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_query_ingestion.py b/tests/test_query_ingestion.py index 48edbc2..a74e826 100644 --- a/tests/test_query_ingestion.py +++ b/tests/test_query_ingestion.py @@ -42,8 +42,8 @@ def test_read_file_content_with_notebook(tmp_path: Path): notebook_path = tmp_path / "dummy_notebook.ipynb" notebook_path.write_text("{}", encoding="utf-8") # minimal JSON - # Patch the symbol as it is used in ingest_from_query - with patch("gitingest.ingest_from_query.process_notebook") as mock_process: + # Patch the symbol as it is used in query_ingestion + with patch("gitingest.query_ingestion.process_notebook") as mock_process: _read_file_content(notebook_path) mock_process.assert_called_once_with(notebook_path) @@ -52,7 +52,7 @@ def test_read_file_content_with_non_notebook(tmp_path: Path): py_file_path = tmp_path / "dummy_file.py" py_file_path.write_text("print('Hello')", encoding="utf-8") - with patch("gitingest.ingest_from_query.process_notebook") as mock_process: + with patch("gitingest.query_ingestion.process_notebook") as mock_process: _read_file_content(py_file_path) mock_process.assert_not_called()