Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds pre-commit hooks to fix/enforce some conventions like automatically formatting the Agda import block insider `<details>` block. - Closes #491 - Add infrastructure for #448 The hooks are written in Python for ease (also for the CI in the future) and are run using [pre-commit](https://pre-commit.com/). The idea is once you have staged all your changes, you can run (which by default also runs `make check`): ```bash make pre-commit ``` It will automatically fix any formatting issues. In principle, we could also add checks for other conventions in the future, like the ones described in CONVENTIONS.md Oh. I also changed CITATION.md as Github encourages to use the .cff extension. - [x] Update the CI to run pre-commit
- Loading branch information
1 parent
5adb594
commit c5ad5a0
Showing
534 changed files
with
1,515 additions
and
1,409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
fail_fast: false | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
|
||
- repo: local | ||
hooks: | ||
|
||
- id: remove-extra-blank-lines | ||
name: Remove extra blank lines | ||
entry: hooks/remove-extra-blank.py | ||
language: python | ||
always_run: true | ||
verbose: true | ||
files: ^src\/.+\.lagda\.md$ | ||
types_or: [markdown, text] | ||
args: [] | ||
require_serial: false | ||
|
||
- id: fix-imports | ||
name: Format Agda imports | ||
entry: hooks/fix-imports.py | ||
language: python | ||
always_run: true | ||
verbose: true | ||
files: ^src\/.+\.lagda\.md$ | ||
types_or: [markdown, text] | ||
args: [] | ||
require_serial: false | ||
|
||
# - repo: https://github.com/pre-commit/mirrors-prettier | ||
# rev: "v3.0.0-alpha.6" | ||
# hooks: | ||
# - id: prettier | ||
# types_or: [css, javascript, markdown,yaml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
## Citing the Agda-UniMath library | ||
|
||
```md | ||
@misc{Agda-UniMath, | ||
author = {Egbert Rijke and Elisabeth Bonnevier and Jonathan Prieto-Cubides and others}, | ||
title = {Univalent mathematics in {Agda}}, | ||
url = {https://github.com/UniMath/agda-unimath/}, | ||
howpublished = {\url{https://unimath.github.io/agda-unimath/}} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
# Statement of inclusion | ||
|
||
There are many reasons to contribute something to a library of formalized mathematics. Some do it just for fun, some do it for their research, some do it to learn something. Whatever your reason is, we welcome your contributions! To keep the experience of contributing something to our library enjoyable for everyone, we strive for an inclusive community of contributors. You can expect from us that we are kind and respectful in discussions, that we will be mindful of your pronouns and use [inclusive language](https://www.apa.org/about/apa/equity-diversity-inclusion/language-guidelines), and that we value your input regardless of your level of experience or status in the community. We're commited to providing a safe and welcoming environment to people of any gender identity, sexual orientation, race, colour, age, ability, ethnicity, background, or fluency in English -- here on GitHub, in online communication channels, and in person. Homotopy type theory is difficult enough without all the barriers that many of us have to face, so we hope to bring some of those down a bit. | ||
There are many reasons to contribute something to a library of formalized mathematics. Some do it just for fun, some do it for their research, some do it to learn something. Whatever your reason is, we welcome your contributions! To keep the experience of contributing something to our library enjoyable for everyone, we strive for an inclusive community of contributors. You can expect from us that we are kind and respectful in discussions, that we will be mindful of your pronouns and use [inclusive language](https://www.apa.org/about/apa/equity-diversity-inclusion/language-guidelines), and that we value your input regardless of your level of experience or status in the community. We're commited to providing a safe and welcoming environment to people of any gender identity, sexual orientation, race, colour, age, ability, ethnicity, background, or fluency in English -- here on GitHub, in online communication channels, and in person. Homotopy type theory is difficult enough without all the barriers that many of us have to face, so we hope to bring some of those down a bit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name: agda-unimath | ||
include: src | ||
flags: --without-K --exact-split --no-import-sorts --auto-inline | ||
flags: --without-K --exact-split --no-import-sorts --auto-inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Grant Acknowledgements | ||
|
||
- The [TydiForm project](https://tydiform.fmf.uni-lj.si) (2020-Present). Air Force Office of Scientific Research, award number FA9550-21-1-0024. | ||
- The [TydiForm project](https://tydiform.fmf.uni-lj.si) (2020-Present). Air Force Office of Scientific Research, award number FA9550-21-1-0024. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
We have included Python hooks which should run on almost any platform. | ||
|
||
Install pre-commit | ||
|
||
``` | ||
pip install pre-commit | ||
``` | ||
|
||
Next time you commit, pre-commit will run the hooks. | ||
|
||
``` | ||
make pre-commit | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
# Run this script: | ||
# $ python3 hooks/fix-imports.py fileName.lagda.md | ||
|
||
import sys | ||
import utils | ||
|
||
status = 0 | ||
|
||
for fpath in utils.agdaFiles(sys.argv[1:]): | ||
with open(fpath, 'r', encoding='UTF-8') as file: | ||
contents = file.read() | ||
start = contents.find('<details>') | ||
end = contents.find('</details>') | ||
if start != -1 and end != -1: | ||
block = contents[start:end] | ||
newBlock = filter(lambda l: l.strip() != '', block.split('\n')) | ||
publicImports = [] | ||
nonPublicImports = [] | ||
otherStuff = [] | ||
|
||
for l in newBlock: | ||
if l.startswith('```') or len(l.strip()) == 0: | ||
continue | ||
if l.startswith('module') or l.startswith('{-# OPTIONS'): | ||
print( | ||
'Error: module decl./pragmas can not be in the details import block\n\ | ||
Please put it in the first Agda block after the first header\n') | ||
sys.exit(1) | ||
elif 'open import' in l: | ||
if l.endswith('public'): | ||
publicImports.append(l) | ||
else: | ||
nonPublicImports.append(l) | ||
elif 'open' in l: | ||
otherStuff.append(l) | ||
|
||
if len(otherStuff) > 0: | ||
|
||
print( | ||
'Warning: Please review the imports block, it contains non-imports statements:\n\t' + str(fpath) ) | ||
imports = '\n'.join( | ||
map(lambda ls: '\n'.join(sorted(ls)), | ||
filter(lambda ls: len(ls) > 0, | ||
[ | ||
publicImports, nonPublicImports, otherStuff]))) | ||
|
||
importBlock = '<details><summary>Imports</summary>\n' + \ | ||
'\n```agda\n' +\ | ||
imports + \ | ||
'\n```\n\n' | ||
|
||
newContent = contents[:start] + \ | ||
importBlock + \ | ||
contents[end:] | ||
with open(fpath, 'w') as file: | ||
file.write(newContent) | ||
else: | ||
agdaBlockStart = utils.find_index(contents,'```agda') | ||
if len(agdaBlockStart) > 1: | ||
print('Warning: No Agda import block found inside <details> block in:\n\t' + str(fpath)) | ||
status = 1 | ||
sys.exit(status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
# Run this script: | ||
# $ python3 hooks/remove-extra-blank.py fileName.lagda.md | ||
|
||
import sys | ||
import utils | ||
import re | ||
|
||
for fpath in utils.agdaFiles(sys.argv[1:]): | ||
with open(fpath, "r") as f: | ||
inputText = f.read() | ||
output = re.sub(r"[ \t]+$", "", inputText, flags=re.MULTILINE) | ||
output = re.sub(r"\n\s*\n\s*\n", "\n\n", output) | ||
with open(fpath, "w") as f: | ||
f.write(output) | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pathlib as path | ||
|
||
def find_index(s : str, t : str) -> list[int]: | ||
return [p for p, c in enumerate(s) if c == t] | ||
|
||
def isAgdaFile(f: path.Path) -> bool: | ||
return (f.match('*.lagda.md') and | ||
f.exists() and | ||
f.is_file()) | ||
|
||
def agdaFiles(files: list[str]) -> list[path.Path]: | ||
return list(filter(isAgdaFile, | ||
map(path.Path, files))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.