Skip to main content

docs-that-run

docs-that-run 是一個輕量級的 Markdown 文件驗證工具。它只會辨識明確標記 dtr-run 的 Python 與 Bash fenced code block,並在使用者明確允許及確認後, 按照文件中的順序執行。

功能範圍

  • 只讀取本機 .md Markdown 文件。
  • 只支援 Python(pythonpy)與 Bash(bashsh)。
  • 只處理語言標籤後含有 dtr-run 的程式碼區塊。
  • 預設只掃描,不執行任何程式碼。
  • 必須提供 --allow-exec,並在提示中回答 y 才會執行。
  • 每個程式碼區塊預設最多執行 30 秒。
  • 區塊依照 Markdown 中的順序執行。
  • 同一次執行共用一個保留的暫存工作目錄,因此可以跨區塊共享檔案。
  • 每個區塊使用獨立程序,不保留 Python 狀態、cdexport 狀態。
  • 顯示成功或失敗、stdout、stderr、執行時間與工作目錄。

需求

  • Python 3.9 或更新版本
  • 若要執行 Bash 區塊,本機必須有 Bash。Windows 可使用 Git for Windows 提供的 Bash。

本工具不會下載遠端文件,也不會替程式碼安裝依賴套件。

安裝

從專案根目錄安裝:

python -m pip install .

開發與測試安裝:

python -m pip install -e ".[test]"

使用

未指定檔案時掃描 README.md

dtr

掃描指定檔案:

dtr README.md

掃描多個檔案:

dtr README.md examples/sample_readme.md

以上指令都不會執行程式碼。只有明確加入 --allow-exec 才會進入執行確認:

dtr README.md --allow-exec

看到確認提示後輸入 y 才會執行;輸入其他內容或無法讀取輸入時會取消。

標記語法

以下是可放入其他 Markdown 文件的標記語法展示:

```python dtr-run
print("Hello from docs-that-run")
```

```bash dtr-run
printf '%s\n' 'shared from Bash' > shared_file.txt
```

```python dtr-run
from pathlib import Path

print(Path("shared_file.txt").read_text(encoding="utf-8").strip())
```

沒有 dtr-run 的區塊只會作為一般文件範例,不會執行:

print("This block is not executable")

測試

pytest

測試用 Markdown 位於 tests/fixtures/,可手動執行的完整範例位於 examples/sample_readme.md

安全注意事項

--allow-exec 會在本機直接執行文件中的程式碼。v0.1 沒有沙箱、CPU、 記憶體或檔案系統隔離;請只執行你信任的文件。

v0.1 限制

  • 不支援 Python 與 Bash 以外的語言。
  • 不支援遠端文件或遠端 repository。
  • 不安裝程式碼所需依賴,也不管理虛擬環境。
  • 不支援互動式、平行或圖形介面程式。
  • 不在區塊之間共享 Python 變數、shell 環境變數或 cd 狀態。
  • 只輸出終端機報告,不產生 HTML、JSON 或 JUnit 報告。
  • 沒有沙箱與資源限制;timeout 只限制執行時間。

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docs_that_run-0.1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docs_that_run-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file docs_that_run-0.1.0.tar.gz.

File metadata

  • Download URL: docs_that_run-0.1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for docs_that_run-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a66cd497319a0119edbde205a853948723807a7bb0c9e7838921b47f7c9f9b3e
MD5 7d5d6e9ad86258869513a178aa1b2ad0
BLAKE2b-256 e4b84f97af43c5ff1ffd2bb8f93f040ad118570269218e0def8c8e750f0f25f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for docs_that_run-0.1.0.tar.gz:

Publisher: release.yml on gfr211306-crypto/docs-that-run

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docs_that_run-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docs_that_run-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for docs_that_run-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14b5c0026563eb47aef1c7290b9702750f690c231be712cb6e93b645a05d127f
MD5 924e34d08d418f12b4058b8176a8eeb5
BLAKE2b-256 239803308703aa8a0bc70d9bc1497905b35b05b167055c684d0b3f468eafe7fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for docs_that_run-0.1.0-py3-none-any.whl:

Publisher: release.yml on gfr211306-crypto/docs-that-run

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page