You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Code Embedder** is a GitHub Action that automatically updates code snippets in your markdown (`README`) files. It finds code blocks in your `README` that reference specific scripts, then replaces these blocks with the current content of those scripts. This keeps your documentation in sync with your code.
14
+
**Code Embedder** is a **GitHub Action** and a **pre-commit hook** that automatically updates code snippets in your markdown (`README`) files. It finds code blocks in your `README` that reference specific scripts, then replaces these blocks with the current content of those scripts. This keeps your documentation in sync with your code.
15
15
16
16
### ✨ Key features
17
17
- 🔄 **Automatic synchronization**: Keep your `README` code examples up-to-date without manual intervention.
18
-
- 🛠️ **Easy setup**: Simply add the action to your GitHub workflow and format your `README` code blocks.
19
-
- 📝 **Section support**: Update only specific sections of the script in the `README`.
18
+
- 🛠️ **Easy setup**: Simply add the action to your GitHub workflow / pre-commit hook and format your `README` code blocks.
19
+
- 📝 **Section support**: Update only specific sections of the script in the `README`. This is **language agnostic**.
20
20
- 🧩 **Object support**: Update only specific objects (functions, classes) in the `README`. *The latest version supports only 🐍 Python objects (other languages to be added soon).*
21
21
22
22
23
-
By using **Code Embedder**, you can focus on writing and updating your actual code 💻, while letting the action take care of keeping your documentation current 📚🔄. This reduces the risk of outdated or incorrect code examples in your project documentation.
23
+
By using **Code Embedder**, you can focus on writing and updating your actual code 💻, while letting the Code-Embedder take care of keeping your documentation current 📚🔄. This reduces the risk of outdated or incorrect code examples in your project documentation.
24
24
25
25
## 🔍 How it works
26
26
27
-
The action looks for specific tags in all markdown (`README`) files, which indicate the script file path (and optionally the section to update), then it updates the code block sections in the `README` files with the content. The changes are then pushed to the repository 🚀.
27
+
The **Code Embedder** scans markdown files for special tags that specify which parts of your scripts to embed. When it finds these tags, it automatically updates the code blocks with the latest content from your source files. When used as a GitHub Action, any changes are automatically committed and pushed to your repository 🚀.
28
28
29
29
### 📄 **Full script** updates
30
30
In the `README` (or other markdown) file, the full script is marked with the following tag:
@@ -47,7 +47,9 @@ You must also add the following comment tags in the script file `path/to/script`
47
47
...
48
48
[Comment sign] code_embedder:section_name end
49
49
```
50
-
The comment sign is the one that is used in the script file, e.g. `#` for Python, or `//` for JavaScript. The `section_name` must be unique in the file, otherwise the action will use the first section found.
50
+
The comment sign is the one that is used in the script file, e.g. `#` for Python, or `//` for JavaScript. For example, in python script you add `# code_embedder:A start` and `# code_embedder:A end` to new lines to mark the start and end of the section `A` you want to include in the `README`.
51
+
52
+
The `section_name` must be unique in the file, otherwise the Code-Embedder will use the first section found.
51
53
52
54
### 🧩 **Object** updates
53
55
In the `README` (or other markdown) file, the object of the script is marked with the following tag:
@@ -59,10 +61,10 @@ In the `README` (or other markdown) file, the object of the script is marked wit
59
61
> Notice that the `path/to/script` is followed by `o:` in the tag to indicate that the object `object_name` is being updated.
60
62
61
63
> [!Note]
62
-
> The object name must match exactly the name of the object (function, class) in the script file, including the case (e.g. `Person` not `person`). Currently, only 🐍 Python objects are supported.
64
+
> The object name must match exactly the name of the object (function, class) in the script file, including the case (e.g. if class is `Person` then object name must be `Person`, not `person`). Currently, only 🐍 Python objects are supported.
63
65
64
-
## 🔧 Setup
65
-
To use this action, you need to configure a yaml workflow file in`.github/workflows` folder (e.g. `.github/workflows/code-embedder.yaml`) with the following content:
66
+
## 🔧 Setup - Github Action
67
+
Use **Code Embedder** as a Github Action by adding the following to your`.github/workflows/code-embedder.yaml` file:
66
68
67
69
```yaml
68
70
name: Code Embedder
@@ -89,6 +91,48 @@ jobs:
89
91
90
92
```
91
93
94
+
## 🔧 Setup - Pre-commit Hook
95
+
You can set up **Code Embedder** as a pre-commit hook using either:
96
+
<oltype="A">
97
+
<li>Installation via PyPI</li>
98
+
<li>Direct repository reference in your <code>.pre-commit-config.yaml</code> file</li>
99
+
</ol>
100
+
101
+
### A. Installation via PyPI
102
+
Install the package:
103
+
```bash
104
+
pip install code-embedder==0.5.2
105
+
```
106
+
107
+
Your `.pre-commit-config.yaml` file should look like this:
108
+
```yaml
109
+
- repo: local
110
+
hooks:
111
+
- id: code-embedder
112
+
name: Code embedder
113
+
entry: code-embedder run
114
+
language: python
115
+
```
116
+
117
+
### B. Direct repository reference
118
+
Alternatively, you can reference the repository directly in your `.pre-commit-config.yaml` file:
Command `code-embedder run` has the following options:
131
+
132
+
| Option | Description |
133
+
| ------ | ----------- |
134
+
| `--all-files` | Process all files in the repository. In pre-commit hook, it by default checks only the changed files. |
135
+
92
136
## 💡 Examples
93
137
94
138
### 📄 Full script update
@@ -107,7 +151,7 @@ The `main.py` file contains the following code:
107
151
print("Embedding successful")
108
152
```
109
153
110
-
Once the workflow runs, the code block sections are filled with the content of the script located at `main.py` and updated in the `README` file.
154
+
Once code-embedder runs, the code block sections are filled with the content of the script located at `main.py` and updated in the `README` file.
111
155
112
156
````md
113
157
# README
@@ -118,7 +162,7 @@ This is a readme.
118
162
print("Embedding successful")
119
163
```
120
164
````
121
-
With any changes to `main.py`, the code block section is updated in the `README` file with the next workflow run.
165
+
With any changes to `main.py`, the code block section is updated in the `README` file with the next code-embedder run.
122
166
123
167
### 📂 Section update
124
168
@@ -140,7 +184,7 @@ print("Embedding successful")
140
184
# code_embedder:A end
141
185
```
142
186
143
-
Once the workflow runs, the code block section will be updated in the `README` file with the content of the section `A` from the script located at `main.py`and pushed to the repository 🚀.
187
+
Once code-embedder runs, the code block section will be updated in the `README` file with the content of the section `A` from the script located at `main.py` (in case of using it as a Github Action, the changes are then pushed to the repository 🚀).
144
188
145
189
````md
146
190
# README
@@ -152,7 +196,7 @@ print("Embedding successful")
152
196
```
153
197
````
154
198
155
-
With any changes to the section `A` in `main.py`, the code block section is updated in the `README` file with the next workflow run.
199
+
With any changes to the section `A` in `main.py`, the code block section is updated in the `README` file with the next code-embedder run.
156
200
157
201
### 🧩 Object update
158
202
The tag used for object update follows the same convention as the tag for section update with the following changes:
@@ -192,7 +236,7 @@ class Person:
192
236
...
193
237
```
194
238
195
-
Once the workflow runs, the code block section will be updated in the `README` file with the content of the function `print_hello` and class `Person` from the script located at `main.py`and pushed to the repository 🚀.
239
+
Once code-embedder runs, the code block section will be updated in the `README` file with the content of the function `print_hello` and class `Person` from the script located at `main.py` (in case of using it as a Github Action, the changes are then pushed to the repository 🚀).
196
240
197
241
````md
198
242
# README
@@ -215,10 +259,10 @@ class Person:
215
259
```
216
260
````
217
261
218
-
With any changes to the function `print_hello` or class `Person` in `main.py`, the code block sections are updated in the `README` file with the next workflow run.
262
+
With any changes to the function `print_hello` or class `Person` in `main.py`, the code block sections are updated in the `README` file with the next code-embedder run.
219
263
220
264
## 🤝 Contributing
221
-
We welcome contributions to improve this tool!
265
+
We welcome contributions to improve this package!
222
266
- If you have an idea for a **new feature** ✨, open a [new feature request](https://github.com/kvankova/code-embedder/issues/new?labels=enhancement&template=feature_request.yaml) on GitHub.
223
267
- If you spot a **bug** 🐛, open a [new issue](https://github.com/kvankova/code-embedder/issues/new/choose) on GitHub.
224
268
- If you want to **contribute to the code**, please pick an issue that is not assigned to anyone and comment on it, so that we know you are working on it.
0 commit comments