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

refactor: refactor module names to avoid function/module name clashes #114

Merged
merged 2 commits into from
Jan 8, 2025
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
8 changes: 4 additions & 4 deletions src/gitingest/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions src/gitingest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/process_query.py → src/query_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/routers/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/routers/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ingest.py → tests/test_query_ingestion.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse_query.py → tests/test_query_parser.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
30 changes: 15 additions & 15 deletions tests/test_clone.py → tests/test_repository_clone.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading