reposnap 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reposnap/__init__.py +0 -0
- reposnap/core/__init__.py +0 -0
- reposnap/core/collector.py +21 -0
- reposnap/core/file_system.py +19 -0
- reposnap/core/git_repo.py +14 -0
- reposnap/core/markdown_generator.py +24 -0
- reposnap/interfaces/__init__.py +0 -0
- reposnap/interfaces/cli.py +21 -0
- reposnap/utils/__init__.py +0 -0
- reposnap/utils/path_utils.py +9 -0
- reposnap-0.2.0.dist-info/METADATA +91 -0
- reposnap-0.2.0.dist-info/RECORD +14 -0
- reposnap-0.2.0.dist-info/WHEEL +4 -0
- reposnap-0.2.0.dist-info/licenses/LICENSE +21 -0
reposnap/__init__.py
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# src/reposnap/core/collector.py
|
2
|
+
|
3
|
+
from .file_system import FileSystem
|
4
|
+
from .git_repo import GitRepo
|
5
|
+
from .markdown_generator import MarkdownGenerator
|
6
|
+
import pathspec
|
7
|
+
|
8
|
+
class ProjectContentCollector:
|
9
|
+
def __init__(self, root_dir: str, output_file: str, structure_only: bool, gitignore_patterns: list):
|
10
|
+
self.root_dir = root_dir
|
11
|
+
self.output_file = output_file
|
12
|
+
self.structure_only = structure_only
|
13
|
+
self.spec = pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, gitignore_patterns)
|
14
|
+
self.file_system = FileSystem(root_dir)
|
15
|
+
self.git_repo = GitRepo(root_dir)
|
16
|
+
self.markdown_generator = MarkdownGenerator()
|
17
|
+
|
18
|
+
def collect_and_generate(self):
|
19
|
+
git_files = self.git_repo.get_git_files()
|
20
|
+
tree_structure = self.file_system.build_tree_structure(git_files)
|
21
|
+
self.markdown_generator.generate_markdown(self.output_file, tree_structure, git_files, self.spec, self.structure_only)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# src/reposnap/core/file_system.py
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
|
5
|
+
class FileSystem:
|
6
|
+
def __init__(self, root_dir: str):
|
7
|
+
self.root_dir = Path(root_dir).resolve()
|
8
|
+
|
9
|
+
def build_tree_structure(self, files):
|
10
|
+
tree = {}
|
11
|
+
for file in files:
|
12
|
+
file_path = Path(file).resolve()
|
13
|
+
relative_path = file_path.relative_to(self.root_dir).as_posix()
|
14
|
+
parts = relative_path.split('/')
|
15
|
+
current_level = tree
|
16
|
+
for part in parts[:-1]:
|
17
|
+
current_level = current_level.setdefault(part, {})
|
18
|
+
current_level[parts[-1]] = relative_path
|
19
|
+
return tree
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# src/reposnap/core/git_repo.py
|
2
|
+
|
3
|
+
from git import Repo, InvalidGitRepositoryError
|
4
|
+
|
5
|
+
class GitRepo:
|
6
|
+
def __init__(self, repo_path: str):
|
7
|
+
self.repo_path = repo_path
|
8
|
+
|
9
|
+
def get_git_files(self):
|
10
|
+
try:
|
11
|
+
repo = Repo(self.repo_path)
|
12
|
+
return repo.git.ls_files().splitlines()
|
13
|
+
except InvalidGitRepositoryError:
|
14
|
+
return []
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# src/reposnap/core/markdown_generator.py
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
from ..utils.path_utils import format_tree
|
5
|
+
|
6
|
+
class MarkdownGenerator:
|
7
|
+
def generate_markdown(self, output_file, tree_structure, git_files, spec, structure_only=False):
|
8
|
+
with open(output_file, 'w') as f:
|
9
|
+
f.write("# Project Structure\n\n")
|
10
|
+
f.write("```\n")
|
11
|
+
for line in format_tree(tree_structure):
|
12
|
+
f.write(line)
|
13
|
+
f.write("```\n\n")
|
14
|
+
|
15
|
+
if not structure_only:
|
16
|
+
for file in git_files:
|
17
|
+
relative_path = Path(file).relative_to(Path(output_file).parent).as_posix()
|
18
|
+
if spec and not spec.match_file(relative_path):
|
19
|
+
# Only read the file if spec is not None and does not match
|
20
|
+
with open(Path(output_file).parent / file, 'r') as file_content:
|
21
|
+
f.write(f"## {relative_path}\n\n")
|
22
|
+
f.write(f"```\n{file_content.read()}\n```\n\n")
|
23
|
+
|
24
|
+
print(f"Markdown file generated: {output_file}")
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# src/reposnap/interfaces/cli.py
|
2
|
+
|
3
|
+
import argparse
|
4
|
+
from reposnap.core.collector import ProjectContentCollector
|
5
|
+
|
6
|
+
def main():
|
7
|
+
parser = argparse.ArgumentParser(description='Generate a Markdown representation of a Git repository.')
|
8
|
+
parser.add_argument('path', help='Path to the Git repository.')
|
9
|
+
parser.add_argument('-o', '--output', help='Output Markdown file', default='output.md')
|
10
|
+
parser.add_argument('--structure-only', action='store_true',
|
11
|
+
help='Only include the file structure without content.')
|
12
|
+
args = parser.parse_args()
|
13
|
+
|
14
|
+
with open(f"{args.path}/.gitignore", 'r') as gitignore:
|
15
|
+
patterns = gitignore.readlines()
|
16
|
+
|
17
|
+
collector = ProjectContentCollector(args.path, args.output, args.structure_only, patterns)
|
18
|
+
collector.collect_and_generate()
|
19
|
+
|
20
|
+
if __name__ == "__main__":
|
21
|
+
main()
|
File without changes
|
@@ -0,0 +1,91 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: reposnap
|
3
|
+
Version: 0.2.0
|
4
|
+
Summary: Generate a Markdown file with all contents of your project
|
5
|
+
Author: agoloborodko
|
6
|
+
License-File: LICENSE
|
7
|
+
Requires-Python: >=3.8
|
8
|
+
Requires-Dist: gitpython>=3.1.43
|
9
|
+
Requires-Dist: pathlib>=1.0.1
|
10
|
+
Requires-Dist: pathspec>=0.12.1
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
|
13
|
+
# RepoSnap
|
14
|
+
|
15
|
+
## Overview
|
16
|
+
|
17
|
+
`reposnap` is a Python script designed to generate a Markdown file that documents the structure and contents of a git project. This tool is particularly useful for creating a quick overview of a project's file hierarchy, including optional syntax-highlighted code snippets.
|
18
|
+
|
19
|
+
## Features
|
20
|
+
|
21
|
+
- **Recursive Directory Traversal**: Automatically traverses through all subdirectories of the specified project root.
|
22
|
+
- **File Exclusion**: Supports excluding specific files and directories using patterns similar to `.gitignore`.
|
23
|
+
- **Syntax Highlighting**: Includes syntax highlighting for known file types in the generated Markdown file.
|
24
|
+
- **Structure Only Option**: The `--structure-only` flag can be used to generate the Markdown file with just the directory structure, omitting the contents of the files.
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Command-Line Interface
|
29
|
+
|
30
|
+
To use the `collect.py` script, run it with the following options:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
python -m collect <project_root> [-o OUTPUT] [-e EXCLUDE ...] [-x EXCLUDE_FILE] [--structure-only]
|
34
|
+
```
|
35
|
+
|
36
|
+
- `<project_root>`: The root directory of the project to document.
|
37
|
+
- `-o, --output`: The name of the output Markdown file. Defaults to `repo-content-<timestamp>.md`.
|
38
|
+
- `-e, --exclude`: Patterns of files or directories to exclude (supports multiple patterns).
|
39
|
+
- `-x, --exclude-file`: A file (e.g., `.gitignore`) containing patterns of files or directories to exclude.
|
40
|
+
- `--structure-only`: Generate a Markdown file that includes only the project structure, without file contents.
|
41
|
+
|
42
|
+
### Examples
|
43
|
+
|
44
|
+
1. **Generate a full project structure with file contents**:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
python -m collect my_project/
|
48
|
+
```
|
49
|
+
|
50
|
+
2. **Generate a project structure only**:
|
51
|
+
|
52
|
+
```bash
|
53
|
+
python -m collect my_project/ --structure-only
|
54
|
+
```
|
55
|
+
|
56
|
+
3. **Generate a Markdown file excluding certain files and directories**:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
python -m collect my_project/ -e '*.log' -e 'build/' -o output.md
|
60
|
+
```
|
61
|
+
|
62
|
+
4. **Use exclusion patterns from a `.gitignore` file**:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
python -m collect my_project/ -x .gitignore
|
66
|
+
```
|
67
|
+
|
68
|
+
## Testing
|
69
|
+
|
70
|
+
This project includes unit tests to ensure the correctness of the code:
|
71
|
+
|
72
|
+
- **`test_collect.py`**: Tests the `file_extension_to_language` function, verifying that file extensions are correctly mapped to programming languages for syntax highlighting in the Markdown file.
|
73
|
+
- **`test_cli.py`**: Tests the command-line interface of the `collect.py` script, including the `--structure-only` flag.
|
74
|
+
|
75
|
+
### Running the Tests
|
76
|
+
|
77
|
+
To run the tests, use `rye`:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
rye test
|
81
|
+
```
|
82
|
+
|
83
|
+
This will execute all test cases and provide a summary of the results.
|
84
|
+
|
85
|
+
## Dependencies
|
86
|
+
|
87
|
+
This project uses standard Python libraries and does not require any external dependencies.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
This project is licensed under the MIT License.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
reposnap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
reposnap/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
reposnap/core/collector.py,sha256=R9G7kEjnDNqJ4FztBZq1pl7bKni9T17z27qcaYFLty0,960
|
4
|
+
reposnap/core/file_system.py,sha256=ICz0B4MswDlCCuLJzE7LRuLeiH-kFmsxqSnDrqRTULY,632
|
5
|
+
reposnap/core/git_repo.py,sha256=JYuYnjAg_LBTd5cEXUZnbSiMXisH6JFcr8Ix4od6qCo,371
|
6
|
+
reposnap/core/markdown_generator.py,sha256=xgShE2o5d77_U5MNczrYrWiM5K8YHqmvHy7LcYDx0Ro,1079
|
7
|
+
reposnap/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
reposnap/interfaces/cli.py,sha256=qF25C579BM2wF1fj2D7EEt7siVhztMZFGJknMSCdgXo,842
|
9
|
+
reposnap/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
reposnap/utils/path_utils.py,sha256=lMuZMMIX2lEE1o6V3QqifmyO5dO5fuA5OUXMxSvYcHI,290
|
11
|
+
reposnap-0.2.0.dist-info/METADATA,sha256=sUNQzLumZjTvvP1-N2buQKj4_a6OfXBwpvQUPBfsgk4,3103
|
12
|
+
reposnap-0.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
13
|
+
reposnap-0.2.0.dist-info/licenses/LICENSE,sha256=Aj7WCYBXi98pvi723HPn4GDRyjxToNWb3PC6j1_lnPk,1069
|
14
|
+
reposnap-0.2.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 agoloborodko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|