Skip to content

Commit cb9a372

Browse files
committed
feat: add logic for dropping dependent area labels
1 parent 5d6af74 commit cb9a372

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/autolabel.lean

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ These are printed for testing purposes.
3131
to the PR specified. This requires the **GitHub CLI** `gh` to be installed!
3232
Example: `lake exe autolabel 10402` for PR https://github.com/leanprover-community/mathlib4/pull/10402.
3333
34-
The script can add up to `MAX_LABELS` labels (defined below).
34+
The script can add up to `MAX_LABELS` labels (defined below),
35+
but it filters them by a hand-curated dependency list:
36+
For example if `t-ring-theory` and `t-algebra` are both applicable, only the former will
37+
be added. This list is defined in `mathlibLabelData` below.
38+
3539
If more than `MAX_LABELS` labels would be applicable, nothing will be added.
3640
3741
## Workflow
@@ -104,7 +108,6 @@ def mathlibLabels : Array Label := #[
104108
dependency-bump»
105109
]
106110

107-
-- Note: Since Lean does not know reflection, this needs to be updated manually!
108111
def Label.toString : Label → String
109112
| .«t-algebra» => "t-algebra"
110113
| .«t-algebraic-geometry» => "t-algebraic-geometry"
@@ -144,6 +147,8 @@ A `LabelData` consists of the
144147
* The `exclusions` field is the array of all "root paths" that are excluded, among the
145148
ones that start with the ones in `dirs`.
146149
Any modifications to a file in an excluded path is ignored for the purposes of labelling.
150+
* The `dependencies` field is the array of all labels, which are lower in the import hierarchy
151+
and which should be excluded if the label is present.
147152
-/
148153
structure LabelData (label : Label) where
149154
/-- Array of paths which fall under this label. e.g. `"Mathlib" / "Algebra"`.
@@ -269,6 +274,18 @@ def getMatchingLabels (files : Array FilePath) : Array Label :=
269274
-- return sorted list of labels
270275
applicable |>.qsort (·.toString < ·.toString)
271276

277+
/-- Helper function: union of all labels an all their dependent labels -/
278+
partial def collectLabelsAndDependentLabels (labels: Array Label) : Array Label :=
279+
labels.flatMap fun label ↦
280+
(collectLabelsAndDependentLabels (mathlibLabelData label).dependencies).push label
281+
282+
/-- Reduce a list of labels to not include any which are dependencies of other
283+
labels in the list -/
284+
def dropDependentLabels (labels: Array Label) : Array Label :=
285+
let dependentLabels := labels.flatMap fun label ↦
286+
(mathlibLabelData label).dependencies
287+
labels.filter (!dependentLabels.contains ·)
288+
272289
/-!
273290
Testing the functionality of the declarations defined in this script
274291
-/
@@ -406,7 +423,7 @@ unsafe def main (args : List String): IO UInt32 := do
406423
let modifiedFiles : Array FilePath := (gitDiff.splitOn "\n").toArray.map (⟨·⟩)
407424

408425
-- find labels covering the modified files
409-
let labels := getMatchingLabels modifiedFiles
426+
let labels := dropDependentLabels <| getMatchingLabels modifiedFiles
410427
println s!"::notice::Applicable labels: {labels}"
411428

412429
match labels with

0 commit comments

Comments
 (0)