repo-to-md 0.1.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.
- repo_to_md/__init__.py +0 -0
- repo_to_md/_core.py +325 -0
- repo_to_md/cli.py +83 -0
- repo_to_md-0.1.0.dist-info/METADATA +145 -0
- repo_to_md-0.1.0.dist-info/RECORD +8 -0
- repo_to_md-0.1.0.dist-info/WHEEL +4 -0
- repo_to_md-0.1.0.dist-info/entry_points.txt +2 -0
- repo_to_md-0.1.0.dist-info/licenses/LICENSE +201 -0
repo_to_md/__init__.py
ADDED
File without changes
|
repo_to_md/_core.py
ADDED
@@ -0,0 +1,325 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import os
|
4
|
+
import re
|
5
|
+
import tempfile
|
6
|
+
import zipfile
|
7
|
+
|
8
|
+
import requests
|
9
|
+
|
10
|
+
import fnmatch
|
11
|
+
import mimetypes
|
12
|
+
from collections import defaultdict
|
13
|
+
from typing import Iterable, List, Set, Sequence, Optional
|
14
|
+
|
15
|
+
import pathspec
|
16
|
+
|
17
|
+
|
18
|
+
GITHUB_ZIP_URL = "https://github.com/{owner}/{repo}/archive/refs/heads/{branch}.zip"
|
19
|
+
REPO_ID_REGEX = re.compile(
|
20
|
+
r"""
|
21
|
+
(?:git@github\.com:|https?://github\.com/)?
|
22
|
+
(?P<owner>[^/]+)/
|
23
|
+
(?P<repo>[^/]+?)(?:\.git)?$
|
24
|
+
""",
|
25
|
+
re.VERBOSE,
|
26
|
+
)
|
27
|
+
|
28
|
+
|
29
|
+
def parse_repo_id(repo_id: str) -> tuple[str, str]:
|
30
|
+
"""Extract owner and repo name from <owner>/<repo> or URL/SSH forms."""
|
31
|
+
m = REPO_ID_REGEX.search(repo_id.strip())
|
32
|
+
if not m:
|
33
|
+
raise ValueError(f"Can't parse GitHub repo from '{repo_id}'")
|
34
|
+
return m.group("owner"), m.group("repo")
|
35
|
+
|
36
|
+
|
37
|
+
def download_and_unpack(owner: str, repo: str, branch: str) -> str:
|
38
|
+
"""Download the branch ZIP and unpack into a temp dir. Returns path to root."""
|
39
|
+
url = GITHUB_ZIP_URL.format(owner=owner, repo=repo, branch=branch)
|
40
|
+
resp = requests.get(url, stream=True)
|
41
|
+
resp.raise_for_status()
|
42
|
+
|
43
|
+
td = tempfile.mkdtemp(prefix="github_to_md_")
|
44
|
+
zip_path = os.path.join(td, "repo.zip")
|
45
|
+
with open(zip_path, "wb") as f:
|
46
|
+
for chunk in resp.iter_content(32_768):
|
47
|
+
f.write(chunk)
|
48
|
+
|
49
|
+
with zipfile.ZipFile(zip_path, "r") as z:
|
50
|
+
z.extractall(td)
|
51
|
+
|
52
|
+
# Find the single subdirectory
|
53
|
+
entries = [d for d in os.listdir(td) if os.path.isdir(os.path.join(td, d))]
|
54
|
+
if len(entries) != 1:
|
55
|
+
raise RuntimeError(f"Unexpected ZIP layout: {entries}")
|
56
|
+
return os.path.join(td, entries[0])
|
57
|
+
|
58
|
+
|
59
|
+
# Popular lock-files that should never be included in the Markdown output
|
60
|
+
_LOCK_FILE_NAMES: Set[str] = {
|
61
|
+
# Node / JS
|
62
|
+
"package-lock.json",
|
63
|
+
"yarn.lock",
|
64
|
+
"pnpm-lock.yaml",
|
65
|
+
"npm-shrinkwrap.json",
|
66
|
+
# Python
|
67
|
+
"poetry.lock",
|
68
|
+
"Pipfile.lock",
|
69
|
+
"poetry.lock",
|
70
|
+
"requirements.lock",
|
71
|
+
"conda-lock.yml",
|
72
|
+
"uv.lock",
|
73
|
+
# Ruby / Bundler
|
74
|
+
"Gemfile.lock",
|
75
|
+
# Rust / Cargo
|
76
|
+
"Cargo.lock",
|
77
|
+
# Go
|
78
|
+
"go.sum",
|
79
|
+
# PHP / Composer
|
80
|
+
"composer.lock",
|
81
|
+
# Swift / CocoaPods
|
82
|
+
"Podfile.lock",
|
83
|
+
# JVM / Gradle & others
|
84
|
+
"gradle.lockfile",
|
85
|
+
"gradle-dependencies.lock",
|
86
|
+
# Dart / Flutter
|
87
|
+
"pubspec.lock",
|
88
|
+
# Elixir
|
89
|
+
"mix.lock",
|
90
|
+
# Terraform
|
91
|
+
"terraform.lock.hcl",
|
92
|
+
# Haskell / Cabal
|
93
|
+
"cabal.project.freeze",
|
94
|
+
# Dotnet
|
95
|
+
"packages.lock.json",
|
96
|
+
# C# NuGet
|
97
|
+
"project.assets.json",
|
98
|
+
# Misc
|
99
|
+
"vcpkg-lock.json",
|
100
|
+
}
|
101
|
+
|
102
|
+
# Common binary / non-text extensions we never want in the output
|
103
|
+
_BINARY_EXTS: Set[str] = {
|
104
|
+
# Images
|
105
|
+
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".tif", ".ico", ".icns", ".webp", ".svg",
|
106
|
+
# Audio / video
|
107
|
+
".mp3", ".wav", ".flac", ".ogg", ".mp4", ".mkv", ".mov", ".avi", ".wmv", ".webm",
|
108
|
+
# Archives / packages
|
109
|
+
".zip", ".tar", ".gz", ".tgz", ".bz2", ".xz", ".lz", ".7z", ".rar",
|
110
|
+
# Fonts
|
111
|
+
".ttf", ".otf", ".woff", ".woff2",
|
112
|
+
# Documents / misc binaries
|
113
|
+
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
|
114
|
+
# Compiled / generated artifacts
|
115
|
+
".class", ".jar", ".war", ".ear", ".dll", ".so", ".dylib", ".exe", ".obj", ".o", ".a", ".bin",
|
116
|
+
".pyc", ".pyo",
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
# ---------------------------------------------------------------------------
|
121
|
+
# Utility helpers
|
122
|
+
# ---------------------------------------------------------------------------
|
123
|
+
|
124
|
+
def _is_binary_by_extension(path: str) -> bool:
|
125
|
+
"""Return True if the filename has a known binary extension."""
|
126
|
+
_, ext = os.path.splitext(path)
|
127
|
+
return ext.lower() in _BINARY_EXTS
|
128
|
+
|
129
|
+
|
130
|
+
def _is_binary_by_content(path: str, read_size: int = 1024) -> bool:
|
131
|
+
"""Detect binary files by reading the first *read_size* bytes."""
|
132
|
+
try:
|
133
|
+
with open(path, "rb") as fp:
|
134
|
+
chunk = fp.read(read_size)
|
135
|
+
if b"\0" in chunk:
|
136
|
+
return True
|
137
|
+
# Fallback: rely on mimetypes – treat text/ * as text
|
138
|
+
mime, _ = mimetypes.guess_type(path)
|
139
|
+
if mime and not mime.startswith("text"):
|
140
|
+
# application/json is fine, treat as text
|
141
|
+
if mime == "application/json":
|
142
|
+
return False
|
143
|
+
return True
|
144
|
+
# Try decoding as UTF-8 – if fails it's likely binary
|
145
|
+
try:
|
146
|
+
chunk.decode("utf-8")
|
147
|
+
except UnicodeDecodeError:
|
148
|
+
return True
|
149
|
+
return False
|
150
|
+
except (FileNotFoundError, PermissionError, OSError):
|
151
|
+
return True
|
152
|
+
|
153
|
+
|
154
|
+
def _is_text_file(path: str) -> bool:
|
155
|
+
"""Return True if *path* appears to be a text file."""
|
156
|
+
return not _is_binary_by_extension(path) and not _is_binary_by_content(path)
|
157
|
+
|
158
|
+
|
159
|
+
def _load_gitignore_spec(repo_root: str) -> pathspec.PathSpec | None:
|
160
|
+
"""Load .gitignore from *repo_root* if present using gitwildmatch rules."""
|
161
|
+
gitignore_path = os.path.join(repo_root, ".gitignore")
|
162
|
+
if not os.path.exists(gitignore_path):
|
163
|
+
return None
|
164
|
+
|
165
|
+
with open(gitignore_path, "r", encoding="utf-8", errors="ignore") as fp:
|
166
|
+
patterns = fp.readlines()
|
167
|
+
return pathspec.PathSpec.from_lines("gitwildmatch", patterns)
|
168
|
+
|
169
|
+
|
170
|
+
# ---------------------------------------------------------------------------
|
171
|
+
# Tree builder
|
172
|
+
# ---------------------------------------------------------------------------
|
173
|
+
|
174
|
+
def _build_tree(repo_root: str, included_files: Iterable[str]) -> str:
|
175
|
+
"""Return a *tree(1)*-like directory layout based on *included_files*.
|
176
|
+
|
177
|
+
*included_files* must be an iterable of paths relative to *repo_root* (using
|
178
|
+
os.sep as separator).
|
179
|
+
"""
|
180
|
+
# Build mapping of directory -> children names
|
181
|
+
children: defaultdict[str, List[str]] = defaultdict(list)
|
182
|
+
for rel_path in included_files:
|
183
|
+
parts = rel_path.split(os.sep)
|
184
|
+
for level in range(len(parts)):
|
185
|
+
parent = os.sep.join(parts[:level])
|
186
|
+
name = parts[level]
|
187
|
+
if name not in children[parent]:
|
188
|
+
children[parent].append(name)
|
189
|
+
|
190
|
+
# Sort the children lists for deterministic output
|
191
|
+
for key in children:
|
192
|
+
children[key].sort()
|
193
|
+
|
194
|
+
lines: List[str] = ["."]
|
195
|
+
|
196
|
+
def _recurse(dir_key: str, prefix: str):
|
197
|
+
entries = children.get(dir_key, [])
|
198
|
+
for idx, name in enumerate(entries):
|
199
|
+
is_last = idx == len(entries) - 1
|
200
|
+
connector = "└── " if is_last else "├── "
|
201
|
+
lines.append(f"{prefix}{connector}{name}")
|
202
|
+
child_key = f"{dir_key}{os.sep}{name}" if dir_key else name
|
203
|
+
if child_key in children:
|
204
|
+
extension = " " if is_last else "│ "
|
205
|
+
_recurse(child_key, prefix + extension)
|
206
|
+
|
207
|
+
_recurse("", "")
|
208
|
+
return "\n".join(lines)
|
209
|
+
|
210
|
+
|
211
|
+
# ---------------------------------------------------------------------------
|
212
|
+
# Core public API
|
213
|
+
# ---------------------------------------------------------------------------
|
214
|
+
|
215
|
+
def _split_filters(items: Optional[Sequence[str]]) -> list[str]:
|
216
|
+
"""Flatten a list of include/exclude CLI values (which may contain ';')"""
|
217
|
+
if not items:
|
218
|
+
return []
|
219
|
+
out: list[str] = []
|
220
|
+
for item in items:
|
221
|
+
if item is None:
|
222
|
+
continue
|
223
|
+
# Split on ';' but keep empty segments out
|
224
|
+
out.extend(seg.strip() for seg in item.split(";") if seg.strip())
|
225
|
+
return out
|
226
|
+
|
227
|
+
|
228
|
+
def _matches_any(rel_path: str, patterns: list[str]) -> bool:
|
229
|
+
"""Return True if *rel_path* matches any of *patterns* using fnmatch/glob rules."""
|
230
|
+
for pat in patterns:
|
231
|
+
pat_clean = pat.rstrip("/")
|
232
|
+
if fnmatch.fnmatch(rel_path, pat_clean):
|
233
|
+
return True
|
234
|
+
if rel_path.startswith(pat_clean + os.sep):
|
235
|
+
return True
|
236
|
+
return False
|
237
|
+
|
238
|
+
|
239
|
+
def repo_to_markdown(
|
240
|
+
path: str,
|
241
|
+
*,
|
242
|
+
includes: Optional[Sequence[str]] = None,
|
243
|
+
excludes: Optional[Sequence[str]] = None,
|
244
|
+
) -> str:
|
245
|
+
"""Return a Markdown string that combines a *tree* output and file contents.
|
246
|
+
|
247
|
+
Args:
|
248
|
+
path: Root of repository to process.
|
249
|
+
includes: Optional list of include patterns (relative to *path*)
|
250
|
+
excludes: Optional list of exclude patterns (relative to *path*)
|
251
|
+
"""
|
252
|
+
path = os.path.abspath(os.path.expanduser(path))
|
253
|
+
gitignore_spec = _load_gitignore_spec(path)
|
254
|
+
|
255
|
+
include_patterns = _split_filters(includes)
|
256
|
+
exclude_patterns = _split_filters(excludes)
|
257
|
+
|
258
|
+
included_files: List[str] = []
|
259
|
+
|
260
|
+
# Walk repository
|
261
|
+
for root, dirs, files in os.walk(path):
|
262
|
+
# Skip .git directory early
|
263
|
+
if ".git" in dirs:
|
264
|
+
dirs.remove(".git")
|
265
|
+
rel_dir = os.path.relpath(root, path)
|
266
|
+
rel_dir = "" if rel_dir == "." else rel_dir
|
267
|
+
|
268
|
+
# Directory pruning when include patterns exist – best-effort optimisation
|
269
|
+
if include_patterns and rel_dir:
|
270
|
+
# if no include pattern overlaps this directory prefix, skip
|
271
|
+
if not any(pat.startswith(rel_dir + os.sep) or rel_dir.startswith(pat.rstrip("/")) for pat in include_patterns):
|
272
|
+
# continue walking; pruning is tricky, so we let loop continue without pruning dirs list for correctness
|
273
|
+
pass
|
274
|
+
|
275
|
+
for fname in files:
|
276
|
+
rel_path = os.path.join(rel_dir, fname) if rel_dir else fname
|
277
|
+
|
278
|
+
# Include / exclude filters
|
279
|
+
if include_patterns:
|
280
|
+
if not _matches_any(rel_path, include_patterns):
|
281
|
+
continue # not in include list
|
282
|
+
|
283
|
+
if exclude_patterns and _matches_any(rel_path, exclude_patterns):
|
284
|
+
continue # explicitly excluded
|
285
|
+
|
286
|
+
# Ignore lock files
|
287
|
+
if os.path.basename(fname) in _LOCK_FILE_NAMES:
|
288
|
+
continue
|
289
|
+
|
290
|
+
# Gitignore patterns
|
291
|
+
if gitignore_spec and gitignore_spec.match_file(rel_path):
|
292
|
+
continue
|
293
|
+
|
294
|
+
abs_path = os.path.join(root, fname)
|
295
|
+
|
296
|
+
# Skip non-text/binary
|
297
|
+
if not _is_text_file(abs_path):
|
298
|
+
continue
|
299
|
+
|
300
|
+
included_files.append(rel_path)
|
301
|
+
|
302
|
+
included_files.sort()
|
303
|
+
|
304
|
+
tree_str = _build_tree(path, included_files)
|
305
|
+
|
306
|
+
project_name = os.path.basename(path)
|
307
|
+
parts: List[str] = []
|
308
|
+
parts.append(f"Directory: {project_name}\n\n")
|
309
|
+
parts.append("Directory Structure:\n")
|
310
|
+
parts.append(tree_str)
|
311
|
+
|
312
|
+
# Append file contents
|
313
|
+
for rel_path in included_files:
|
314
|
+
abs_path = os.path.join(path, rel_path)
|
315
|
+
parts.append("\n\n")
|
316
|
+
parts.append(f"```{os.path.splitext(rel_path)[1].lstrip('.')} # {rel_path}\n")
|
317
|
+
try:
|
318
|
+
with open(abs_path, "r", encoding="utf-8", errors="replace") as fp:
|
319
|
+
parts.append(fp.read())
|
320
|
+
except Exception as exc: # pragma: no cover – unforeseen read errors
|
321
|
+
parts.append(f"<error reading file: {exc}>")
|
322
|
+
parts.append("\n```")
|
323
|
+
|
324
|
+
parts.append("\n\n")
|
325
|
+
return "".join(parts)
|
repo_to_md/cli.py
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
import argparse
|
2
|
+
import sys
|
3
|
+
import os
|
4
|
+
import textwrap
|
5
|
+
|
6
|
+
from ._core import (
|
7
|
+
download_and_unpack,
|
8
|
+
parse_repo_id,
|
9
|
+
repo_to_markdown,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
def _determine_repo_dir(source: str, branch: str) -> str:
|
14
|
+
"""Return a local directory for *source* which can be either a local
|
15
|
+
filesystem path or a GitHub *owner/name* expression. In the latter case the
|
16
|
+
repository is downloaded as a ZIP archive.
|
17
|
+
"""
|
18
|
+
expanded = os.path.expanduser(source)
|
19
|
+
if os.path.exists(expanded):
|
20
|
+
return os.path.abspath(expanded)
|
21
|
+
|
22
|
+
# Treat as GitHub repo ID
|
23
|
+
owner, repo = parse_repo_id(source)
|
24
|
+
return download_and_unpack(owner, repo, branch)
|
25
|
+
|
26
|
+
|
27
|
+
def run():
|
28
|
+
p = argparse.ArgumentParser(
|
29
|
+
prog="repo-to-md",
|
30
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
31
|
+
description=textwrap.dedent(
|
32
|
+
"""
|
33
|
+
Convert a GitHub repository (or a local path) into a single Markdown document
|
34
|
+
containing a *tree* listing and concatenated source files.
|
35
|
+
|
36
|
+
SOURCE can be one of the following:
|
37
|
+
• <owner>/<repo>
|
38
|
+
• https://github.com/<owner>/<repo>.git
|
39
|
+
• git@github.com:<owner>/<repo>.git
|
40
|
+
• /absolute/or/relative/path/to/local/dir
|
41
|
+
"""
|
42
|
+
).strip(),
|
43
|
+
)
|
44
|
+
|
45
|
+
p.add_argument("source", help="GitHub repository or local filesystem path")
|
46
|
+
p.add_argument("-b", "--branch", default="main", help="GitHub branch to download (default: main)")
|
47
|
+
p.add_argument("-o", "--output", metavar="FILE", help="Write Markdown to FILE instead of stdout")
|
48
|
+
p.add_argument(
|
49
|
+
"-i",
|
50
|
+
"--include",
|
51
|
+
metavar="PATTERN",
|
52
|
+
action="append",
|
53
|
+
help="Include pattern(s). May be used multiple times or separated with ';'. When supplied, only matching paths are considered for output.",
|
54
|
+
)
|
55
|
+
p.add_argument(
|
56
|
+
"-e",
|
57
|
+
"--exclude",
|
58
|
+
metavar="PATTERN",
|
59
|
+
action="append",
|
60
|
+
help="Exclude pattern(s). May be used multiple times or separated with ';'. Applied after include filtering.",
|
61
|
+
)
|
62
|
+
|
63
|
+
args = p.parse_args()
|
64
|
+
|
65
|
+
try:
|
66
|
+
repo_dir = _determine_repo_dir(args.source, args.branch)
|
67
|
+
except ValueError as exc:
|
68
|
+
sys.exit(str(exc))
|
69
|
+
|
70
|
+
markdown = repo_to_markdown(
|
71
|
+
repo_dir,
|
72
|
+
includes=args.include,
|
73
|
+
excludes=args.exclude,
|
74
|
+
)
|
75
|
+
|
76
|
+
if args.output:
|
77
|
+
out_path = os.path.abspath(args.output)
|
78
|
+
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
79
|
+
with open(out_path, "w", encoding="utf-8") as fp:
|
80
|
+
fp.write(markdown)
|
81
|
+
print(f"Markdown written to {out_path}")
|
82
|
+
else:
|
83
|
+
sys.stdout.write(markdown)
|
@@ -0,0 +1,145 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: repo-to-md
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Inject git and GitHub repos as markdown for LLM and AI Agents context
|
5
|
+
Author-email: vduseev <vagiz@duseev.com>
|
6
|
+
Maintainer-email: vduseev <vagiz@duseev.com>
|
7
|
+
License-Expression: Apache-2.0
|
8
|
+
License-File: LICENSE
|
9
|
+
Keywords: ai,claude,context,fetch,git,llm,markdown,read,repo,repository,text
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
22
|
+
Requires-Python: >=3.10
|
23
|
+
Requires-Dist: pathspec>=0.12.1
|
24
|
+
Requires-Dist: requests>=2.32.4
|
25
|
+
Description-Content-Type: text/markdown
|
26
|
+
|
27
|
+
# repo-to-md
|
28
|
+
|
29
|
+
[](https://pypi.org/project/repo-to-md/)
|
30
|
+
[](https://pypi.org/project/repo-to-md/)
|
31
|
+
|
32
|
+
**repo-to-md** turns any repo or just a part of it into a single **Markdown** with a full file `tree` and the full contents of every source file. Binary files, images, build artifacts, and dependency lock-files are automatically excluded so you get a clean, copy-pastable context for:
|
33
|
+
|
34
|
+
* providing context to AI coding assistants such as **Claude Code** (Anthropic), **ChatGPT** (OpenAI), **GitHub Copilot**, or **deep-research** agents;
|
35
|
+
* code reviews, documentation, or quick sharing on forums and gists;
|
36
|
+
* pasting snippets while staying under model token limits.
|
37
|
+
|
38
|
+
## Table of contents
|
39
|
+
|
40
|
+
* [Features](#features)
|
41
|
+
* [Installation](#installation)
|
42
|
+
* [Usage](#usage)
|
43
|
+
* [Copy to clipboard](#copy-to-clipboard)
|
44
|
+
* [With Claude Code](#with-claude-code)
|
45
|
+
* [Contributing & License](#contributing--license)
|
46
|
+
|
47
|
+
## Features
|
48
|
+
|
49
|
+
* Remote or local - works with `owner/repo`, `/local/path/repo`, full Git URLs and more.
|
50
|
+
* Selective output - include (`-i`) and exclude (`-e`) any number of paths or globs like `src/`, `tests/*`, `README.md`.
|
51
|
+
* Smart filtering - skips binary blobs, media, archives, and dozens of lock files automatically.
|
52
|
+
* Pure-Python - no system-level dependencies, runs everywhere Python does.
|
53
|
+
* Supports Python 3.10 and newer - published on PyPI.
|
54
|
+
|
55
|
+
## Installation
|
56
|
+
|
57
|
+
The project is distributed on PyPI, so any modern Python installer will work.
|
58
|
+
If you already use the excellent [`uv`](https://github.com/astral-sh/uv) tool, a
|
59
|
+
single command is enough:
|
60
|
+
|
61
|
+
To run `repo-to-md` one time, without installing it, use `uvx`:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
# Run one time using uvx
|
65
|
+
uvx repo-to-md github/repo > repo.md
|
66
|
+
```
|
67
|
+
|
68
|
+
Or install it globally:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
# Install
|
72
|
+
uv tool install repo-to-md
|
73
|
+
# Run it
|
74
|
+
repo-to-md github/repo > repo.md
|
75
|
+
```
|
76
|
+
|
77
|
+
Of course, you can also use `pip` if you prefer.
|
78
|
+
|
79
|
+
```bash
|
80
|
+
# Install
|
81
|
+
pip install repo-to-md
|
82
|
+
# Run it
|
83
|
+
repo-to-md github/repo > repo.md
|
84
|
+
```
|
85
|
+
|
86
|
+
### Supported platforms
|
87
|
+
|
88
|
+
* macOS, Linux, Windows
|
89
|
+
* Python ≥ 3.10 (see badge above)
|
90
|
+
|
91
|
+
## Usage
|
92
|
+
|
93
|
+
Entire GitHub repo into a single `hello-world.md` file.
|
94
|
+
|
95
|
+
```bash
|
96
|
+
repo-to-md octocat/Hello-World > hello-world.md
|
97
|
+
```
|
98
|
+
|
99
|
+
Local repo but only files inside the `src/` folder.
|
100
|
+
|
101
|
+
```bash
|
102
|
+
repo-to-md ~/Projects/myapp -i src/ > myapp_src.md
|
103
|
+
```
|
104
|
+
|
105
|
+
Print contents of just the `pyproject.toml` file alone:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
repo-to-md . -i pyproject.toml
|
109
|
+
```
|
110
|
+
|
111
|
+
The first positional argument is either a GitHub repo or a local path.
|
112
|
+
Selectively include or exclude files/directories with `-i/--include` and `-e/--exclude`.
|
113
|
+
|
114
|
+
## Copy to clipboard
|
115
|
+
|
116
|
+
* **macOS**: `repo-to-md . | pbcopy` *(paste with ⌘<kbd>V</kbd>)*
|
117
|
+
* **Linux / X11**: `repo-to-md . | xclip -selection clipboard`
|
118
|
+
* **Windows / PowerShell**: `repo-to-md . | clip`
|
119
|
+
|
120
|
+
Replace `.` with any path or GitHub repo, and feel free to include `src/` or similar after it.
|
121
|
+
|
122
|
+
## With Claude Code
|
123
|
+
|
124
|
+
Best way to use it inside Claude Code is to ask it to dump the repo into
|
125
|
+
a Markdown file and then work with that file.
|
126
|
+
|
127
|
+
```shell
|
128
|
+
Bash(repo-to-md github/repo > repo.md)
|
129
|
+
```
|
130
|
+
|
131
|
+
Alternatively, you can just output the entire repo into current context:
|
132
|
+
|
133
|
+
```shell
|
134
|
+
Bash(repo-to-md github/repo)
|
135
|
+
```
|
136
|
+
|
137
|
+
You can even invoke it without `Bash` and Claude will understand you.
|
138
|
+
|
139
|
+
```shell
|
140
|
+
repo-to-md github/repo
|
141
|
+
```
|
142
|
+
|
143
|
+
## Contributing & License
|
144
|
+
|
145
|
+
Issues and pull requests are welcome. Licensed under the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html).
|
@@ -0,0 +1,8 @@
|
|
1
|
+
repo_to_md/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
repo_to_md/_core.py,sha256=6wNxtopowZ0p0Yg3v12PKb1vz3OzOBI9vG0y8UTQLz4,10726
|
3
|
+
repo_to_md/cli.py,sha256=icnnNltfpf5bqbAUvCKiCaDhi86RG_eibA2JXZ61kgs,2660
|
4
|
+
repo_to_md-0.1.0.dist-info/METADATA,sha256=hZX13efJ_y9WkH4itU1n_Th_VdJ1sMfHsh1dkopo-5g,4647
|
5
|
+
repo_to_md-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
+
repo_to_md-0.1.0.dist-info/entry_points.txt,sha256=9bh8Sy6d2YTNkEJLp3izGOqctzWG65bs4aqB9G_PvwM,50
|
7
|
+
repo_to_md-0.1.0.dist-info/licenses/LICENSE,sha256=4U1FZ3NVKSPBlyMz15P4NGxUruUonLsuBvCVeMTPCKk,11342
|
8
|
+
repo_to_md-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2025 Vagiz Duseev
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|