Skip to content

Commit d36cd44

Browse files
CI to check Mathlib imports: negative test
1 parent b0ce14d commit d36cd44

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.github/workflows/push_master.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
run: |
2727
! (find LeanCamCombi -name "*.lean" -type f -print0 | xargs -0 grep -E -n '^import Mathlib$')
2828
29+
2930
build_project:
3031
runs-on: ubuntu-latest
3132
name: Build project
@@ -36,6 +37,10 @@ jobs:
3637
- name: Copy README.md to website/index.md
3738
run: cp README.md website/index.md
3839

40+
- name: Check LeanCamCombi.Mathlib only imports from Mathlib or LeanCamCombi.Mathlib
41+
run: |
42+
python3 scripts/check_mathlib_imports.py
43+
3944
- name: Upstreaming dashboard
4045
run: |
4146
mkdir -p website/_includes

LeanCamCombi/Mathlib/Combinatorics/Additive/ApproximateSubgroup.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
22
import Mathlib.Combinatorics.Additive.ApproximateSubgroup
33
import Mathlib.Tactic.Bound
4+
import LeanCamCombi.ExtrProbCombi.BernoulliSeq
45

56
open scoped Finset Pointwise
67

scripts/check_mathlib_imports.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
def list_files_by_type_recursive(folder_path, file_extension):
4+
"""Recursively lists all files in a folder and subfolders with the specified file extension."""
5+
matching_files = []
6+
for root, _, files in os.walk(folder_path):
7+
matching_files.extend(os.path.join(root, f) for f in files if f.endswith(file_extension))
8+
return matching_files
9+
10+
folder = "LeanCamCombi/Mathlib"
11+
extension = ".lean"
12+
files = list_files_by_type_recursive(folder, extension)
13+
14+
for file in files:
15+
code = None
16+
with open(file, "r") as reader:
17+
code = reader.read()
18+
lines = code.split("\n")
19+
header = [line for line in lines if line.lstrip().startswith("import")]
20+
21+
for imp in header:
22+
imp_file = imp.lstrip()[len("import"):].strip()
23+
if (not imp_file.startswith("Mathlib.")) and \
24+
(not imp_file.startswith("LeanCamCombi.Mathlib")):
25+
raise IOError("A file in LeanCamCombi.Mathlib imports a file not in Mathlib or LeanCamCombi.Mathlib")

0 commit comments

Comments
 (0)