Skip to content

Commit 3194b5d

Browse files
authored
Feat: add documentation (MkDocs) (#4)
## Summary add MkDocs-based documentation for the TinyBear project, including a minimal and user-friendly configuration for deployment to GitHub Pages under the /tinybear subpath.
1 parent f407e5a commit 3194b5d

File tree

8 files changed

+1052
-125
lines changed

8 files changed

+1052
-125
lines changed

.github/workflows/deploy.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy MkDocs to GitHub Pages (gh-pages branch)
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: 3.x
17+
- name: Install dependencies
18+
run: |
19+
pip install mkdocs mkdocs-material
20+
- name: Build docs
21+
run: |
22+
mkdocs build --site-dir site
23+
- name: Deploy to GitHub Pages
24+
uses: peaceiris/actions-gh-pages@v4
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
publish_branch: gh-pages
28+
publish_dir: ./site

docs/api.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# API Reference
2+
3+
---
4+
5+
## tinybear.csv_xls
6+
7+
### append_empty_column_to_csv
8+
```python
9+
def append_empty_column_to_csv(path_to_file: Path, name_of_new_column: str, delimiter: CSVDelimiter = ",", custom_path_to_output_file: Optional[Path] = None) -> None:
10+
```
11+
Adds empty column (as last column) to CSV file. **Overwrites file**, but optional output path can be specified to create a new file.
12+
13+
Raises:
14+
- ValueError if column name already exists in file.
15+
- FileExistsError if custom output file is specified and already exists.
16+
17+
---
18+
19+
### check_csv_for_malformed_rows
20+
```python
21+
def check_csv_for_malformed_rows(path_to_file: Path) -> None:
22+
```
23+
Checks whether all rows in CSV file have the same number of columns. Throws IndexError if they do not.
24+
25+
---
26+
27+
### check_csv_for_repetitions_in_column
28+
```python
29+
def check_csv_for_repetitions_in_column(path_to_file: Path, column_name: str) -> None:
30+
```
31+
Throws ValueError if there are repetitions in given column of given file.
32+
33+
---
34+
35+
### convert_xls_to_csv
36+
```python
37+
def convert_xls_to_csv(path_to_input_excel_file: Path, sheet_name: str, path_to_output_csv_file: Path, delimiter: CSVDelimiter = ",", overwrite: bool = True) -> None:
38+
```
39+
Converts sheet from Excel file to CSV format.
40+
41+
---
42+
43+
### read_column_from_csv
44+
```python
45+
def read_column_from_csv(path_to_file: Path, column_name: str) -> list[str]:
46+
```
47+
Reads one column from CSV file. Column name is taken from the top row. Raises KeyError if no such column exists.
48+
49+
---
50+
51+
### read_dicts_from_csv
52+
```python
53+
def read_dicts_from_csv(path_to_file: Path, delimiter: CSVDelimiter = ",") -> list[dict[str, str]]:
54+
```
55+
Reads CSV as list of dictionaries (top row is considered key).
56+
57+
---
58+
59+
### read_dict_from_2_csv_columns
60+
```python
61+
def read_dict_from_2_csv_columns(path_to_file: Path, key_col: str, val_col: str, delimiter: CSVDelimiter = ",") -> dict[str, str]:
62+
```
63+
Reads CSV and returns dict mapping keys from key_col to values from val_col.
64+
65+
---
66+
67+
### read_dicts_from_xls
68+
```python
69+
def read_dicts_from_xls(path_to_file: Path, sheet_name: str) -> list[dict[str, str]]:
70+
```
71+
Reads XLS sheet as list of dictionaries (top row as key).
72+
73+
---
74+
75+
### read_plain_rows_from_csv
76+
```python
77+
def read_plain_rows_from_csv(path_to_file: Path, delimiter: CSVDelimiter = ",", remove_1st_row: bool = False) -> list[list[str]]:
78+
```
79+
Reads plain rows (list of lists) from CSV.
80+
81+
---
82+
83+
### remove_rows_with_given_content_in_lookup_column
84+
```python
85+
def remove_rows_with_given_content_in_lookup_column(rows: list[dict[str, str]], lookup_column: str, match_value: str) -> tuple[list[dict[str, str]], tuple[int, ...]]:
86+
```
87+
Remove rows where lookup_column matches match_value. Returns (new list, indices of removed rows).
88+
89+
---
90+
91+
### write_csv
92+
```python
93+
def write_csv(rows, path_to_file: Path, overwrite: bool, delimiter: CSVDelimiter) -> None:
94+
```
95+
Writes rows (various formats) to CSV file. Adds header if writing dicts/NamedTuples.
96+
97+
---
98+
99+
## tinybear.json_toml_yaml
100+
101+
### check_yaml_file
102+
```python
103+
def check_yaml_file(path_to_file: Path, verbose: bool = True) -> None:
104+
```
105+
Validates YAML file, throws if malformed or duplicate top-level keys are found.
106+
107+
---
108+
109+
### read_json_toml_yaml
110+
```python
111+
def read_json_toml_yaml(path_to_file: Path) -> Union[dict[str, Any], list[str]]:
112+
```
113+
Auto-detects file extension and deserializes JSON, TOML, or YAML to Python types.
114+
115+
---
116+
117+
## tinybear.txt
118+
119+
### check_encoding_of_file
120+
```python
121+
def check_encoding_of_file(file: Path) -> str:
122+
```
123+
Check encoding (utf-8 or cp1251/ANSI); returns detected encoding.
124+
125+
---
126+
127+
### read_non_empty_lines_from_txt_file
128+
```python
129+
def read_non_empty_lines_from_txt_file(path_to_file: Path) -> list[str]:
130+
```
131+
Gets non-empty lines from TXT file as list.
132+
133+
---
134+
135+
### read_plain_text_from_file
136+
```python
137+
def read_plain_text_from_file(path_to_file: Path) -> str:
138+
```
139+
Reads plain text from file (utf-8 or cp1251 encoding).
140+
141+
---
142+
143+
### remove_extra_space
144+
```python
145+
def remove_extra_space(str_: str) -> str:
146+
```
147+
Removes leading/trailing/multiple spaces in a string.
148+
149+
---
150+
151+
### write_plain_text_to_file
152+
```python
153+
def write_plain_text_to_file(content: Union[str, list[str], tuple[str]], file: Path, overwrite: bool, newline_char: str = "\n") -> None:
154+
```
155+
Writes string or lines to text file. Optionally enforces overwrite/newlines.
156+
157+
---
158+
159+
### move_line
160+
```python
161+
def move_line(file: Path, line_number_to_cut: int, line_number_to_insert_before: Union[int, Literal["END"]], output_file: Union[Path, None] = None) -> None:
162+
```
163+
Moves a line in a text file to another position; saves to output file if given.
164+
165+
---
166+
167+
## tinybear.html.validate_html
168+
169+
### validate_html
170+
```python
171+
def validate_html(html: str, allowed_tags: Iterable[str] = (...), is_text_at_root_level_allowed: bool = False) -> None:
172+
```
173+
Validate HTML string for allowed tags, structure, and correct entities. Raises ParsingError on errors.
174+
175+
---
176+
177+
## tinybear.html.from_docx
178+
179+
### convert_file_from_doc
180+
```python
181+
def convert_file_from_doc(path_to_file: Path, output_dir: Path = DEFAULT_OUTPUT_DIR, style_map: str = DEFAULT_STYLE_MAP, print_html: bool = True) -> Path:
182+
```
183+
Read from DOC(x), write to HTML file, return output path.
184+
185+
---
186+
187+
### convert_all_docs
188+
```python
189+
def convert_all_docs(input_dir: Path = DEFAULT_INPUT_DIR, output_dir: Path = DEFAULT_OUTPUT_DIR, print_html: bool = True) -> None:
190+
```
191+
Convert all .DOC(x) files in a directory to HTML.
192+
193+
---
194+
195+
### read_from_doc
196+
```python
197+
def read_from_doc(path_to_file: Path, style_map: str = DEFAULT_STYLE_MAP) -> str:
198+
```
199+
Read binary DOCX file, return HTML string.
200+
201+
---
202+
203+
## tinybear.exceptions
204+
205+
### ParsingError
206+
```python
207+
class ParsingError(Exception):
208+
"""Base class for all parsing errors."""
209+
```

docs/getting_started.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Getting Started
2+
3+
Welcome to **TinyBear**!
4+
5+
This guide will help you quickly set up and start using TinyBear in your project.
6+
7+
## Installation
8+
9+
You can install TinyBear via pip:
10+
11+
```bash
12+
pip install tinybear
13+
```
14+
15+
Or clone the repository and install locally:
16+
17+
```bash
18+
git clone https://github.com/lemontree210/tinybear
19+
cd tinybear
20+
pip install .
21+
```
22+
23+
## Requirements
24+
25+
TinyBear requires Python 3.9 or newer.
26+
27+
---
28+
29+
Continue to the [Usage](usage.md) section to learn how to use TinyBear in your workflow.

docs/index.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# TinyBear
2+
3+
**TinyBear** is a lightweight utility library for working with data files and serialization formats in Python. It provides convenient tools for reading, writing, and validating CSV, XLS, JSON, TOML, YAML, and HTML files.
4+
5+
---
6+
7+
## Features
8+
9+
- Simple interface for common data tasks
10+
- Support for multiple data formats
11+
- Easy data validation
12+
- Designed for Python 3.9+
13+
- Minimal dependencies
14+
15+
---
16+
17+
## Get Started
18+
19+
- 📖 [Getting Started](getting_started.md)
20+
-[Usage](usage.md)
21+
- 🧩 [API Reference](api.md)
22+
23+
---
24+
25+
For more details on available modules and methods, see the source code or contribute to extend the docs!

docs/usage.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Usage
2+
3+
This section provides examples and instructions for using TinyBear.
4+
5+
## Importing Modules
6+
7+
You can import TinyBear modules in your Python code:
8+
9+
```python
10+
from tinybear import csv_xls, json_toml_yaml
11+
```
12+
13+
## CSV/XLS Operations
14+
15+
Read, write, and process CSV or XLS files using the `csv_xls` module. Example:
16+
17+
```python
18+
from tinybear import csv_xls
19+
# usage example here
20+
```
21+
22+
## JSON, TOML, YAML Handling
23+
24+
Use the `json_toml_yaml` module for seamless serialization and deserialization:
25+
26+
```python
27+
from tinybear import json_toml_yaml
28+
# usage example here
29+
```
30+
31+
---
32+
33+
For more detailed API information, refer to the source code or contribute to the docs!

mkdocs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
site_name: TinyBear Documentation
2+
site_url: https://lemontree210.github.io/tinybear/
3+
extra:
4+
base_url: /tinybear/
5+
nav:
6+
- Home: index.md
7+
- Getting Started: getting_started.md
8+
- Usage: usage.md
9+
- API Reference: api.md
10+
docs_dir: docs
11+
site_dir: site
12+
theme:
13+
name: material
14+
features:
15+
- navigation.instant # ⚡ Instant loading
16+
- navigation.tracking # 📊 Track scroll position
17+
- navigation.tabs.sticky # 📌 Sticky navigation
18+
- navigation.top # ⬆️ Back to top button
19+
- search.suggest # 🔍 Search suggestions
20+
- search.share # 🔗 Share search
21+
- header.autohide # 🎩 Auto-hide header
22+
- content.code.annotate # 💡 Code annotations

0 commit comments

Comments
 (0)