Skip to content

Commit

Permalink
replace all-repos.yaml with a curated list of tools
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 18, 2024
1 parent d57c569 commit 53aacc6
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 220 deletions.
10 changes: 0 additions & 10 deletions .github/pull_request_template.md

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
*.html
*.pyc
*.swp
/all-hooks.json
/build
/node_modules
12 changes: 0 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,3 @@ repos:
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/[email protected]"]
- repo: local
hooks:
- id: no-github-dot-git
name: No need for .git for github/gitlab urls
entry: '(github|gitlab).*\.git'
files: all-repos.yaml
language: pygrep
- id: no-github-trailing-slash
name: No need for trailing / for urls
entry: '.*/$'
files: all-repos.yaml
language: pygrep
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: install-hooks build/main_bs5.css all-hooks.json index.html hooks.html
all: install-hooks build/main_bs5.css index.html hooks.html

.PHONY: install-hooks
install-hooks: venv
Expand All @@ -7,10 +7,7 @@ install-hooks: venv
build/main_bs5.css: node_modules build scss/main_bs5.scss scss/_variables.scss
node_modules/.bin/sass --style=compressed --load-path=. scss/main_bs5.scss build/main_bs5.css

all-hooks.json: venv make_all_hooks.py all-repos.yaml
venv/bin/python make_all_hooks.py

index.html hooks.html: venv all-hooks.json base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md
index.html hooks.html: venv base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md
venv/bin/python make_templates.py

venv: requirements-dev.txt Makefile
Expand All @@ -28,11 +25,10 @@ node_modules: package.json
push: venv
venv/bin/markdown-to-presentation push \
.nojekyll README.md CNAME \
build assets *.html *.png *.svg favicon.ico \
all-hooks.json
build assets *.html *.png *.svg favicon.ico

clean:
rm -rf venv build node_modules *.html all-hooks.json
rm -rf venv build node_modules *.html

build:
mkdir -p build
Expand Down
45 changes: 0 additions & 45 deletions assets/filter_repos.js

This file was deleted.

48 changes: 1 addition & 47 deletions hooks.mako
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,4 @@

<div class="page-header"><h1>Supported hooks</h1></div>

<div class="row mb-4">
<div class="col">
<label for="search-hook-id" class="mb-2">Filter hook id:</label>
<input id="search-hook-id" type="text" placeholder="filter hook id" class="form-control form-control-sm"></input>
</div>
<div class="col">
<label for="search-hook-id" class="mb-2">Filter hook type:</label>
<select id="select-hook-type" class="form-select form-select-sm">
<option value="">--</option>
% for hook_type in sorted(all_types, key=str.lower):
<option value="${hook_type}">${hook_type}</option>
% endfor
</select>
</div>
</div>

<p>
To add to this list, fork <a href="https://github.com/pre-commit/pre-commit.com">this repository</a>.
</p>

<p>
Also available in <a href="/all-hooks.json">json</a>.
</p>

<div id="hooks">
% for repository, hooks in all_hooks.items():
<h3 data-repo="${repository}">
<a href="${repository}" target="_blank">
${repository.replace('https://', '')}
</a>
</h3>
<ul data-repo="${repository}">
% for hook_dict in hooks:
<li data-id="${hook_dict['id']}" data-types="${', '.join(hook_dict.get('types', []) + hook_dict.get('types_or', []))}">
<code>${hook_dict['id']}</code>
% if hook_dict.get('description'):
- ${hook_dict['description']}
% elif hook_dict['name'].lower() != hook_dict['id'].lower():
- ${hook_dict['name']}
% endif
</li>
% endfor
</ul>
% endfor
</div>

<script src="assets/filter_repos.js"></script>
${body}
65 changes: 0 additions & 65 deletions make_all_hooks.py

This file was deleted.

43 changes: 13 additions & 30 deletions make_templates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import annotations

import collections
import json
import os.path
from typing import Any

import mako.lookup
import markupsafe
Expand All @@ -29,13 +26,7 @@
)


ALL_TEMPLATES = [
filename for filename in os.listdir('.')
if filename.endswith('.mako') and filename != 'base.mako'
]


def get_env() -> dict[str, Any]:
def index_body() -> markupsafe.Markup:
body_parts = []
for title, filename in SECTIONS:
div_id, _ = os.path.splitext(os.path.basename(filename))
Expand All @@ -50,30 +41,22 @@ def get_env() -> dict[str, Any]:
f'</div>\n',
),
)
body = markupsafe.Markup().join(body_parts)
return markupsafe.Markup().join(body_parts)

all_hooks = json.loads(
open('all-hooks.json').read(),
object_pairs_hook=collections.OrderedDict,
)
all_types = {
hook_type
for properties in all_hooks.values()
for hook_type in (
properties[0].get('types', []) + properties[0].get('types_or', [])
)
}
return {'all_hooks': all_hooks, 'all_types': all_types, 'body': body}

def hooks_body() -> markupsafe.Markup:
with open('sections/hooks.md') as f:
return md(f.read())


def main() -> int:
env = get_env()
for template in ALL_TEMPLATES:
template_name, _ = os.path.splitext(template)
env['template_name'] = template_name
with open(f'{template_name}.html', 'w') as html_file:
template_obj = template_lookup.get_template(template)
html_file.write(template_obj.render(**env))
with open('index.html', 'w') as f:
tmpl = template_lookup.get_template('index.mako')
f.write(tmpl.render(body=index_body(), template_name='index'))

with open('hooks.html', 'w') as f:
tmpl = template_lookup.get_template('hooks.mako')
f.write(tmpl.render(body=hooks_body(), template_name='hooks'))
return 0


Expand Down
Loading

0 comments on commit 53aacc6

Please sign in to comment.