project-to-markdown 0.1.0__tar.gz

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.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: project-to-markdown
3
+ Version: 0.1.0
4
+ Summary: Export a Python project into a single Markdown file.
5
+ Author-email: Your Name <your@email.com>
6
+ License: MIT
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+
10
+ # project-to-markdown
11
+
12
+ Export a Python project into a single Markdown file.
13
+
14
+ ## Features
15
+ - Recursively scans a project directory
16
+ - Includes code and markdown files (configurable)
17
+ - Outputs a single, well-structured Markdown file
18
+ - Supports file/directory exclusion and size limits
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ pip install project-to-markdown
24
+ ```
25
+
26
+ Or, for local development:
27
+
28
+ ```sh
29
+ pip install .
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ From the command line:
35
+
36
+ ```sh
37
+ project-to-markdown --root path/to/project --output export.md --include-exts .py,.md --exclude-dirs .venv,.git --title "My Project"
38
+ ```
39
+
40
+ ### Options
41
+ - `--root` Root directory of the project (default: current directory)
42
+ - `--output` Output Markdown file (default: project_export.md)
43
+ - `--title` Title for the Markdown document
44
+ - `--include-exts` Comma-separated list of file extensions to include (default: .py,.md)
45
+ - `--exclude-dirs` Comma-separated list of directory names to exclude
46
+ - `--exclude-files`Comma-separated list of file names to exclude
47
+ - `--use-gitignore`Respect .gitignore files in the export
48
+ - `--all-files` Include all files, not just tracked files
49
+ - `--max-bytes` Maximum size of files to include (default: 10,000,000)
50
+
51
+ ## Example
52
+
53
+ ```sh
54
+ project-to-markdown --root my_project --output my_project.md --title "My Project"
55
+ ```
56
+
57
+ ## License
58
+
59
+ MIT License
60
+
61
+ ---
62
+
63
+ Created by Your Name. Contributions welcome!
64
+
@@ -0,0 +1,55 @@
1
+ # project-to-markdown
2
+
3
+ Export a Python project into a single Markdown file.
4
+
5
+ ## Features
6
+ - Recursively scans a project directory
7
+ - Includes code and markdown files (configurable)
8
+ - Outputs a single, well-structured Markdown file
9
+ - Supports file/directory exclusion and size limits
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ pip install project-to-markdown
15
+ ```
16
+
17
+ Or, for local development:
18
+
19
+ ```sh
20
+ pip install .
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ From the command line:
26
+
27
+ ```sh
28
+ project-to-markdown --root path/to/project --output export.md --include-exts .py,.md --exclude-dirs .venv,.git --title "My Project"
29
+ ```
30
+
31
+ ### Options
32
+ - `--root` Root directory of the project (default: current directory)
33
+ - `--output` Output Markdown file (default: project_export.md)
34
+ - `--title` Title for the Markdown document
35
+ - `--include-exts` Comma-separated list of file extensions to include (default: .py,.md)
36
+ - `--exclude-dirs` Comma-separated list of directory names to exclude
37
+ - `--exclude-files`Comma-separated list of file names to exclude
38
+ - `--use-gitignore`Respect .gitignore files in the export
39
+ - `--all-files` Include all files, not just tracked files
40
+ - `--max-bytes` Maximum size of files to include (default: 10,000,000)
41
+
42
+ ## Example
43
+
44
+ ```sh
45
+ project-to-markdown --root my_project --output my_project.md --title "My Project"
46
+ ```
47
+
48
+ ## License
49
+
50
+ MIT License
51
+
52
+ ---
53
+
54
+ Created by Your Name. Contributions welcome!
55
+
@@ -0,0 +1,5 @@
1
+ # main.py for project_to_markdown package
2
+
3
+ from .main import main
4
+ # __init__.py for project_to_markdown package
5
+
@@ -0,0 +1,183 @@
1
+ # main.py for project_to_markdown package
2
+
3
+ # The following code is moved from __main__.py
4
+
5
+ import argparse
6
+ import fnmatch
7
+ import io
8
+ from pathlib import Path
9
+ from typing import List, Tuple
10
+
11
+
12
+ def parse_args() -> argparse.Namespace:
13
+ parser = argparse.ArgumentParser(
14
+ description="Export a Python project into a single Markdown file."
15
+ )
16
+ parser.add_argument(
17
+ "-r",
18
+ "--root",
19
+ type=Path,
20
+ default=Path.cwd(),
21
+ help="Root directory of the Python project to export",
22
+ )
23
+ parser.add_argument(
24
+ "-o",
25
+ "--output",
26
+ type=Path,
27
+ default=Path("project_export.md"),
28
+ help="Output Markdown file",
29
+ )
30
+ parser.add_argument(
31
+ "-t",
32
+ "--title",
33
+ type=str,
34
+ default="Project Documentation",
35
+ help="Title for the Markdown document",
36
+ )
37
+ parser.add_argument(
38
+ "--include-exts",
39
+ type=str,
40
+ default=".py,.md",
41
+ help="Comma-separated list of file extensions to include",
42
+ )
43
+ parser.add_argument(
44
+ "--exclude-dirs",
45
+ type=str,
46
+ default="",
47
+ help="Comma-separated list of directory names to exclude",
48
+ )
49
+ parser.add_argument(
50
+ "--exclude-files",
51
+ type=str,
52
+ default="",
53
+ help="Comma-separated list of file names to exclude",
54
+ )
55
+ parser.add_argument(
56
+ "--use-gitignore",
57
+ action="store_true",
58
+ help="Respect .gitignore files in the export",
59
+ )
60
+ parser.add_argument(
61
+ "--all-files",
62
+ action="store_true",
63
+ help="Include all files in the export, not just tracked files",
64
+ )
65
+ parser.add_argument(
66
+ "--max-bytes",
67
+ type=int,
68
+ default=10_000_000,
69
+ help="Maximum size of files to include (in bytes)",
70
+ )
71
+ return parser.parse_args()
72
+
73
+
74
+ def build_tree(
75
+ root: Path, files_only: bool = False, exclude_dirs: set = None
76
+ ) -> List[Tuple[Path, bool]]:
77
+ if exclude_dirs is None:
78
+ exclude_dirs = set()
79
+
80
+ structure = []
81
+ for path in sorted(root.rglob("*")):
82
+ if path.is_dir():
83
+ if any(
84
+ fnmatch.fnmatch(path.name, pattern)
85
+ for pattern in exclude_dirs
86
+ ):
87
+ continue
88
+ structure.append((path, True))
89
+ elif not files_only:
90
+ structure.append((path, False))
91
+ return structure
92
+
93
+
94
+ def render_tree_markdown(root: Path, structure_paths: List[Path]) -> str:
95
+ tree_md = []
96
+ for path in structure_paths:
97
+ rel_path = path.relative_to(root)
98
+ tree_md.append(f"- {'📁' if path.is_dir() else '📄'} {rel_path}")
99
+ return "\n".join(tree_md)
100
+
101
+
102
+ def collect_files(
103
+ root: Path,
104
+ include_exts: set,
105
+ exclude_dirs: set,
106
+ exclude_files: set,
107
+ use_gitignore: bool,
108
+ all_files: bool,
109
+ max_bytes: int,
110
+ ) -> List[Path]:
111
+ files = []
112
+ for path in sorted(root.rglob("*")):
113
+ if path.is_dir():
114
+ continue
115
+ if any(fnmatch.fnmatch(path.name, pattern) for pattern in exclude_files):
116
+ continue
117
+ if not any(fnmatch.fnmatch(path.suffix, pattern) for pattern in include_exts):
118
+ continue
119
+ if path.stat().st_size > max_bytes:
120
+ continue
121
+ files.append(path)
122
+ return files
123
+
124
+
125
+ def write_markdown(
126
+ root: Path, files: List[Path], tree_md: str, out_path: Path, title: str
127
+ ) -> None:
128
+ with io.open(out_path, "w", encoding="utf-8") as md_file:
129
+ # Write the document title
130
+ md_file.write(f"# {title}\n\n")
131
+
132
+ # Write the tree structure
133
+ md_file.write("## Project Structure\n")
134
+ md_file.write(tree_md)
135
+ md_file.write("\n\n")
136
+
137
+ # Write each file's content
138
+ for file_path in files:
139
+ rel_path = file_path.relative_to(root)
140
+ md_file.write(f"## {rel_path}\n")
141
+ with io.open(file_path, "r", encoding="utf-8") as src_file:
142
+ content = src_file.read()
143
+ md_file.write("```\n")
144
+ md_file.write(content)
145
+ md_file.write("\n```\n\n")
146
+
147
+
148
+ def main():
149
+ args = parse_args()
150
+
151
+ root: Path = args.root.resolve()
152
+ if not root.exists() or not root.is_dir():
153
+ raise SystemExit(f"[error] Root directory not found: {root}")
154
+
155
+ include_exts = {e.strip().lower() for e in args.include_exts.split(",") if e.strip()}
156
+ exclude_dirs = {d.strip() for d in args.exclude_dirs.split(",") if d.strip()}
157
+ exclude_files = {f.strip() for f in args.exclude_files.split(",") if f.strip()}
158
+
159
+ # Build a structure list for the tree (dirs + files) to display at top
160
+ structure_entries = build_tree(root, files_only=False, exclude_dirs=exclude_dirs)
161
+ structure_paths = [p for p, _is_dir in structure_entries]
162
+ tree_md = render_tree_markdown(root, structure_paths)
163
+
164
+ # Now collect *actual* files to export (respects filters)
165
+ files = collect_files(
166
+ root=root,
167
+ include_exts=include_exts,
168
+ exclude_dirs=exclude_dirs,
169
+ exclude_files=exclude_files,
170
+ use_gitignore=args.use_gitignore,
171
+ all_files=bool(args.all_files),
172
+ max_bytes=int(args.max_bytes),
173
+ )
174
+
175
+ # Write Markdown
176
+ out_path: Path = args.output if args.output.is_absolute() else Path.cwd() / args.output
177
+ write_markdown(root, files, tree_md, out_path, title=args.title)
178
+
179
+ print(f"[ok] Wrote {len(files)} files into: {out_path}")
180
+
181
+
182
+ if __name__ == "__main__":
183
+ main()
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: project-to-markdown
3
+ Version: 0.1.0
4
+ Summary: Export a Python project into a single Markdown file.
5
+ Author-email: Your Name <your@email.com>
6
+ License: MIT
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown
9
+
10
+ # project-to-markdown
11
+
12
+ Export a Python project into a single Markdown file.
13
+
14
+ ## Features
15
+ - Recursively scans a project directory
16
+ - Includes code and markdown files (configurable)
17
+ - Outputs a single, well-structured Markdown file
18
+ - Supports file/directory exclusion and size limits
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ pip install project-to-markdown
24
+ ```
25
+
26
+ Or, for local development:
27
+
28
+ ```sh
29
+ pip install .
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ From the command line:
35
+
36
+ ```sh
37
+ project-to-markdown --root path/to/project --output export.md --include-exts .py,.md --exclude-dirs .venv,.git --title "My Project"
38
+ ```
39
+
40
+ ### Options
41
+ - `--root` Root directory of the project (default: current directory)
42
+ - `--output` Output Markdown file (default: project_export.md)
43
+ - `--title` Title for the Markdown document
44
+ - `--include-exts` Comma-separated list of file extensions to include (default: .py,.md)
45
+ - `--exclude-dirs` Comma-separated list of directory names to exclude
46
+ - `--exclude-files`Comma-separated list of file names to exclude
47
+ - `--use-gitignore`Respect .gitignore files in the export
48
+ - `--all-files` Include all files, not just tracked files
49
+ - `--max-bytes` Maximum size of files to include (default: 10,000,000)
50
+
51
+ ## Example
52
+
53
+ ```sh
54
+ project-to-markdown --root my_project --output my_project.md --title "My Project"
55
+ ```
56
+
57
+ ## License
58
+
59
+ MIT License
60
+
61
+ ---
62
+
63
+ Created by Your Name. Contributions welcome!
64
+
@@ -0,0 +1,10 @@
1
+ MANIFEST.in
2
+ README.md
3
+ pyproject.toml
4
+ project_to_markdown/__init__.py
5
+ project_to_markdown/main.py
6
+ project_to_markdown.egg-info/PKG-INFO
7
+ project_to_markdown.egg-info/SOURCES.txt
8
+ project_to_markdown.egg-info/dependency_links.txt
9
+ project_to_markdown.egg-info/entry_points.txt
10
+ project_to_markdown.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ project-to-markdown = project_to_markdown.main:main
@@ -0,0 +1 @@
1
+ project_to_markdown
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "project-to-markdown"
7
+ version = "0.1.0"
8
+ description = "Export a Python project into a single Markdown file."
9
+ authors = [{name = "Your Name", email = "your@email.com"}]
10
+ readme = "README.md"
11
+ requires-python = ">=3.7"
12
+ license = {text = "MIT"}
13
+ dependencies = []
14
+
15
+ [project.scripts]
16
+ project-to-markdown = "project_to_markdown.main:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+