Skip to content

Commit 66494de

Browse files
authored
Merge pull request #6 from second-ed/dev
v0.2.0
2 parents 0122a9d + e47d3f2 commit 66494de

16 files changed

Lines changed: 803 additions & 308 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Build & maybe upload PyPI package
22
'on':
33
push:
4-
branches:
5-
- main
64
tags:
75
- '*'
86
pull_request:

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/uv-pre-commit
3+
rev: 0.5.26
4+
hooks:
5+
- id: uv-lock
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v5.0.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-toml
12+
- id: check-yaml
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.9.4
15+
hooks:
16+
- id: ruff
17+
args: [ --fix ]
18+
- id: ruff-format
19+
- repo: local
20+
hooks:
21+
- id: build
22+
name: build
23+
entry: cargo build --verbose
24+
language: rust
25+
pass_filenames: false
26+
- id: fmt
27+
name: fmt
28+
entry: cargo fmt --all -- --check
29+
language: rust
30+
pass_filenames: false
31+
- id: test
32+
name: test
33+
entry: cargo test
34+
language: rust
35+
pass_filenames: false
36+
- id: clippy
37+
name: clippy
38+
entry: cargo clippy
39+
language: rust
40+
pass_filenames: false
41+
- id: repo-map
42+
name: repo_map
43+
entry: uv
44+
language: system
45+
pass_filenames: false
46+
args:
47+
- run
48+
- -m
49+
- repo_mapper
50+
- --repo-root
51+
- .
52+
- --readme-path
53+
- ./README.md
54+
- --gitignore-path
55+
- ./.gitignore
56+
- --allowed-exts
57+
- py,rs,md,yaml,toml,lock
58+
- --ignore-dirs
59+
- .venv,target,.git
60+
# - --ignore-hidden

Cargo.lock

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[package]
22
name = "readme-update"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[lib]
88
name = "readme_update"
9-
crate-type = ["cdylib"]
9+
crate-type = ["cdylib", "rlib"]
1010

1111
[dependencies]
1212
colored = "3.0.0"
1313
pyo3 = "0.25.0"
1414
rayon = "1.10.0"
1515
regex = "1.11.1"
16+
test-case = "3.3.1"
1617
walkdir = "2.5.0"

