Skip to content

Commit

Permalink
Refactor module names to avoid function/module name clashes
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
filipchristiansen committed Jan 8, 2025
1 parent 96bc395 commit 5d6d195
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
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 ingest_from_query
from gitingest.parse_query import parse_query
from gitingest.query_ingestion import ingest_from_query
from gitingest.query_parser import parse_query
from gitingest.repository_clone import clone_repo
from gitingest.repository_ingest import ingest

__all__ = ["ingest_from_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 ingest_from_query
from gitingest.parse_query import parse_query
from gitingest.query_ingestion import ingest_from_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
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 ingest_from_query
from gitingest.parse_query import parse_query
from gitingest.query_ingestion import ingest_from_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
30 changes: 15 additions & 15 deletions tests/test_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
4 changes: 2 additions & 2 deletions tests/test_ingest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" Tests for the ingest_from_query module """
""" Tests for the query_ingestion module """

from pathlib import Path
from typing import Any

from gitingest.ingest_from_query import _extract_files_content, _scan_directory
from gitingest.query_ingestion import _extract_files_content, _scan_directory


def test_scan_directory(temp_directory: Path, sample_query: dict[str, Any]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parse_query.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

0 comments on commit 5d6d195

Please sign in to comment.