cmake2chat 0.1.0a0__py2.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.
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: cmake2chat
3
+ Version: 0.1.0a0
4
+ Summary: Scans your CMake project directory, builds a tree view of the codebase, and exports the tree view, the paths of all `CMakeLists.txt` files along with their contents to an OpenAI Chat Completions-compatible JSON.
5
+ Author-email: Jifeng Wu <jifengwu2k@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jifengwu2k/cmake2chat
8
+ Project-URL: Bug Tracker, https://github.com/jifengwu2k/cmake2chat/issues
9
+ Classifier: Programming Language :: Python :: 2
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=2
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: build-filesystem-trie
16
+ Requires-Dist: cowlist
17
+ Dynamic: license-file
18
+
19
+ # `cmake2chat`
20
+
21
+ Lost in a huge CMake project? Wish an LLM could just "see" the codebase structure and all build rules? Now they can!
22
+
23
+ ## What's This?
24
+
25
+ `cmake2chat` scans your CMake project directory, builds a tree view of the codebase, and exports the tree view, the paths of all `CMakeLists.txt` files along with their contents to an OpenAI Chat Completions-compatible JSON.
26
+
27
+ ### Typical Use Cases
28
+
29
+ - Instant overview: Give an LLM a complete picture of your project's structure (files, folders) plus CMake build logic at every level.
30
+ - Build-system-powered Q&A: Ask questions like "What libraries does this project build?", "Where is the executable defined?", or "What targets/flags are set in this module?" and get relevant, context-based answers!
31
+ - AI onboarding: Drop into a new CMake project and let an LLM guide you using actual high-level structure and build scripts, not just guesses.
32
+ - No manual plumbing: Skip hours of clicking/repeating `find .`, opening dozens of files, or pasting snippets piecemeal. Feed the AI the *whole map* and let it answer or advise precisely.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install cmake2chat
38
+ ```
39
+
40
+ ## Example
41
+
42
+ Suppose you have the following CMake project directory structure:
43
+
44
+ ```
45
+ - my_project/
46
+ - CMakeLists.txt
47
+ - src/
48
+ - CMakeLists.txt
49
+ - main.cpp
50
+ - lib/
51
+ - CMakeLists.txt
52
+ ```
53
+
54
+ To generate an OpenAI Chat Completions-compatible JSON describing your project, simply run:
55
+
56
+ ```bash
57
+ python -m cmake2chat my_project -o my_project.json
58
+ ```
59
+
60
+ An example of the beginning of the output might look like:
61
+
62
+ ```json
63
+ [
64
+ {
65
+ "role": "user",
66
+ "content": "- my_project/\n - CMakeLists.txt\n - src/\n - CMakeLists.txt\n - main.cpp\n - lib/\n - CMakeLists.txt"
67
+ },
68
+ {
69
+ "role": "user",
70
+ "content": "CMakeLists.txt"
71
+ },
72
+ {
73
+ "role": "user",
74
+ "content": "# Top-level build logic goes here\ncmake_minimum_required(VERSION 3.10)\nproject(MyProject)\n..."
75
+ },
76
+ {
77
+ "role": "user",
78
+ "content": "src/CMakeLists.txt"
79
+ },
80
+ {
81
+ "role": "user",
82
+ "content": "# Build logic for src directory\nadd_executable(main main.cpp)\n..."
83
+ }
84
+ ]
85
+ ```
86
+
87
+ You can now use this JSON directly as input to an LLM API for a powerful, context-aware understanding of your CMake project!
88
+
89
+ ## How it works
90
+
91
+ - **Scan**: Recursively walks your project directory.
92
+ - **Map**: Extracts the structure (files & folders) as a tree.
93
+ - **Collect**: For each `CMakeLists.txt`, grabs its path and full content.
94
+ - **Export**: Outputs everything as an OpenAI Chat Completions-compatible JSON.
95
+
96
+ ## Contributing
97
+
98
+ Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
99
+
100
+ ## License
101
+
102
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,6 @@
1
+ cmake2chat.py,sha256=63ZxPlgMOdJ0AZJcnYf-Jb6-xdmzn3wW3JQuATJ74Hg,2952
2
+ cmake2chat-0.1.0a0.dist-info/licenses/LICENSE,sha256=hvfX-ADssuMYgrXDUAjMMut4l8W3meA31ZAYfpdlJKY,1066
3
+ cmake2chat-0.1.0a0.dist-info/METADATA,sha256=60H5zPMgGsgzRUwMasusM3Hb2532z6Eb8aCziGKyDlI,3498
4
+ cmake2chat-0.1.0a0.dist-info/WHEEL,sha256=Q6xS052dXadQWXcEVKSI037R6NoyqhUlJ5BcYz2iMP4,110
5
+ cmake2chat-0.1.0a0.dist-info/top_level.txt,sha256=v7faZZAJmfj58H-gjMj5LHIKR6vm3d5a9D54u7wOnbs,11
6
+ cmake2chat-0.1.0a0.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jifeng Wu
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.
@@ -0,0 +1 @@
1
+ cmake2chat
cmake2chat.py ADDED
@@ -0,0 +1,90 @@
1
+ # Copyright (c) 2026 Jifeng Wu
2
+ # Licensed under the MIT License. See LICENSE file in the project root for full license information.
3
+ import argparse
4
+ import codecs
5
+ import json
6
+ import os.path
7
+ import sys
8
+
9
+ from build_filesystem_trie import (
10
+ build_filesystem_trie,
11
+ iterate_relative_path_components_is_dir_tuples
12
+ )
13
+ from cowlist import COWList
14
+
15
+
16
+ def main():
17
+ parser = argparse.ArgumentParser()
18
+ parser.add_argument('path', help='Path to cmake project root')
19
+ parser.add_argument('-o', '--output', default='-', help='Output JSON file (default: - for stdout)')
20
+ parser.add_argument('--recurse-dotted', action='store_true', help='Include hidden files/directories')
21
+ args = parser.parse_args()
22
+
23
+ prefix, trie = build_filesystem_trie(args.path, recurse_dotted=args.recurse_dotted)
24
+
25
+ cmake_files_json = [
26
+ {'role': 'user', 'content': filesystem_trie_to_filesystem_tree_view(trie)}
27
+ ]
28
+
29
+ for (
30
+ cmakelists_path_components,
31
+ cmakelists_content
32
+ ) in find_cmakelists_paths_and_contents(prefix, trie, COWList((trie.value,))):
33
+ cmake_files_json.append(
34
+ {'role': 'user', 'content': os.path.join(*cmakelists_path_components)}
35
+ )
36
+ cmake_files_json.append(
37
+ {'role': 'user', 'content': cmakelists_content}
38
+ )
39
+
40
+ if args.output != '-':
41
+ with codecs.open(args.output, 'w', encoding='utf-8') as f:
42
+ json.dump(cmake_files_json, f, indent=2)
43
+ f.write('\n')
44
+ else:
45
+ json.dump(cmake_files_json, sys.stdout, indent=2)
46
+ sys.stdout.write('\n')
47
+
48
+
49
+ def filesystem_trie_to_filesystem_tree_view(
50
+ filesystem_trie,
51
+ ):
52
+ # type: (...) -> str
53
+ lines = []
54
+ for relative_path_components, is_dir in iterate_relative_path_components_is_dir_tuples(
55
+ filesystem_trie
56
+ ):
57
+ lines.append(
58
+ '%s- %s%s' % (
59
+ ' ' * (len(relative_path_components) - 1),
60
+ relative_path_components[-1],
61
+ '/' if is_dir else '',
62
+ )
63
+ )
64
+ return '\n'.join(lines)
65
+
66
+
67
+ def find_cmakelists_paths_and_contents(prefix, trie, relative_path_components):
68
+ """
69
+ Yield (relative_path_components, file_contents)
70
+ for every CMakeLists.txt under prefix.
71
+ relative_path_components is relative to prefix.
72
+ """
73
+ # If this is a file named CMakeLists.txt
74
+ if trie.is_end and trie.value == 'CMakeLists.txt':
75
+ path = os.path.join(*prefix.extend(relative_path_components))
76
+ with codecs.open(path, 'r', encoding='utf-8') as f:
77
+ yield relative_path_components, f.read()
78
+ # If this is a directory, search children:
79
+ elif trie.children:
80
+ for child_name, child in trie.children.items():
81
+ for _ in find_cmakelists_paths_and_contents(
82
+ prefix,
83
+ child,
84
+ relative_path_components.append(child_name)
85
+ ):
86
+ yield _
87
+
88
+
89
+ if __name__ == '__main__':
90
+ main()