reposcape


Namereposcape JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryRepository maps for LLMs
upload_time2025-10-06 20:35:56
maintainerNone
docs_urlNone
authorPhilipp Temminghoff
requires_python>=3.12
licenseMIT License Copyright (c) 2024, Philipp Temminghoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RepoScape

[![PyPI License](https://img.shields.io/pypi/l/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Package status](https://img.shields.io/pypi/status/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Monthly downloads](https://img.shields.io/pypi/dm/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Distribution format](https://img.shields.io/pypi/format/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Wheel availability](https://img.shields.io/pypi/wheel/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Python version](https://img.shields.io/pypi/pyversions/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Implementation](https://img.shields.io/pypi/implementation/reposcape.svg)](https://pypi.org/project/reposcape/)
[![Releases](https://img.shields.io/github/downloads/phil65/reposcape/total.svg)](https://github.com/phil65/reposcape/releases)
[![Github Contributors](https://img.shields.io/github/contributors/phil65/reposcape)](https://github.com/phil65/reposcape/graphs/contributors)
[![Github Discussions](https://img.shields.io/github/discussions/phil65/reposcape)](https://github.com/phil65/reposcape/discussions)
[![Github Forks](https://img.shields.io/github/forks/phil65/reposcape)](https://github.com/phil65/reposcape/forks)
[![Github Issues](https://img.shields.io/github/issues/phil65/reposcape)](https://github.com/phil65/reposcape/issues)
[![Github Issues](https://img.shields.io/github/issues-pr/phil65/reposcape)](https://github.com/phil65/reposcape/pulls)
[![Github Watchers](https://img.shields.io/github/watchers/phil65/reposcape)](https://github.com/phil65/reposcape/watchers)
[![Github Stars](https://img.shields.io/github/stars/phil65/reposcape)](https://github.com/phil65/reposcape/stars)
[![Github Repository size](https://img.shields.io/github/repo-size/phil65/reposcape)](https://github.com/phil65/reposcape)
[![Github last commit](https://img.shields.io/github/last-commit/phil65/reposcape)](https://github.com/phil65/reposcape/commits)
[![Github release date](https://img.shields.io/github/release-date/phil65/reposcape)](https://github.com/phil65/reposcape/releases)
[![Github language count](https://img.shields.io/github/languages/count/phil65/reposcape)](https://github.com/phil65/reposcape)
[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/reposcape)](https://github.com/phil65/reposcape)
[![Package status](https://codecov.io/gh/phil65/reposcape/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/reposcape/)
[![PyUp](https://pyup.io/repos/github/phil65/reposcape/shield.svg)](https://pyup.io/repos/github/phil65/reposcape/)

[Read the documentation!](https://phil65.github.io/reposcape/)

# RepoScape

RepoScape is a Python library for mapping and analyzing repository structures with a focus on understanding code dependencies and importance. It parses code files, builds a graph representation, and helps identify important components through various scoring algorithms.

## Installation

```bash
pip install reposcape
```

Requires Python 3.12 or higher.

## Quick Start

```python
from reposcape import RepoMapper, DetailLevel

# Create mapper with default settings
mapper = RepoMapper()

# Generate overview of entire repository
overview = mapper.create_overview(
    repo_path="path/to/repo",
    detail=DetailLevel.SIGNATURES,
    token_limit=2000  # Optional token limit for output
)

# Generate focused view of specific files
focused = mapper.create_focused_view(
    files=["main.py", "utils.py"],
    repo_path="path/to/repo",
    detail=DetailLevel.DOCSTRINGS
)
```

## Core Components

### RepoMapper

The main entry point for repository analysis. Configurable with custom analyzers, scorers, and serializers.

```python
class RepoMapper:
    def __init__(
        self,
        *,
        analyzers: Sequence[CodeAnalyzer] | None = None,
        scorer: GraphScorer | None = None,
        serializer: CodeSerializer | None = None,
    ): ...

    def create_overview(
        self,
        repo_path: str | PathLike[str],
        *,
        token_limit: int | None = None,
        detail: DetailLevel = DetailLevel.SIGNATURES,
        exclude_patterns: list[str] | None = None,
    ) -> str: ...

    def create_focused_view(
        self,
        files: Sequence[str | PathLike[str]],
        repo_path: str | PathLike[str],
        *,
        token_limit: int | None = None,
        detail: DetailLevel = DetailLevel.SIGNATURES,
        exclude_patterns: list[str] | None = None,
    ) -> str: ...
```

### Detail Levels

Control how much information is included in the output:

```python
class DetailLevel(Enum):
    STRUCTURE   # Just names and hierarchy
    SIGNATURES  # Include function/class signatures
    DOCSTRINGS  # Include signatures + docstrings
    FULL_CODE   # Include complete implementations
```

## Code Analysis

RepoScape includes analyzers for different file types:

### PythonAstAnalyzer

Analyzes Python files using AST parsing:
- Extracts classes, functions, methods, variables
- Tracks references between symbols
- Collects docstrings and signatures

```python
analyzer = PythonAstAnalyzer()
nodes = analyzer.analyze_file("main.py")
```

### TextAnalyzer

Basic analyzer for text files:
- Handles .txt, .md, .rst files
- Extracts sections from markdown files
- Preserves file content and first paragraph as docstring

## Importance Scoring

RepoScape offers different algorithms for calculating code importance:

### ReferenceScorer

Simple reference-based scoring that considers:
- Number of incoming references (highest weight)
- Number of outgoing references (medium weight)
- Being referenced by important files (high boost)
- Distance from important files (decreasing boost)

```python
from reposcape.importance import ReferenceScorer

scorer = ReferenceScorer(
    ref_weight=1.0,
    outref_weight=0.5,
    important_ref_boost=2.0,
    distance_decay=0.5,
)
```

### PageRankScorer

Uses the PageRank algorithm to score nodes based on the graph structure:
- Considers connection patterns
- Handles cycles in dependencies
- Supports personalization for focused analysis

```python
from reposcape.importance import PageRankScorer

scorer = PageRankScorer()
```

## Output Serialization

Multiple serializers are available for different output formats:

### MarkdownSerializer

Generates detailed markdown with:
- Hierarchical structure using headers
- Code blocks for signatures/implementations
- Emojis for different node types
- Optional details based on importance scores

### CompactSerializer

Produces a compact, indented format:
- Single line per node
- Indentation shows hierarchy
- Abbreviated signatures
- Good for quick overviews

### TreeSerializer

ASCII tree-style output:
- Uses box-drawing characters
- Shows clear parent-child relationships
- Similar to `tree` command output

Example usage:

```python
from reposcape.serializers import MarkdownSerializer, CompactSerializer, TreeSerializer

# Create mapper with specific serializer
mapper = RepoMapper(serializer=TreeSerializer())
```

## Advanced Usage

### Custom Analyzers

Implement `CodeAnalyzer` for custom file analysis:

```python
class CustomAnalyzer(CodeAnalyzer):
    def can_handle(self, path: str | PathLike[str] | upath.UPath) -> bool:
        return path.endswith(".custom")

    def analyze_file(
        self,
        path: str | PathLike[str] | upath.UPath,
        content: str | None = None
    ) -> list[CodeNode]: ...
```

### Focused Analysis

Analyze specific files and their relationships:

```python
mapper = RepoMapper()

# Focus on specific files
focused_view = mapper.create_focused_view(
    files=["src/core.py", "src/utils.py"],
    repo_path=".",
    detail=DetailLevel.DOCSTRINGS,
    exclude_patterns=["**/test_*.py", "**/__pycache__/*"]
)
```

### Token Limits

Control output size for large repositories:

```python
# Limit output to approximately 2000 tokens
overview = mapper.create_overview(
    repo_path=".",
    token_limit=2000,
    detail=DetailLevel.SIGNATURES
)
```

## Models

### CodeNode

Immutable representation of code elements:

```python
@dataclass(frozen=True)
class CodeNode:
    name: str
    node_type: NodeType
    path: str
    content: str | None = None
    docstring: str | None = None
    signature: str | None = None
    children: Mapping[str, CodeNode] | None = None
    references_to: Sequence[Reference] | None = None
    referenced_by: Sequence[Reference] | None = None
    importance: float = 0.0
```

### NodeType

Available node types:
- DIRECTORY
- FILE
- CLASS
- FUNCTION
- METHOD
- VARIABLE

### Reference

Tracks symbol references:

```python
@dataclass(frozen=True)
class Reference:
    name: str
    path: str
    line: int
    column: int
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "reposcape",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": null,
    "author": "Philipp Temminghoff",
    "author_email": "Philipp Temminghoff <philipptemminghoff@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fc/47/a0189a976a252a62b04111d144d07862a2f317dfc11bd4beee7c6ad4fa89/reposcape-0.2.0.tar.gz",
    "platform": null,
    "description": "# RepoScape\n\n[![PyPI License](https://img.shields.io/pypi/l/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Package status](https://img.shields.io/pypi/status/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Monthly downloads](https://img.shields.io/pypi/dm/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Distribution format](https://img.shields.io/pypi/format/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Wheel availability](https://img.shields.io/pypi/wheel/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Python version](https://img.shields.io/pypi/pyversions/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Implementation](https://img.shields.io/pypi/implementation/reposcape.svg)](https://pypi.org/project/reposcape/)\n[![Releases](https://img.shields.io/github/downloads/phil65/reposcape/total.svg)](https://github.com/phil65/reposcape/releases)\n[![Github Contributors](https://img.shields.io/github/contributors/phil65/reposcape)](https://github.com/phil65/reposcape/graphs/contributors)\n[![Github Discussions](https://img.shields.io/github/discussions/phil65/reposcape)](https://github.com/phil65/reposcape/discussions)\n[![Github Forks](https://img.shields.io/github/forks/phil65/reposcape)](https://github.com/phil65/reposcape/forks)\n[![Github Issues](https://img.shields.io/github/issues/phil65/reposcape)](https://github.com/phil65/reposcape/issues)\n[![Github Issues](https://img.shields.io/github/issues-pr/phil65/reposcape)](https://github.com/phil65/reposcape/pulls)\n[![Github Watchers](https://img.shields.io/github/watchers/phil65/reposcape)](https://github.com/phil65/reposcape/watchers)\n[![Github Stars](https://img.shields.io/github/stars/phil65/reposcape)](https://github.com/phil65/reposcape/stars)\n[![Github Repository size](https://img.shields.io/github/repo-size/phil65/reposcape)](https://github.com/phil65/reposcape)\n[![Github last commit](https://img.shields.io/github/last-commit/phil65/reposcape)](https://github.com/phil65/reposcape/commits)\n[![Github release date](https://img.shields.io/github/release-date/phil65/reposcape)](https://github.com/phil65/reposcape/releases)\n[![Github language count](https://img.shields.io/github/languages/count/phil65/reposcape)](https://github.com/phil65/reposcape)\n[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/reposcape)](https://github.com/phil65/reposcape)\n[![Package status](https://codecov.io/gh/phil65/reposcape/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/reposcape/)\n[![PyUp](https://pyup.io/repos/github/phil65/reposcape/shield.svg)](https://pyup.io/repos/github/phil65/reposcape/)\n\n[Read the documentation!](https://phil65.github.io/reposcape/)\n\n# RepoScape\n\nRepoScape is a Python library for mapping and analyzing repository structures with a focus on understanding code dependencies and importance. It parses code files, builds a graph representation, and helps identify important components through various scoring algorithms.\n\n## Installation\n\n```bash\npip install reposcape\n```\n\nRequires Python 3.12 or higher.\n\n## Quick Start\n\n```python\nfrom reposcape import RepoMapper, DetailLevel\n\n# Create mapper with default settings\nmapper = RepoMapper()\n\n# Generate overview of entire repository\noverview = mapper.create_overview(\n    repo_path=\"path/to/repo\",\n    detail=DetailLevel.SIGNATURES,\n    token_limit=2000  # Optional token limit for output\n)\n\n# Generate focused view of specific files\nfocused = mapper.create_focused_view(\n    files=[\"main.py\", \"utils.py\"],\n    repo_path=\"path/to/repo\",\n    detail=DetailLevel.DOCSTRINGS\n)\n```\n\n## Core Components\n\n### RepoMapper\n\nThe main entry point for repository analysis. Configurable with custom analyzers, scorers, and serializers.\n\n```python\nclass RepoMapper:\n    def __init__(\n        self,\n        *,\n        analyzers: Sequence[CodeAnalyzer] | None = None,\n        scorer: GraphScorer | None = None,\n        serializer: CodeSerializer | None = None,\n    ): ...\n\n    def create_overview(\n        self,\n        repo_path: str | PathLike[str],\n        *,\n        token_limit: int | None = None,\n        detail: DetailLevel = DetailLevel.SIGNATURES,\n        exclude_patterns: list[str] | None = None,\n    ) -> str: ...\n\n    def create_focused_view(\n        self,\n        files: Sequence[str | PathLike[str]],\n        repo_path: str | PathLike[str],\n        *,\n        token_limit: int | None = None,\n        detail: DetailLevel = DetailLevel.SIGNATURES,\n        exclude_patterns: list[str] | None = None,\n    ) -> str: ...\n```\n\n### Detail Levels\n\nControl how much information is included in the output:\n\n```python\nclass DetailLevel(Enum):\n    STRUCTURE   # Just names and hierarchy\n    SIGNATURES  # Include function/class signatures\n    DOCSTRINGS  # Include signatures + docstrings\n    FULL_CODE   # Include complete implementations\n```\n\n## Code Analysis\n\nRepoScape includes analyzers for different file types:\n\n### PythonAstAnalyzer\n\nAnalyzes Python files using AST parsing:\n- Extracts classes, functions, methods, variables\n- Tracks references between symbols\n- Collects docstrings and signatures\n\n```python\nanalyzer = PythonAstAnalyzer()\nnodes = analyzer.analyze_file(\"main.py\")\n```\n\n### TextAnalyzer\n\nBasic analyzer for text files:\n- Handles .txt, .md, .rst files\n- Extracts sections from markdown files\n- Preserves file content and first paragraph as docstring\n\n## Importance Scoring\n\nRepoScape offers different algorithms for calculating code importance:\n\n### ReferenceScorer\n\nSimple reference-based scoring that considers:\n- Number of incoming references (highest weight)\n- Number of outgoing references (medium weight)\n- Being referenced by important files (high boost)\n- Distance from important files (decreasing boost)\n\n```python\nfrom reposcape.importance import ReferenceScorer\n\nscorer = ReferenceScorer(\n    ref_weight=1.0,\n    outref_weight=0.5,\n    important_ref_boost=2.0,\n    distance_decay=0.5,\n)\n```\n\n### PageRankScorer\n\nUses the PageRank algorithm to score nodes based on the graph structure:\n- Considers connection patterns\n- Handles cycles in dependencies\n- Supports personalization for focused analysis\n\n```python\nfrom reposcape.importance import PageRankScorer\n\nscorer = PageRankScorer()\n```\n\n## Output Serialization\n\nMultiple serializers are available for different output formats:\n\n### MarkdownSerializer\n\nGenerates detailed markdown with:\n- Hierarchical structure using headers\n- Code blocks for signatures/implementations\n- Emojis for different node types\n- Optional details based on importance scores\n\n### CompactSerializer\n\nProduces a compact, indented format:\n- Single line per node\n- Indentation shows hierarchy\n- Abbreviated signatures\n- Good for quick overviews\n\n### TreeSerializer\n\nASCII tree-style output:\n- Uses box-drawing characters\n- Shows clear parent-child relationships\n- Similar to `tree` command output\n\nExample usage:\n\n```python\nfrom reposcape.serializers import MarkdownSerializer, CompactSerializer, TreeSerializer\n\n# Create mapper with specific serializer\nmapper = RepoMapper(serializer=TreeSerializer())\n```\n\n## Advanced Usage\n\n### Custom Analyzers\n\nImplement `CodeAnalyzer` for custom file analysis:\n\n```python\nclass CustomAnalyzer(CodeAnalyzer):\n    def can_handle(self, path: str | PathLike[str] | upath.UPath) -> bool:\n        return path.endswith(\".custom\")\n\n    def analyze_file(\n        self,\n        path: str | PathLike[str] | upath.UPath,\n        content: str | None = None\n    ) -> list[CodeNode]: ...\n```\n\n### Focused Analysis\n\nAnalyze specific files and their relationships:\n\n```python\nmapper = RepoMapper()\n\n# Focus on specific files\nfocused_view = mapper.create_focused_view(\n    files=[\"src/core.py\", \"src/utils.py\"],\n    repo_path=\".\",\n    detail=DetailLevel.DOCSTRINGS,\n    exclude_patterns=[\"**/test_*.py\", \"**/__pycache__/*\"]\n)\n```\n\n### Token Limits\n\nControl output size for large repositories:\n\n```python\n# Limit output to approximately 2000 tokens\noverview = mapper.create_overview(\n    repo_path=\".\",\n    token_limit=2000,\n    detail=DetailLevel.SIGNATURES\n)\n```\n\n## Models\n\n### CodeNode\n\nImmutable representation of code elements:\n\n```python\n@dataclass(frozen=True)\nclass CodeNode:\n    name: str\n    node_type: NodeType\n    path: str\n    content: str | None = None\n    docstring: str | None = None\n    signature: str | None = None\n    children: Mapping[str, CodeNode] | None = None\n    references_to: Sequence[Reference] | None = None\n    referenced_by: Sequence[Reference] | None = None\n    importance: float = 0.0\n```\n\n### NodeType\n\nAvailable node types:\n- DIRECTORY\n- FILE\n- CLASS\n- FUNCTION\n- METHOD\n- VARIABLE\n\n### Reference\n\nTracks symbol references:\n\n```python\n@dataclass(frozen=True)\nclass Reference:\n    name: str\n    path: str\n    line: int\n    column: int\n```\n",
    "bugtrack_url": null,
    "license": "MIT License\n         \n         Copyright (c) 2024, Philipp Temminghoff\n         \n         Permission is hereby granted, free of charge, to any person obtaining a copy\n         of this software and associated documentation files (the \"Software\"), to deal\n         in the Software without restriction, including without limitation the rights\n         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n         copies of the Software, and to permit persons to whom the Software is\n         furnished to do so, subject to the following conditions:\n         \n         The above copyright notice and this permission notice shall be included in all\n         copies or substantial portions of the Software.\n         \n         THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n         SOFTWARE.\n         ",
    "summary": "Repository maps for LLMs",
    "version": "0.2.0",
    "project_urls": {
        "Code coverage": "https://app.codecov.io/gh/phil65/reposcape",
        "Discussions": "https://github.com/phil65/reposcape/discussions",
        "Documentation": "https://phil65.github.io/reposcape/",
        "Issues": "https://github.com/phil65/reposcape/issues",
        "Source": "https://github.com/phil65/reposcape"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "79e49bca084f024d9aee1934742ae112e57b6e4aec69b116dd9e27df05ae9c20",
                "md5": "703ddb15bcd7bce330f93ab145d78918",
                "sha256": "98207f4b4b2f806c7846658dae9ac4427b13226eddaceb2e8c8940d949b159dc"
            },
            "downloads": -1,
            "filename": "reposcape-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "703ddb15bcd7bce330f93ab145d78918",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 34571,
            "upload_time": "2025-10-06T20:35:54",
            "upload_time_iso_8601": "2025-10-06T20:35:54.644717Z",
            "url": "https://files.pythonhosted.org/packages/79/e4/9bca084f024d9aee1934742ae112e57b6e4aec69b116dd9e27df05ae9c20/reposcape-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fc47a0189a976a252a62b04111d144d07862a2f317dfc11bd4beee7c6ad4fa89",
                "md5": "75632cc4a439207a5a8c628faa86890b",
                "sha256": "39d7437660bf61620c0e23ed151e2cfd04f611ce597cb4eabda93980799f0f85"
            },
            "downloads": -1,
            "filename": "reposcape-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "75632cc4a439207a5a8c628faa86890b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 23667,
            "upload_time": "2025-10-06T20:35:56",
            "upload_time_iso_8601": "2025-10-06T20:35:56.081085Z",
            "url": "https://files.pythonhosted.org/packages/fc/47/a0189a976a252a62b04111d144d07862a2f317dfc11bd4beee7c6ad4fa89/reposcape-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-06 20:35:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "phil65",
    "github_project": "reposcape",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "reposcape"
}
        
Elapsed time: 1.35166s