├── python ├── src │ └── mdplan │ │ ├── tests │ │ ├── __init__.py │ │ ├── test_plot.py │ │ ├── data │ │ │ ├── .gitignore │ │ │ ├── example_repo.tar.gz │ │ │ ├── nested_repo.tar.gz │ │ │ ├── bad_commit_repo.tar.gz │ │ │ ├── README.md │ │ │ └── utils │ │ │ │ ├── package.sh │ │ │ │ ├── unpackage.sh │ │ │ │ └── commit-ammend.sh │ │ ├── test_tree.py │ │ ├── test_count.py │ │ ├── fixtures.py │ │ ├── test_git.py │ │ └── test_parse.py │ │ ├── git │ │ ├── __init__.py │ │ ├── plot.py │ │ └── history.py │ │ ├── __init__.py │ │ ├── task.py │ │ ├── utils.py │ │ ├── data │ │ └── plot_template.html │ │ ├── count.py │ │ ├── __main__.py │ │ ├── tree.py │ │ └── parse.py ├── pyproject.toml └── .gitignore ├── .gitignore ├── javascript ├── babel.config.json ├── package.json ├── __tests__ │ └── count.test.js ├── count.js └── .gitignore ├── images ├── dag.png ├── schedule.png ├── mobile-app.png ├── browser-chart.png ├── burn-up-chart.jpg └── desktop-app.jpg ├── README.md └── LICENSE /python/src/mdplan/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/test_plot.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | .plans 3 | .idea -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/.gitignore: -------------------------------------------------------------------------------- 1 | *_repo 2 | -------------------------------------------------------------------------------- /python/src/mdplan/git/__init__.py: -------------------------------------------------------------------------------- 1 | from .history import * 2 | -------------------------------------------------------------------------------- /javascript/babel.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /images/dag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/dag.png -------------------------------------------------------------------------------- /images/schedule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/schedule.png -------------------------------------------------------------------------------- /images/mobile-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/mobile-app.png -------------------------------------------------------------------------------- /images/browser-chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/browser-chart.png -------------------------------------------------------------------------------- /images/burn-up-chart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/burn-up-chart.jpg -------------------------------------------------------------------------------- /images/desktop-app.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/images/desktop-app.jpg -------------------------------------------------------------------------------- /python/src/mdplan/__init__.py: -------------------------------------------------------------------------------- 1 | from .git import * 2 | from .count import * 3 | from .parse import * 4 | from .task import * 5 | from .tree import * 6 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/example_repo.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/python/src/mdplan/tests/data/example_repo.tar.gz -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/nested_repo.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/python/src/mdplan/tests/data/nested_repo.tar.gz -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/bad_commit_repo.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexgarland/markdown-plan/HEAD/python/src/mdplan/tests/data/bad_commit_repo.tar.gz -------------------------------------------------------------------------------- /python/src/mdplan/task.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | 4 | @dataclass 5 | class Task: 6 | """ 7 | A description of work 8 | """ 9 | 10 | description: str 11 | done: bool 12 | dependencies: list[str] 13 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/README.md: -------------------------------------------------------------------------------- 1 | How this folder works: 2 | 1. You create a _repo folder to create a new test repo (automatically ignored, see .gitignore) 3 | 2. Init git repo within that folder, then commit as you would normally. 4 | 3. Run `utils/package.sh _repo` to create a git-trackable package of the repo to be used in testing. -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/utils/package.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | if [[ "${TRACE-0}" == "1" ]]; then 7 | set -o xtrace 8 | fi 9 | 10 | if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then 11 | echo 'Usage: ./package.sh arg-one arg-two 12 | 13 | Creates a package for the repo. 14 | ' 15 | exit 16 | fi 17 | 18 | main() { 19 | name=$1 20 | tar -czf $name.tar.gz $name 21 | } 22 | 23 | main "$@" 24 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/utils/unpackage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | if [[ "${TRACE-0}" == "1" ]]; then 7 | set -o xtrace 8 | fi 9 | 10 | if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then 11 | echo 'Usage: ./unpackage.sh repo_folder_name 12 | 13 | Expands an example data repo for use in testing. 14 | ' 15 | exit 16 | fi 17 | 18 | main() { 19 | name=$1 20 | tar -xzf $name.tar.gz 21 | } 22 | 23 | main "$@" 24 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/data/utils/commit-ammend.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | if [[ "${TRACE-0}" == "1" ]]; then 7 | set -o xtrace 8 | fi 9 | 10 | if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then 11 | echo 'Usage: ./commit-ammend.sh isodate [author] 12 | 13 | This will ammend the last commit using the given date and optional author. 14 | 15 | ' 16 | exit 17 | fi 18 | 19 | main() { 20 | date=$1 21 | author=${2:-"Martin L King "} 22 | GIT_COMMITTER_DATE="$date" git commit --date="$date" --author="$author" --amend 23 | } 24 | 25 | main "$@" 26 | -------------------------------------------------------------------------------- /javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-plan", 3 | "version": "1.0.0", 4 | "description": "project planning in markdown", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/rexgarland/markdown-plan" 12 | }, 13 | "keywords": [ 14 | "markdown", 15 | "productivity" 16 | ], 17 | "author": "Rex Garland (https://rexgarland.dev/)", 18 | "license": "GPL-3.0-or-later", 19 | "devDependencies": { 20 | "@babel/preset-env": "^7.22.9", 21 | "jest": "^29.6.1" 22 | }, 23 | "jest": { 24 | "transform": { 25 | "^.+\\.[t|j]sx?$": "babel-jest" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /python/src/mdplan/utils.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | import math 3 | 4 | 5 | def gcd(*numbers): 6 | return reduce(math.gcd, numbers) 7 | 8 | 9 | def find_groups(string, grouper): 10 | """ 11 | Returns a list of texts enclosed in grouper. 12 | 13 | E.g. 14 | find_groups('hello {there}', '{}') -> ['there'] 15 | """ 16 | starter = grouper[0] 17 | finisher = grouper[1] 18 | groups = [] 19 | while starter in string: 20 | i1 = string.index(starter) + len(starter) 21 | i2 = string.index(finisher) 22 | groups.append(string[i1:i2]) 23 | string = string[i2 + 1 :] 24 | return groups 25 | 26 | 27 | def pipe(functions): 28 | return lambda x: reduce(lambda a, v: v(a), functions, x) 29 | -------------------------------------------------------------------------------- /python/src/mdplan/data/plot_template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /python/src/mdplan/count.py: -------------------------------------------------------------------------------- 1 | from typing import Optional 2 | 3 | from .tree import Node, Tree 4 | from .task import Task 5 | from .parse import parse_tree 6 | 7 | 8 | def trickle_completion(tree: Tree[Task]): 9 | """ 10 | Trickle-down completion from parent to children. 11 | If a node is done, all its progeny are also marked done. 12 | """ 13 | 14 | def recurse(node: Node[Task], done: Optional[bool] = None): 15 | if done: 16 | node.value.done = True 17 | for child in node.children: 18 | recurse(child, done=node.value.done) 19 | 20 | for root in tree.roots: 21 | recurse(root) 22 | 23 | 24 | def count_all_tasks(plan): 25 | tree = parse_tree(plan) 26 | return len(tree.leaves) 27 | 28 | 29 | def count_remaining_tasks(plan): 30 | tree = parse_tree(plan) 31 | trickle_completion(tree) 32 | remaining_tasks = [leaf.value for leaf in tree.leaves if not leaf.value.done] 33 | return len(remaining_tasks) 34 | -------------------------------------------------------------------------------- /python/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "markdown-plan" 7 | version = "1.0.2" 8 | dependencies = [ 9 | "pygit2~=1.11", 10 | "importlib-resources==5.9.0", 11 | ] 12 | authors = [ 13 | { name="Rex Garland", email="rex@rexgarland.dev" }, 14 | ] 15 | description = "project planning in markdown" 16 | readme = "README.md" 17 | license = { file="LICENSE" } 18 | requires-python = ">=3.9" 19 | classifiers = [ 20 | "Programming Language :: Python :: 3", 21 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 22 | "Operating System :: OS Independent", 23 | ] 24 | 25 | [project.urls] 26 | Source = "https://github.com/rexgarland/markdown-plan" 27 | 28 | [project.scripts] 29 | mdplan = "mdplan.__main__:main" 30 | 31 | [project.optional-dependencies] 32 | tests = [ 33 | "pytest", 34 | ] 35 | 36 | [tool.setuptools] 37 | include-package-data = true 38 | 39 | [tool.setuptools.packages.find] 40 | where = ["src"] 41 | 42 | [tool.setuptools.package-data] 43 | "mdplan.data" = ["*"] 44 | 45 | 46 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/test_tree.py: -------------------------------------------------------------------------------- 1 | from ..tree import TreeBuilder 2 | 3 | 4 | class TestTreeBuilder: 5 | def test_connects_two_levels(self): 6 | builder = TreeBuilder() 7 | a = builder.add("a", indent=0) 8 | b = builder.add("b", indent=1) 9 | assert b.parent == a 10 | 11 | def test_connects_three_levels(self): 12 | builder = TreeBuilder() 13 | builder.add("a", indent=0) 14 | b = builder.add("b", indent=1) 15 | c = builder.add("c", indent=2) 16 | assert c.parent == b 17 | 18 | def test_multiple_siblings_to_parent(self): 19 | builder = TreeBuilder() 20 | a = builder.add("a", indent=0) 21 | b = builder.add("b", indent=1) 22 | c = builder.add("c", indent=1) 23 | assert b.parent == a 24 | assert c.parent == a 25 | 26 | def test_parse_correctly_when_root_is_none(self): 27 | builder = TreeBuilder() 28 | builder.add("a", indent=0) 29 | builder.add("b", indent=1) 30 | c = builder.add("c", indent=0) 31 | d = builder.add("d", indent=1) 32 | assert c.parent == None 33 | assert d.parent == c 34 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/test_count.py: -------------------------------------------------------------------------------- 1 | from ..count import count_all_tasks, count_remaining_tasks 2 | 3 | 4 | def test_counts_a_flat_list(): 5 | plan = """1. first task 6 | 2. second""" 7 | num = count_remaining_tasks(plan) 8 | 9 | assert num == 2 10 | 11 | 12 | def test_only_counts_leaves_as_remaining_tasks(): 13 | plan = """ 14 | 1. create plan 15 | - this is one step 16 | - here is another 17 | 2. edit plan 18 | - something 19 | """ 20 | num = count_remaining_tasks(plan) 21 | 22 | assert num == 3, "should not count the parent tasks" 23 | 24 | 25 | def test_does_not_count_completed_tasks(): 26 | plan = """ 27 | 1. [x] this is done 28 | 2. remaining work 29 | """ 30 | num = count_remaining_tasks(plan) 31 | 32 | assert num == 1 33 | 34 | 35 | def test_does_not_count_subtasks_of_finished_parent(): 36 | plan = """ 37 | 1. [x] parent 38 | - sub1 39 | - sub2""" 40 | num = count_remaining_tasks(plan) 41 | 42 | assert num == 0 43 | 44 | 45 | def test_counts_all_tasks(): 46 | plan = """ 47 | 1. [x] first thing 48 | - do this 49 | - then that 50 | 2. finall, do this""" 51 | num = count_all_tasks(plan) 52 | 53 | assert num == 3 54 | -------------------------------------------------------------------------------- /python/src/mdplan/__main__.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from pathlib import Path 3 | 4 | from .git.history import GitHistory 5 | from .git.plot import GitPlot 6 | 7 | description = """ 8 | A tool for analyzing markdown plans 9 | """ 10 | 11 | epilog = """ 12 | Analysis details: 13 | * history: parses the git history of a plan file, outputting version statistics as JSON 14 | * plot: opens a browser to display a plan's history (as a burn-up chart) 15 | 16 | """ 17 | 18 | 19 | def main(): 20 | parser = argparse.ArgumentParser( 21 | description=description, 22 | epilog=epilog, 23 | formatter_class=argparse.RawDescriptionHelpFormatter, 24 | ) 25 | parser.add_argument( 26 | "command", choices=["history", "plot"], help="the type of analysis to run" 27 | ) 28 | parser.add_argument( 29 | "planfile", 30 | type=Path, 31 | help="the path to a markdown plan", 32 | ) 33 | args = parser.parse_args() 34 | 35 | if args.command == "history": 36 | history = GitHistory(args.planfile) 37 | print(history.to_json()) 38 | if args.command == "plot": 39 | history = GitHistory(args.planfile) 40 | plot = GitPlot(history) 41 | plot.open() 42 | 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /javascript/__tests__/count.test.js: -------------------------------------------------------------------------------- 1 | import { countTasks } from "../count"; 2 | 3 | describe("counting tasks", () => { 4 | it("should count a header", () => { 5 | const plan = "# hello"; 6 | const { total } = countTasks(plan); 7 | expect(total).toBe(1); 8 | }); 9 | 10 | it("should count multi headers", () => { 11 | const plan = "### subheader"; 12 | const { total } = countTasks(plan); 13 | expect(total).toBe(1); 14 | }); 15 | 16 | it("should count a list item", () => { 17 | const plan = "- hello"; 18 | const { total } = countTasks(plan); 19 | expect(total).toBe(1); 20 | }); 21 | 22 | it("should only count leaves", () => { 23 | const plan = `- parent 24 | - child`; 25 | const { total } = countTasks(plan); 26 | expect(total).toBe(1); 27 | }); 28 | 29 | it("should consider not count headers with children", () => { 30 | const plan = `# title 31 | - task`; 32 | const { total } = countTasks(plan); 33 | expect(total).toBe(1); 34 | }); 35 | 36 | it("should handle multiple sublevels", () => { 37 | const plan = `- parent1 38 | - child1 39 | - parent2 40 | - child2`; 41 | const { total } = countTasks(plan); 42 | expect(total).toBe(2); 43 | }); 44 | 45 | it("should count done tasks", () => { 46 | const plan = "- [x] hello"; 47 | const { completed } = countTasks(plan); 48 | expect(completed).toBe(1); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /python/src/mdplan/git/plot.py: -------------------------------------------------------------------------------- 1 | import json 2 | import subprocess 3 | import os 4 | import platform 5 | import tempfile 6 | from importlib_resources import files 7 | 8 | 9 | from .history import GitHistory 10 | 11 | 12 | def native_open(file): 13 | if platform.system() == "Darwin": 14 | subprocess.call(("open", file)) 15 | elif platform.system() == "Windows": 16 | os.startfile(file) 17 | else: 18 | subprocess.call(("xdg-open", file)) 19 | 20 | 21 | class GitPlot: 22 | history: GitHistory 23 | template_path = files("mdplan").joinpath("data").joinpath("plot_template.html") 24 | 25 | def __init__(self, history: GitHistory): 26 | self.history = history 27 | 28 | def to_html(self) -> str: 29 | text = self.history.to_json() 30 | data = json.loads(text) 31 | 32 | def to_total(v): 33 | return {"date": v["date"], "type": "total", "tasks": v["tasks"]["total"]} 34 | 35 | def to_completed(v): 36 | return { 37 | "date": v["date"], 38 | "type": "completed", 39 | "tasks": v["tasks"]["completed"], 40 | } 41 | 42 | totals, completions = zip( 43 | *[(to_total(v), to_completed(v)) for v in data["versions"]] 44 | ) 45 | stacked = list(totals + completions) 46 | values = json.dumps(stacked) 47 | 48 | template = self.template_path.read_text() 49 | html = template.replace("{{values}}", values) 50 | return html 51 | 52 | def open(self): 53 | with tempfile.NamedTemporaryFile(delete=False) as temp: 54 | path = temp.name + ".html" 55 | with open(path, "w") as f: 56 | f.write(self.to_html()) 57 | native_open(path) 58 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/fixtures.py: -------------------------------------------------------------------------------- 1 | from pytest import fixture 2 | from tempfile import TemporaryDirectory 3 | from os.path import dirname 4 | from pathlib import Path 5 | import tarfile 6 | 7 | this_folder = dirname(__file__) 8 | 9 | config_flat = { 10 | "repo_folder": "example_repo", 11 | "repo_archive": "data/example_repo.tar.gz", 12 | "plan_file": "test.plan.md", 13 | } 14 | 15 | config_nested = { 16 | "repo_folder": "nested_repo", 17 | "repo_archive": "data/nested_repo.tar.gz", 18 | "plan_file": "plans/test.plan.md", 19 | } 20 | 21 | config_bad_commit = { 22 | "repo_folder": "bad_commit_repo", 23 | "repo_archive": "data/bad_commit_repo.tar.gz", 24 | "plan_file": "test.plan.md", 25 | } 26 | 27 | 28 | def clone_repo(config, folder): 29 | archive_path = Path(this_folder) / config["repo_archive"] 30 | tar = tarfile.open(archive_path) 31 | tar.extractall(folder) 32 | return Path(folder) / config["repo_folder"] 33 | 34 | 35 | @fixture 36 | def repo(): 37 | with TemporaryDirectory() as tmpdir: 38 | repodir = clone_repo(config_flat, tmpdir) 39 | yield str(repodir) 40 | 41 | 42 | @fixture 43 | def plan(repo): 44 | return str(Path(repo) / config_flat["plan_file"]) 45 | 46 | 47 | @fixture 48 | def repo_nested(): 49 | with TemporaryDirectory() as tmpdir: 50 | repodir = clone_repo(config_nested, tmpdir) 51 | yield str(repodir) 52 | 53 | 54 | @fixture 55 | def plan_nested(repo_nested): 56 | return str(Path(repo_nested) / config_nested["plan_file"]) 57 | 58 | 59 | @fixture 60 | def repo_bad_commit(): 61 | with TemporaryDirectory() as tmpdir: 62 | repodir = clone_repo(config_bad_commit, tmpdir) 63 | yield str(repodir) 64 | 65 | 66 | @fixture 67 | def plan_with_bad_commit(repo_bad_commit): 68 | return str(Path(repo_bad_commit) / config_bad_commit["plan_file"]) -------------------------------------------------------------------------------- /javascript/count.js: -------------------------------------------------------------------------------- 1 | function isHeader(line) { 2 | return line.match(/^#{1,6}\s/); 3 | } 4 | 5 | function isListItem(line) { 6 | return line.match(/^\s*(-|\*)\s/); 7 | } 8 | 9 | function isTask(line) { 10 | return isHeader(line) || isListItem(line); 11 | } 12 | 13 | function parseListLevel(line) { 14 | let num = 0; 15 | for (const char of line) { 16 | if (char === " ") { 17 | num++; 18 | } else { 19 | break; 20 | } 21 | } 22 | return num; 23 | } 24 | 25 | function parseHeaderLevel(headerLine) { 26 | const match = headerLine.match(/^(#{1,6})\s/); 27 | const hashes = match[1]; 28 | return hashes.length; 29 | } 30 | 31 | function parseLevel(taskLine) { 32 | if (isHeader(taskLine)) { 33 | const headerLevel = parseHeaderLevel(taskLine); 34 | // h6 corresponds to -1 35 | return headerLevel - 7; 36 | } 37 | return parseListLevel(taskLine); 38 | } 39 | 40 | function parseDescription(taskLine) { 41 | let match; 42 | if (isHeader(taskLine)) { 43 | match = taskLine.match(/^#{1,6}\s(.*)/); 44 | return match[1]; 45 | } 46 | match = taskLine.match(/^\s*(-|\*)\s(.*)/); 47 | return match[2]; 48 | } 49 | 50 | function isCompleted(taskLine) { 51 | const description = parseDescription(taskLine); 52 | return description.match(/^\s*\[x\]\s/); 53 | } 54 | 55 | function filterLeaves(taskLines) { 56 | const levels = taskLines.map(parseLevel); 57 | 58 | return taskLines.filter((_, i) => { 59 | const isLastLine = i === taskLines.length - 1; 60 | 61 | if (isLastLine) { 62 | return true; 63 | } 64 | 65 | const thisLevel = levels[i]; 66 | const nextLevel = levels[i + 1]; 67 | const isParent = nextLevel > thisLevel; 68 | 69 | return !isParent; 70 | }); 71 | } 72 | 73 | export function countTasks(plan) { 74 | const lines = plan.split("\n"); 75 | 76 | const taskLines = lines.filter(isTask); 77 | const leaveTaskLines = filterLeaves(taskLines); 78 | 79 | const total = leaveTaskLines.length; 80 | 81 | const completed = leaveTaskLines.filter(isCompleted).length; 82 | 83 | return { total, completed }; 84 | } 85 | -------------------------------------------------------------------------------- /python/src/mdplan/tests/test_git.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from .fixtures import * 4 | from ..git.history import GitHistory 5 | 6 | 7 | def test_finds_multiple_versions(plan): 8 | history = GitHistory(plan) 9 | assert len(history) > 1 10 | 11 | 12 | def test_finds_source(plan): 13 | history = GitHistory(plan) 14 | v1 = history[0] 15 | assert ( 16 | v1.source 17 | == """# Test plan 18 | 19 | 1. write a test 20 | 2. watch it fail 21 | 3. make it pass 22 | """ 23 | ) 24 | 25 | 26 | def test_finds_source_from_subdirectory(plan_nested): 27 | history = GitHistory(plan_nested) 28 | v1 = history[0] 29 | assert v1.source 30 | 31 | 32 | def test_finds_correct_dates(plan): 33 | history = GitHistory(plan) 34 | date_strings = [version.datetime.isoformat() for version in history[:5]] 35 | assert date_strings == [ 36 | "2023-01-16T00:00:00+00:00", 37 | "2023-01-17T00:00:00+00:00", 38 | "2023-01-18T00:00:00+00:00", 39 | "2023-01-19T00:00:00+00:00", 40 | "2023-01-21T00:00:00+00:00", 41 | ] 42 | 43 | 44 | def test_finds_correct_statistics(plan): 45 | history = GitHistory(plan) 46 | 47 | total = [v.task_statistics.total for v in history[:5]] 48 | assert total == [3, 4, 4, 5, 5] 49 | 50 | completed = [v.task_statistics.completed for v in history[:5]] 51 | assert completed == [0, 0, 1, 2, 5] 52 | 53 | 54 | expected_data = { 55 | "versions": [ 56 | {"date": "2023-01-16T00:00:00+00:00", "tasks": {"total": 3, "completed": 0}}, 57 | {"date": "2023-01-17T00:00:00+00:00", "tasks": {"total": 4, "completed": 0}}, 58 | {"date": "2023-01-18T00:00:00+00:00", "tasks": {"total": 4, "completed": 1}}, 59 | {"date": "2023-01-19T00:00:00+00:00", "tasks": {"total": 5, "completed": 2}}, 60 | {"date": "2023-01-21T00:00:00+00:00", "tasks": {"total": 5, "completed": 5}}, 61 | ] 62 | } 63 | expected_json = json.dumps(expected_data) 64 | 65 | 66 | def test_renders_correct_json_history(plan): 67 | history = GitHistory(plan) 68 | json = history.to_json() 69 | assert json == expected_json 70 | 71 | def test_does_not_crash_if_encountering_unparseable_commit(plan_with_bad_commit): 72 | history = GitHistory(plan_with_bad_commit) 73 | json = history.to_json() # This could fail because one of the commit has a bad indent. See git log in test repo folder. -------------------------------------------------------------------------------- /python/src/mdplan/tree.py: -------------------------------------------------------------------------------- 1 | from typing import Generic, Optional, Set, Tuple, TypeVar 2 | 3 | V = TypeVar("V") 4 | 5 | 6 | class Node(Generic[V]): 7 | value: V 8 | parent: Optional["Node[V]"] 9 | children: Set["Node"] 10 | 11 | def __init__(self, value): 12 | self.value = value 13 | self.parent = None 14 | self.children = set() 15 | 16 | @classmethod 17 | def adopt(cls, parent: "Node", child: "Node"): 18 | parent.children.add(child) 19 | child.parent = parent 20 | 21 | 22 | class Tree(Generic[V]): 23 | nodes: Set[Node[V]] 24 | 25 | def __init__(self, nodes: list[Node[V]]): 26 | self.nodes = set(nodes) 27 | 28 | @property 29 | def leaves(self) -> Set[Node[V]]: 30 | s = set([node for node in self.nodes if len(node.children) == 0]) 31 | return s 32 | 33 | @property 34 | def roots(self) -> Set[Node[V]]: 35 | return set([node for node in self.nodes if node.parent == None]) 36 | 37 | 38 | Ancestor = Tuple[Node[V], int] # node and its indentation level 39 | 40 | 41 | class TreeBuilder(Generic[V]): 42 | """ 43 | Builds a tree from a list of indented values 44 | """ 45 | 46 | curr_lineage: list[Ancestor[V]] 47 | 48 | def __init__(self): 49 | self.curr_lineage = [] 50 | 51 | def find_placement_in_lineage(self, indent: int) -> int: 52 | i = 0 53 | while i < len(self.curr_lineage) and self.curr_lineage[i][1] < indent: 54 | i += 1 55 | return i 56 | 57 | def place_in_lineage(self, node: Node[V], indent: int) -> Optional[Ancestor[V]]: 58 | i = self.find_placement_in_lineage(indent) 59 | self.curr_lineage[i:] = [(node, indent)] 60 | 61 | def add(self, value: V, indent: int) -> Node[V]: 62 | node = Node(value) 63 | self.place_in_lineage(node, indent) 64 | 65 | node_has_parent = len(self.curr_lineage) > 1 66 | if node_has_parent: 67 | parent, _ = self.curr_lineage[-2] 68 | Node.adopt(parent, node) # connect the two nodes 69 | 70 | return node 71 | 72 | 73 | def build_tree_from_indents(values, indents) -> Tree: 74 | builder = TreeBuilder() 75 | nodes = [] 76 | for (value, indent) in zip(values, indents): 77 | node = builder.add(value, indent=indent) 78 | nodes.append(node) 79 | 80 | return Tree(nodes) 81 | -------------------------------------------------------------------------------- /javascript/.gitignore: -------------------------------------------------------------------------------- 1 | ## gigman[start]: Node 2 | 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | lerna-debug.log* 10 | .pnpm-debug.log* 11 | 12 | # Diagnostic reports (https://nodejs.org/api/report.html) 13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | *.lcov 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # Bower dependency directory (https://bower.io/) 35 | bower_components 36 | 37 | # node-waf configuration 38 | .lock-wscript 39 | 40 | # Compiled binary addons (https://nodejs.org/api/addons.html) 41 | build/Release 42 | 43 | # Dependency directories 44 | node_modules/ 45 | jspm_packages/ 46 | 47 | # Snowpack dependency directory (https://snowpack.dev/) 48 | web_modules/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional stylelint cache 60 | .stylelintcache 61 | 62 | # Microbundle cache 63 | .rpt2_cache/ 64 | .rts2_cache_cjs/ 65 | .rts2_cache_es/ 66 | .rts2_cache_umd/ 67 | 68 | # Optional REPL history 69 | .node_repl_history 70 | 71 | # Output of 'npm pack' 72 | *.tgz 73 | 74 | # Yarn Integrity file 75 | .yarn-integrity 76 | 77 | # dotenv environment variable files 78 | .env 79 | .env.development.local 80 | .env.test.local 81 | .env.production.local 82 | .env.local 83 | 84 | # parcel-bundler cache (https://parceljs.org/) 85 | .cache 86 | .parcel-cache 87 | 88 | # Next.js build output 89 | .next 90 | out 91 | 92 | # Nuxt.js build / generate output 93 | .nuxt 94 | dist 95 | 96 | # Gatsby files 97 | .cache/ 98 | # Comment in the public line in if your project uses Gatsby and not Next.js 99 | # https://nextjs.org/blog/next-9-1#public-directory-support 100 | # public 101 | 102 | # vuepress build output 103 | .vuepress/dist 104 | 105 | # vuepress v2.x temp and cache directory 106 | .temp 107 | .cache 108 | 109 | # Docusaurus cache and generated files 110 | .docusaurus 111 | 112 | # Serverless directories 113 | .serverless/ 114 | 115 | # FuseBox cache 116 | .fusebox/ 117 | 118 | # DynamoDB Local files 119 | .dynamodb/ 120 | 121 | # TernJS port file 122 | .tern-port 123 | 124 | # Stores VSCode versions used for testing VSCode extensions 125 | .vscode-test 126 | 127 | # yarn v2 128 | .yarn/cache 129 | .yarn/unplugged 130 | .yarn/build-state.yml 131 | .yarn/install-state.gz 132 | .pnp.* 133 | 134 | 135 | ## gigman[end]: Node -------------------------------------------------------------------------------- /python/src/mdplan/tests/test_parse.py: -------------------------------------------------------------------------------- 1 | from ..parse import is_task, parse_task, parse_tree 2 | 3 | 4 | class TestIsTask: 5 | def test_recognizes_list_item(self): 6 | line = "- hello" 7 | assert is_task(line) 8 | line = "1. hello" 9 | assert is_task(line), "Could not recognize numbered task" 10 | line = " 1. hello" 11 | assert is_task(line), "Could not recognize task with indentation" 12 | 13 | def test_recognizes_header(self): 14 | line = "# hello" 15 | assert is_task(line) 16 | line = "## hello" 17 | assert is_task(line), "Could not recognize h2 as task" 18 | 19 | def test_ignores_block_quote(self): 20 | line = "> * hello" 21 | assert not is_task(line) 22 | 23 | def test_ignores_horizontal_line(self): 24 | line = "***" 25 | assert not is_task(line) 26 | 27 | 28 | class TestParseTask: 29 | def test_captures_description(self): 30 | line = " - hello @(world)" 31 | task = parse_task(line) 32 | assert task.description == "hello" 33 | 34 | def test_description_excludes_done(self): 35 | line = "- [x] hello" 36 | task = parse_task(line) 37 | assert task.description == "hello" 38 | 39 | def test_description_excludes_empty_checkbox(self): 40 | line = "- [ ] hello" 41 | task = parse_task(line) 42 | assert task.description == "hello" 43 | 44 | def test_captures_is_done(self): 45 | line = "- [x] hello" 46 | task = parse_task(line) 47 | assert task.done 48 | 49 | def test_captures_empty_done(self): 50 | line = "- [ ] hello" 51 | task = parse_task(line) 52 | assert not task.done 53 | 54 | def test_captures_dependencies(self): 55 | line = "- [x] hello @(world, universe)" 56 | task = parse_task(line) 57 | assert "world" in task.dependencies 58 | assert "universe" in task.dependencies 59 | 60 | 61 | class TestParseTree: 62 | def test_contains_appropriate_leaves(self): 63 | plan = """ 64 | - one 65 | - two 66 | """ 67 | tree = parse_tree(plan) 68 | assert len(tree.leaves) == 1 69 | assert tree.leaves.pop().value.description == "two" 70 | 71 | def test_correctly_finds_children(self): 72 | plan = """ 73 | - parent 74 | - child1 75 | - child2 76 | """ 77 | tree = parse_tree(plan) 78 | parent = [node for node in tree.nodes if node.value.description == "parent"][0] 79 | assert len(parent.children) == 2 80 | 81 | def test_ignores_code_blocks(self): 82 | plan = """ 83 | - task1 84 | ``` 85 | - task2 86 | ``` 87 | """ 88 | tree = parse_tree(plan) 89 | assert len(tree.nodes) == 1 90 | 91 | def test_allows_for_indentation_jumps(self): 92 | # some markdown formatters do this by default 93 | plan = """ 94 | 1. first 95 | - second 96 | - third 97 | - fourth 98 | """ 99 | tree = parse_tree(plan) 100 | assert len(tree.roots) == 1 101 | assert len(tree.leaves) == 2 102 | first = tree.roots.pop() 103 | assert len(first.children) == 2 104 | third = (tree.leaves - first.children).pop() 105 | assert third 106 | -------------------------------------------------------------------------------- /python/src/mdplan/git/history.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from collections.abc import Sequence 3 | from datetime import datetime, timedelta, timezone 4 | from pathlib import Path 5 | from typing import Optional 6 | import pygit2 7 | import json 8 | 9 | from ..tree import Tree 10 | from ..task import Task 11 | from ..parse import parse_tree 12 | from ..count import count_all_tasks, count_remaining_tasks 13 | 14 | 15 | @dataclass 16 | class TaskStatistics: 17 | total: int 18 | completed: int 19 | 20 | def as_data(self): 21 | data = {"total": self.total, "completed": self.completed} 22 | return data 23 | 24 | 25 | class GitVersion: 26 | commit: pygit2.Commit 27 | source: str 28 | 29 | def __init__(self, commit, source): 30 | self.commit = commit 31 | self.source = source 32 | 33 | def __iter__(self): 34 | yield self 35 | 36 | @property 37 | def tree(self) -> Tree[Task]: 38 | return parse_tree(self.source) 39 | 40 | @property 41 | def datetime(self) -> datetime: 42 | timestamp = self.commit.commit_time 43 | offset = self.commit.commit_time_offset 44 | tz = timezone(timedelta(minutes=offset)) 45 | return datetime.fromtimestamp(timestamp, tz) 46 | 47 | @property 48 | def task_statistics(self) -> TaskStatistics: 49 | total = count_all_tasks(self.source) 50 | completed = total - count_remaining_tasks(self.source) 51 | return TaskStatistics(total=total, completed=completed) 52 | 53 | def as_data(self): 54 | data = { 55 | "date": self.datetime.isoformat(), 56 | "tasks": self.task_statistics.as_data(), 57 | } 58 | return data 59 | 60 | 61 | def is_repo(folder: Path): 62 | gitdir = folder / ".git" 63 | return gitdir.exists() 64 | 65 | 66 | def find_closest_repo(path: Path): 67 | for folder in path.parents: 68 | if is_repo(folder): 69 | return folder 70 | raise Exception("Could not find a git repo containing '{path}'") 71 | 72 | 73 | class GitHistory(Sequence): 74 | plan: Path 75 | repo: Path 76 | versions: list[GitVersion] 77 | 78 | def __init__(self, planfile): 79 | self.plan = Path(planfile).absolute() 80 | self.repo = find_closest_repo(self.plan) 81 | self.find_versions() 82 | 83 | super().__init__() 84 | 85 | def __getitem__(self, index): 86 | return self.versions[index] 87 | 88 | def __len__(self): 89 | return len(self.versions) 90 | 91 | def read_source_from_commit(self, commit: pygit2.Commit) -> Optional[str]: 92 | tree = commit.tree 93 | relpath = self.plan.relative_to(self.repo) 94 | try: 95 | blob = tree[str(relpath)] 96 | if blob: 97 | return blob.data.decode("utf-8") 98 | except: 99 | pass 100 | 101 | def find_versions(self): 102 | self.versions = [] 103 | repo = pygit2.Repository(self.repo) 104 | for commit in repo.walk(repo.head.target): 105 | source = self.read_source_from_commit(commit) 106 | if source: 107 | version = GitVersion(commit, source) 108 | self.versions.append(version) 109 | self.versions.sort(key=lambda v: v.datetime) 110 | 111 | def to_json(self) -> str: 112 | version_jsons = [] 113 | 114 | for version in self.versions: 115 | try: 116 | json_txt = version.as_data() 117 | version_jsons.append(json_txt) 118 | except Exception as e: 119 | # Just ignore it as a bad commit. 120 | # Sometimes one of the commits will not parse, e.g. because of indent error. 121 | print(e) 122 | 123 | data = {"versions": version_jsons} 124 | return json.dumps(data) 125 | -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | 3 | ## gigman[start]: Python 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | cover/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | .pybuilder/ 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | # For a library or package, you might want to ignore these files since the code is 91 | # intended to run in multiple environments; otherwise, check them in: 92 | # .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # poetry 102 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 103 | # This is especially recommended for binary packages to ensure reproducibility, and is more 104 | # commonly ignored for libraries. 105 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 106 | #poetry.lock 107 | 108 | # pdm 109 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 110 | #pdm.lock 111 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 112 | # in version control. 113 | # https://pdm.fming.dev/#use-with-ide 114 | .pdm.toml 115 | 116 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 117 | __pypackages__/ 118 | 119 | # Celery stuff 120 | celerybeat-schedule 121 | celerybeat.pid 122 | 123 | # SageMath parsed files 124 | *.sage.py 125 | 126 | # Environments 127 | .env 128 | .venv 129 | env/ 130 | venv/ 131 | ENV/ 132 | env.bak/ 133 | venv.bak/ 134 | 135 | # Spyder project settings 136 | .spyderproject 137 | .spyproject 138 | 139 | # Rope project settings 140 | .ropeproject 141 | 142 | # mkdocs documentation 143 | /site 144 | 145 | # mypy 146 | .mypy_cache/ 147 | .dmypy.json 148 | dmypy.json 149 | 150 | # Pyre type checker 151 | .pyre/ 152 | 153 | # pytype static type analyzer 154 | .pytype/ 155 | 156 | # Cython debug symbols 157 | cython_debug/ 158 | 159 | # PyCharm 160 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 161 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 162 | # and can be added to the global gitignore or merged into this file. For a more nuclear 163 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 164 | #.idea/ 165 | 166 | 167 | ## gigman[end]: Python 168 | -------------------------------------------------------------------------------- /python/src/mdplan/parse.py: -------------------------------------------------------------------------------- 1 | from datetime import date, datetime 2 | import re 3 | 4 | from . import utils 5 | from .task import Task 6 | from .tree import Tree, build_tree_from_indents 7 | 8 | TODAY = date.today() 9 | NOW = datetime.now() 10 | 11 | 12 | WHITESPACE = [" ", "\t"] 13 | 14 | 15 | def get_initial_white(string): 16 | text = "" 17 | for char in string: 18 | if char in WHITESPACE: 19 | text += char 20 | else: 21 | return text 22 | return "" 23 | 24 | 25 | LIST_MARKERS = ["*", "-"] 26 | 27 | 28 | def is_header(word): 29 | return all([c == "#" for c in word]) 30 | 31 | 32 | def is_task(line): 33 | # task lines must start with a marker (after any initial indent whitespace) 34 | stripped = line.strip() 35 | if not stripped: 36 | return False 37 | first_word = stripped.split(" ")[0] 38 | if first_word in LIST_MARKERS: 39 | return True 40 | if is_header(first_word): 41 | return True 42 | if first_word[0].isnumeric() and first_word[-1] == ".": 43 | return all([c.isnumeric() for c in first_word[:-1]]) 44 | return False 45 | 46 | 47 | def get_dependencies(string): 48 | groups = utils.find_groups(string, ["@(", ")"]) 49 | if not groups: 50 | return [] 51 | assert len(groups) == 1 52 | string = groups[0] 53 | splits = string.split(",") 54 | return [split.strip() for split in splits] 55 | 56 | 57 | def is_done(line): 58 | for text in utils.find_groups(line, "[]")[:1]: 59 | if text == "x": 60 | return True 61 | return False 62 | 63 | 64 | def indent_level(line, single_indent="\t"): 65 | stripped_line = line.strip() 66 | first_printable = stripped_line[0] 67 | first_index = line.index(first_printable) 68 | level = line[:first_index].count(single_indent) 69 | return level 70 | 71 | 72 | def calculate_nesting_level(line, single_indent="\t"): 73 | """ 74 | Returns the nesting level. 75 | 76 | For headers, it is negative, with -6 being h1 and -1 being h6. 77 | For list items, it is non-negative, starting at 0 for no indentation. 78 | """ 79 | stripped_line = line.strip() 80 | first_printable = stripped_line[0] 81 | if first_printable == "#": 82 | num_hashes = stripped_line.split(" ")[0].count("#") 83 | return -7 + num_hashes 84 | else: 85 | return indent_level(line, single_indent) 86 | 87 | 88 | def get_description(content): 89 | start, end = 0, len(content) 90 | if is_done(content): 91 | start = 3 92 | elif content.startswith("[ ]"): 93 | start = 3 94 | if re.search(r"""@\(.*\)""", content): 95 | end = content.find("@(") 96 | return content[start:end].strip() 97 | 98 | 99 | def infer_indent(text) -> str: 100 | lines = text.split("\n") 101 | indents = [get_initial_white(line) for line in lines if is_task(line)] 102 | indents = [indent for indent in indents if indent] 103 | if not indents: 104 | return "\t" # default 105 | chartype = indents[0][0] 106 | together = "".join(indents) 107 | assert together.count(chartype) == len(together), "Indentation must be consistent" 108 | counts = {len(indent) for indent in indents} 109 | return utils.gcd(*counts) * chartype 110 | 111 | 112 | def lstrip(chars): 113 | def strip_fn(text): 114 | index = 0 115 | while index < len(text) and text[index] in chars: 116 | index += 1 117 | return text[index:] 118 | 119 | return strip_fn 120 | 121 | 122 | def strip_headers(line): 123 | return lstrip(["#"])(line) 124 | 125 | 126 | def strip_list_markers(line): 127 | if line: 128 | if line[0] == "-": 129 | return line[1:] 130 | if line[0].isnumeric(): 131 | no_left_numbers = lstrip("1234567890")(line) 132 | if no_left_numbers and no_left_numbers[0] == ".": 133 | return no_left_numbers[1:] 134 | return line 135 | 136 | 137 | def strip_left_whitespace(line): 138 | return lstrip([" ", "\t"])(line) 139 | 140 | 141 | def strip_markdown(line): 142 | return utils.pipe( 143 | [ 144 | strip_left_whitespace, 145 | strip_headers, 146 | strip_list_markers, 147 | strip_left_whitespace, 148 | ] 149 | )(line) 150 | 151 | 152 | def parse_task(line): 153 | content = strip_markdown(line) 154 | done = is_done(content) 155 | description = get_description(content) 156 | dependencies = get_dependencies(content) 157 | return Task(description=description, done=done, dependencies=dependencies) 158 | 159 | 160 | def sliding_pairs(arr: list): 161 | return [(arr[i], arr[i + 1]) for i in range(len(arr) - 1)] 162 | 163 | 164 | def is_code_block_delimiter(line): 165 | return line.startswith("```") 166 | 167 | 168 | def remove_code_blocks(lines: list[str]) -> list[str]: 169 | out = [] 170 | in_code_block = False 171 | for line in lines: 172 | if in_code_block: 173 | if is_code_block_delimiter(line): 174 | in_code_block = False 175 | else: 176 | if is_code_block_delimiter(line): 177 | in_code_block = True 178 | else: 179 | out.append(line) 180 | return out 181 | 182 | 183 | def parse_tree(plan: str) -> Tree[Task]: 184 | indent = infer_indent(plan) 185 | lines = plan.splitlines() 186 | lines = remove_code_blocks(lines) 187 | filtered_lines = [line for line in lines if is_task(line)] 188 | indents = [calculate_nesting_level(line, indent) for line in filtered_lines] 189 | tasks = [parse_task(line) for line in filtered_lines] 190 | tree = build_tree_from_indents(tasks, indents) 191 | return tree 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # markdown-plan 2 | 3 | `markdown-plan` is a project planning syntax for markdown. 4 | 5 | ```md 6 | # Example plan 7 | 8 | 1. [x] This task is done 9 | 2. This one is bigger 10 | - It has sub-tasks 11 | - This one is unique 12 | - This one depends on @(unique) 13 | ``` 14 | 15 | Writing your plan in markdown offers some unique benefits: 16 | 17 | - Tracking it in version control 18 | - Plotting progress over time to calculate better ETAs 19 | - Documenting changes to the plan 20 | - Visualizing a plan (e.g. as a DAG of tasks) 21 | - Easily sharing a plan with others 22 | 23 | All of these things make planning more transparent and flexible to change. 24 | 25 | ## Syntax 26 | 27 | Any line formatted as a list item or header is a task. 28 | 29 | ```md 30 | # Title task 31 | 32 | - child task 33 | ``` 34 | 35 | Everything else is ignored. 36 | 37 | ````md 38 | - first task 39 | 40 | This paragraph is ignored. 41 | 42 | - second task 43 | 44 | ``` 45 | A code block, also ignored. 46 | ``` 47 | ```` 48 | 49 | Tasks can be organized into hierarchical lists, ordered or unordered. 50 | 51 | ```md 52 | 1. first 53 | - these tasks 54 | - in parallel 55 | 2. second, after first 56 | ``` 57 | 58 | A task can be marked as "done" with an `[x]` at the beginning: 59 | 60 | ``` 61 | - [x] my finished task 62 | - [ ] todo 63 | ``` 64 | 65 | Tasks can also have explicit dependencies using the `@(...)` syntax, although this is rarely needed. 66 | 67 | ```md 68 | - task1 69 | - task2 70 | - must be last @(task1, task2) 71 | ``` 72 | 73 | Each dependency is a unique substring of the task it depends on. 74 | The substring cannot include commas. 75 | 76 | ### Parsing 77 | 78 | Any valid plan can be parsed into a [tree]() or a [DAG](https://en.wikipedia.org/wiki/Directed_acyclic_graph), depending on the user's needs. 79 | 80 | It is possible to create cyclic dependencies using the dependency notation above. 81 | A plan with cyclic dependencies is not a valid plan. 82 | 83 | ## Extensions 84 | 85 | The core syntax described above is as simple as possible by design. But it is useful to extend it, like add optional dates and time intervals to tasks. 86 | See the Gantt example below. 87 | 88 | Any "extended" syntax must still be parseable as a "vanilla" markdown plan, as specified by this document. 89 | 90 | ## Installing 91 | 92 | ```sh 93 | pipx install markdown-plan 94 | ``` 95 | 96 | ## Usage 97 | 98 | This repo only ships with some basic CLI tools and a parsing library. 99 | See examples below for more sophisticated tools. 100 | 101 | Basic usage: 102 | 103 | ```shell 104 | # create example.plan.md, commit changes to it with git 105 | 106 | # then, from within that git repo... 107 | mdplan history example.plan.md # outputs json 108 | mdplan plot example.plan.md # opens a plot 109 | ``` 110 | 111 | ![Burn-up chart in browser](images/browser-chart.png) 112 | 113 | ### Library 114 | 115 | Example usage: counting tasks, displaying a task 116 | 117 | ```python 118 | from mdplan.parse import parse_tree 119 | 120 | # ... get the plan text ... 121 | tree = parse_tree(plan_text) 122 | 123 | # count the leaves 124 | num_tasks = len(tree.leaves) 125 | 126 | # display the root task's description 127 | root = tree.roots.pop() 128 | task = root.value 129 | print(task.description) 130 | 131 | # ... see the Tree, Node, and Task classes for details 132 | ``` 133 | 134 | Example usage: getting data from multiple commits 135 | 136 | ```python 137 | from mdplan.git import GitHistory 138 | 139 | # ... get the path to a plan ... 140 | history = GitHistory(path) 141 | 142 | # a history is just a chronological list of versions 143 | dates = [version.datetime for version in history] 144 | trees = [version.tree for version in history] 145 | statistics = [version.task_statistics for version in history] 146 | 147 | # ... see the GitVersion class for more details 148 | ``` 149 | 150 | ## Testing 151 | 152 | Python code: 153 | 154 | ```sh 155 | cd python 156 | 157 | # create virtual environment (try pipx instead if this fails) 158 | python3 -m venv venv 159 | source venv/bin/activate 160 | python3 -m pip install . 161 | 162 | # run all tests 163 | pytest 164 | ``` 165 | 166 | ## Examples 167 | 168 | There are various other tools / repos for visualizing a plan. For example... 169 | 170 | A Gantt chart generated from a markdown plan ([topological ordering](https://en.wikipedia.org/wiki/Topological_sorting)): 171 | 172 | ![Example schedule](images/schedule.png) 173 | 174 | A little [desktop app](https://github.com/rexgarland/SimplePlanner), for those who don't want to think about git. 175 | 176 | ![Desktop app](images/desktop-app.jpg) 177 | 178 | A [mobile app](https://rexgarland.dev/app/markdown-plan/), for on-the-go. 179 | 180 | ![mobile app screenshot](images/mobile-app.png) 181 | 182 | Visualizing a markdown plan as a [DAG](https://en.wikipedia.org/wiki/Directed_acyclic_graph) of tasks ([demo](https://rexgarland.dev/app/markdown-plan-web)): 183 | 184 | ![Generated DAG](images/dag.png) 185 | 186 | ## Motivation 187 | 188 | The main goal is to make planning easier and more useful. 189 | Ultimately, planning should help us answer questions like: 190 | 191 | - "When will this be done?" 192 | - "How are we doing so far?" 193 | - "What actually happened?" 194 | 195 | Good plans should be: 196 | 197 | - easy to create 198 | - easy to adapt 199 | - easy to share 200 | 201 | Plans that are hard to read or write are difficult to share. 202 | 203 | Plans that are easy to edit encourage adapting to change. 204 | Editing is easier if the history of edits is never lost, and each edit can be documented. 205 | 206 | If a plan is easy to parse, people are encouraged to build their own tools to help interpret the plan. 207 | 208 | ## Prior Art 209 | 210 | This project was inspired by Thomas Figg's "[Programming is Terrible](https://www.youtube.com/watch?v=csyL9EC0S0c)," Andrew Steel's [gantt](https://github.com/andrew-ls/gantt) repo, Dave Farley's video "[How to Estimate Software Development Time](https://www.youtube.com/watch?v=v21jg8wb1eU)," and Allen Holub's talk "[No Estimates](https://www.youtube.com/watch?v=QVBlnCTu9Ms)" (itself inspired by the book by [Vasco Duarte](https://www.amazon.com/NoEstimates-Measure-Project-Progress-Estimating-ebook/dp/B01FWMSBBK)). 211 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------