README.md

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Tired of updating documentation?
1+
# readme-update 🦀
2+
[![PyPI Downloads](https://static.pepy.tech/badge/readme-update)](https://pepy.tech/projects/readme-update)
3+
4+
## Tired of updating documentation?
25
This tool updates your `README.md` with a one line description for each of the python scripts in a directory you point it to (and recursively). It adds the text for lines that start with `"Description: "` and `"Link: "`. It ignores any that don't have the description.
36

47
The idea is that links should link to higher level documentation (if it exists).
@@ -15,15 +18,18 @@ It will update in place if the `# Scripts` block exists or else it will append i
1518
| `example1.py` | This is an example file that links to my own github. | [Link](https://github.com/second-ed) |
1619
| `example2.py` | Some other description. | |
1720
| `example3.py` | | [Link](https://doc.rust-lang.org/book/) |
18-
| `example_usage.py` | | |
1921
::
2022

21-
# To install the package
23+
# Installation
2224
```shell
2325
pip install readme-update
2426
```
27+
Or
28+
```shell
29+
uv add readme-update
30+
```
2531

26-
# Usage
32+
# Usage
2733
Assuming its is run from this location.
2834
```shell
2935
root/
@@ -32,15 +38,58 @@ root/
3238
README.md
3339
```
3440

35-
# example_script.py
36-
```python
37-
import readme_update
38-
from pathlib import Path
41+
```shell
42+
uv run -m readme-update \
43+
--scripts-root "./scripts" \
44+
--readme-path "./README.md"
45+
```
46+
3947

40-
path = Path(__file__)
48+
# Args
49+
| Argument | Type | Required | Default | Description |
50+
| ------------------ | --------------------- | -------- | ------- | ---------------------------------------------------- |
51+
| `--scripts-root` | `str` || | Path to the root of the scripts to scan |
52+
| `--readme-path` | `str` || `'./README.md'` | Path to the README file that will be modified |
4153

42-
readme_update.py_main(
43-
str(path.parent),
44-
str(path.parents[1] / "README.md")
45-
)
54+
55+
# Ret codes
56+
| RetCode | int | description |
57+
| ----------------------| --- | --------------------- |
58+
| `NoModification` | 0 | The Repo Map reflects the current state of the repo. |
59+
| `ModifiedReadme` | 1 | The README was updated. |
60+
| `NoPyFiles` | 2 | No python files found at the `scripts-root` location. |
61+
| `FailedParsingFile` | 3 | Failed to read README file |
62+
| `FailedToWriteReadme` | 4 | The given `README.md` path does not match the expected basename. |
63+
64+
65+
# Repo map
66+
```
67+
├── .github
68+
│ └── workflows
69+
│ ├── ci.yaml
70+
│ └── publish.yaml
71+
├── python
72+
│ └── update_readme
73+
│ ├── __init__.py
74+
│ └── __main__.py
75+
├── scripts
76+
│ ├── example1.py
77+
│ ├── example2.py
78+
│ └── example3.py
79+
├── src
80+
│ ├── core
81+
│ │ ├── adapters.rs
82+
│ │ ├── domain.rs
83+
│ │ └── mod.rs
84+
│ ├── api.rs
85+
│ └── lib.rs
86+
├── tests
87+
│ └── integration_tests.rs
88+
├── .pre-commit-config.yaml
89+
├── Cargo.lock
90+
├── Cargo.toml
91+
├── README.md
92+
├── pyproject.toml
93+
└── uv.lock
94+
::
4695
```

pyproject.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@ build-backend = "maturin"
44

55
[project]
66
name = "readme-update"
7-
version = "0.1.2"
7+
version = "0.2.0"
88
readme = "README.md"
99
requires-python = ">=3.10"
1010
classifiers = [
1111
"Programming Language :: Rust",
1212
"Programming Language :: Python :: Implementation :: CPython",
1313
"Programming Language :: Python :: Implementation :: PyPy",
1414
]
15-
dynamic = ["version"]
1615
license = { text = "MIT" }
1716
dependencies = []
17+
1818
[tool.maturin]
1919
features = ["pyo3/extension-module"]
20+
module-name = "readme_update"
21+
python-source = "python"
22+
python-packages = ["update_readme"]
23+
strip = true
2024

2125
[tool.uv]
2226
# Rebuild package when any rust files change
2327
cache-keys = [{file = "pyproject.toml"}, {file = "rust/Cargo.toml"}, {file = "**/*.rs"}]
28+
29+
[dependency-groups]
30+
dev = [
31+
"pre-commit>=4.2.0",
32+
"repo-mapper-rs>=0.1.0",
33+
"ruff>=0.12.5",
34+
]
2435
# Uncomment to build rust code in development mode
25-
# config-settings = { build-args = '--profile=dev' }
36+
# config-settings = { build-args = '--profile=dev' }

python/update_readme/__init__.py

Whitespace-only changes.

python/update_readme/__main__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import argparse
2+
import os
3+
import sys
4+
import readme_update
5+
6+
if __name__ == "__main__":
7+
parser = argparse.ArgumentParser()
8+
9+
parser.add_argument(
10+
"--scripts-root",
11+
type=os.path.abspath,
12+
required=True,
13+
help="Path to the root of the scripts to generate the table for.",
14+
)
15+
parser.add_argument(
16+
"--readme-path",
17+
type=os.path.abspath,
18+
default="./README.md",
19+
help="Path to the readme file.",
20+
)
21+
args = parser.parse_args()
22+
sys.exit(int(readme_update.py_main(args.scripts_root, args.readme_path)))

scripts/example_usage.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/api.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::core::adapters::RealFileSystem;
2+
use crate::core::domain::{main, RetCode};
3+
use pyo3::prelude::*;
4+
use std::path::Path;
5+
6+
#[pyfunction]
7+
fn py_main(scripts_root: String, readme_path: String) -> PyResult<i8> {
8+
let mut file_sys = RealFileSystem;
9+
match main(&mut file_sys, scripts_root, Path::new(&readme_path)) {
10+
RetCode::NoModification => Ok(0),
11+
RetCode::ModifiedReadme => Ok(1),
12+
RetCode::NoPyFiles => Ok(2),
13+
RetCode::FailedParsingFile => Ok(3),
14+
RetCode::FailedToWriteReadme => Ok(4),
15+
}
16+
}
17+
18+
#[pymodule]
19+
fn readme_update(m: &Bound<'_, PyModule>) -> PyResult<()> {
20+
m.add_function(wrap_pyfunction!(py_main, m)?)?;
21+
Ok(())
22+
}

0 commit comments

Comments
 (0)