Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - ci(scripts/*): linting for copyright, imports, module docstrings, line length #4486

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0296cb5
chore(scripts/*): crude linting for copyright, imports, module docstr…
jcommelin Oct 6, 2020
8b2a6a6
Merge branch 'community-master' into mod-doc-lint
bryangingechen Oct 6, 2020
d6b96b8
rework scripts and output format
bryangingechen Oct 6, 2020
0d90a8c
update github workflow and update_nolints.sh
bryangingechen Oct 6, 2020
54c69c7
allow "Author(s):"
bryangingechen Oct 6, 2020
f1d572b
use enumerate
bryangingechen Oct 7, 2020
0947fef
update exceptions
bryangingechen Oct 7, 2020
8664a96
fix enumerate index, relax copyright header check
bryangingechen Oct 7, 2020
466623c
chore(*): fix authorship for split files (#4480)
bryangingechen Oct 6, 2020
99bdeb8
feat(ring_theory/witt_vector/structure_polynomial): witt_structure_ra…
jcommelin Oct 6, 2020
d41c321
feat(data/polynomial/degree/basic): add lemmas dealing with monomials…
adomani Oct 6, 2020
5caa01f
feat(measure_theory): integral of a non-negative function is >0 iff μ…
urkud Oct 6, 2020
f080aaa
feat(data/nat/basic): add_succ_lt_add (#4483)
jsm28 Oct 6, 2020
d1df3b9
lint(order/bounded_lattice): docstring (#4484)
hrmacbeth Oct 6, 2020
c510fbc
lint(ring_theory/*): docstrings (#4485)
awainverse Oct 7, 2020
319c624
feat(control/traversable/basic): composition of applicative transform…
kmill Oct 7, 2020
6d3d425
lint(order/order_iso_nat): docstrings (#4488)
awainverse Oct 7, 2020
ffb10a8
lint(order/lexographic, pilex): docstrings (#4489)
awainverse Oct 7, 2020
6560f6a
chore(scripts): update nolints.txt (#4490)
leanprover-community-bot Oct 7, 2020
9eed9ec
Allow comments in import-only files
jcommelin Oct 7, 2020
9b251b6
Allow unicode copyright symbol in headers
jcommelin Oct 7, 2020
0e3f228
Don't allow empty lines before copyright header
jcommelin Oct 7, 2020
5484cca
lint(group_theory/perm/*): docstrings (#4492)
awainverse Oct 7, 2020
f9492d1
lint(group_theory/*): docstrings and an inhabited instance (#4493)
awainverse Oct 7, 2020
8377549
Merge branch 'master' into mod-doc-lint
jcommelin Oct 7, 2020
fcb6e59
Apply suggestions from code review
jcommelin Oct 7, 2020
72bbc94
fix errors
jcommelin Oct 7, 2020
12d651c
lint for long lines
jcommelin Oct 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
set -o pipefail
curl https://raw.githubusercontent.com/Kha/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y
~/.elan/bin/lean --version
echo "::add-path::$HOME/.elan/bin"
echo "::set-env name=short_lean_version::$(~/.elan/bin/lean --run scripts/lean_version.lean)"
echo "$HOME/.elan/bin" >> $GITHUB_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not unhappy with the change, but it's completely unrelated, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Bryan mentioned a link to a GH blog post about some vulnerability that is fixed by this change.

echo "short_lean_version=$(~/.elan/bin/lean --run scripts/lean_version.lean)" >> $GITHUB_ENV

- name: install azcopy
run: |
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
set -o pipefail
curl https://raw.githubusercontent.com/Kha/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y
~/.elan/bin/lean --version
echo "::add-path::$HOME/.elan/bin"
echo "$HOME/.elan/bin" >> $GITHUB_PATH

- name: lint
run: |
Expand All @@ -119,7 +119,7 @@ jobs:
set -o pipefail
curl https://raw.githubusercontent.com/Kha/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y
~/.elan/bin/lean --version
echo "::add-path::$HOME/.elan/bin"
echo "$HOME/.elan/bin" >> $GITHUB_PATH

- name: install Python
uses: actions/setup-python@v1
Expand All @@ -144,3 +144,7 @@ jobs:
python scripts/yaml_check.py docs/100.yaml docs/overview.yaml docs/undergrad.yaml
bash scripts/mk_all.sh
lean --run scripts/yaml_check.lean

- name: check for copyright headers and module docstrings
run: |
Comment on lines +147 to +149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be run before any of the really slow build steps? I don't want to wait hours for a build, only for it to then say my line is too long and have to start all over again because the file I wrapped the line in needs rebuilding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was the opposite; since fixing the issues caught by this script shouldn't typically create new build / linter issues, it's better to report those "more serious" problems first so that those can be addressed / discussed. For example, fixing a build / linter issue (e.g. from a github suggestion) might temporarily make a line too long, and I think it'd be better to first check that the suggestion "works" rather than force people to reflow everything up front.

Feel free to bring this up on Zulip, I'd be curious to hear others' thoughts on this as well.

Note that you should be able to run this script manually by executing ./scripts/lint-copy-mod-doc.sh.

./scripts/lint-copy-mod-doc.sh
339 changes: 339 additions & 0 deletions scripts/copy-mod-doc-exceptions.txt

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions scripts/lint-copy-mod-doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env python3

import sys

fns = sys.argv[1:]

ERR_COP = 0
ERR_IMP = 1
ERR_MOD = 2

exceptions = []

with open("scripts/copy-mod-doc-exceptions-short.txt") as f:
lines = f.readlines()
for line in lines:
(fn, c, errno) = line.split()
jcommelin marked this conversation as resolved.
Show resolved Hide resolved
if errno == "ERR_COP":
exceptions += [(ERR_COP, fn)]
if errno == "ERR_IMP":
exceptions += [(ERR_IMP, fn)]
if errno == "ERR_MOD":
exceptions += [(ERR_MOD, fn)]

new_exceptions = False

def import_only_check(lines, fn):
import_only_file = True
errors = []
line_nr = 0
in_comment = False
for line_nr, line in enumerate(lines, 1):
if "/-" in line:
in_comment = True
if "-/" in line:
in_comment = False
continue
if line == "\n" or in_comment:
continue
imports = line.split()
if imports[0] == "--":
continue
if imports[0] != "import":
import_only_file = False
break
if len(imports) > 2:
if imports[2] == "--":
continue
else:
errors += [(ERR_IMP, line_nr, fn)]
return (import_only_file, errors)

def regular_check(lines, fn):
errors = []
copy_started = False
copy_done = False
copy_start_line_nr = 0
copy_lines = ""
for line_nr, line in enumerate(lines, 1):
if not copy_started and line == "\n":
errors += [(ERR_COP, copy_start_line_nr, fn)]
continue
if not copy_started and line == "/-\n":
copy_started = True
copy_start_line_nr = line_nr
continue
if not copy_started:
errors += [(ERR_COP, line_nr, fn)]
if copy_started and not copy_done:
copy_lines += line
if line == "-/\n":
if ((not "Copyright" in copy_lines) or
(not "Apache" in copy_lines) or
(not "Author" in copy_lines)):
errors += [(ERR_COP, copy_start_line_nr, fn)]
copy_done = True
continue
if copy_done and line == "\n":
continue
words = line.split()
if words[0] != "import" and words[0] != "/-!":
errors += [(ERR_MOD, line_nr, fn)]
break
if words[0] == "/-!":
break
# final case: words[0] == "import"
if len(words) > 2:
if words[2] != "--":
errors += [(ERR_IMP, line_nr, fn)]
return errors

def format_errors(errors):
global new_exceptions
for (errno, line_nr, fn) in errors:
if (errno, fn) in exceptions:
continue
new_exceptions = True
# filename first, then line so that we can call "sort" on the output
if errno == ERR_COP:
print("{} : line {} : ERR_COP : Malformed or missing copyright header".format(fn, line_nr))
if errno == ERR_IMP:
print("{} : line {} : ERR_IMP : More than one file imported per line".format(fn, line_nr))
if errno == ERR_MOD:
print("{} : line {} : ERR_MOD : Module docstring missing, or too late".format(fn, line_nr))

def lint(fn):
with open(fn) as f:
lines = f.readlines()
(b, errs) = import_only_check(lines, fn)
if b:
format_errors(errs)
return
errs = regular_check(lines, fn)
format_errors(errs)

for fn in fns:
lint(fn)

# if "exceptions" is empty,
# we're trying to generate copy-mod-doc-exceptions.txt,
# so new exceptions are expected
if new_exceptions and len(exceptions) > 0:
exit(1)
12 changes: 12 additions & 0 deletions scripts/lint-copy-mod-doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# This is a little wrapper around the python script
# lint-copy-mod-doc.py

touch scripts/copy-mod-doc-exceptions.txt

cut -d: -f1,3 < scripts/copy-mod-doc-exceptions.txt > scripts/copy-mod-doc-exceptions-short.txt

find src archive -name '*.lean' | xargs ./scripts/lint-copy-mod-doc.py

rm scripts/copy-mod-doc-exceptions-short.txt
124 changes: 0 additions & 124 deletions scripts/nolints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ apply_nolint category_theory.Kleisli.comp_def unused_arguments
apply_nolint category_theory.Kleisli.id_def unused_arguments
apply_nolint category_theory.Kleisli.mk doc_blame has_inhabited_instance

-- category_theory/endomorphism.lean
jcommelin marked this conversation as resolved.
Show resolved Hide resolved
apply_nolint category_theory.Aut doc_blame has_inhabited_instance
apply_nolint category_theory.End has_inhabited_instance

-- category_theory/equivalence.lean
apply_nolint category_theory.equivalence has_inhabited_instance
apply_nolint category_theory.equivalence.adjointify_η doc_blame
Expand All @@ -33,56 +29,6 @@ apply_nolint category_theory.functor.inv_fun_id doc_blame
apply_nolint category_theory.functor.obj_preimage doc_blame
apply_nolint category_theory.is_equivalence.mk doc_blame

-- category_theory/groupoid.lean
apply_nolint category_theory.large_groupoid doc_blame
apply_nolint category_theory.small_groupoid doc_blame

-- category_theory/limits/cones.lean
apply_nolint category_theory.limits.cocone has_inhabited_instance
apply_nolint category_theory.limits.cocone.extensions doc_blame
apply_nolint category_theory.limits.cocone_morphism has_inhabited_instance
apply_nolint category_theory.limits.cone has_inhabited_instance
apply_nolint category_theory.limits.cone.extensions doc_blame
apply_nolint category_theory.limits.cone_morphism has_inhabited_instance

-- category_theory/limits/over.lean
apply_nolint category_theory.functor.to_cocone doc_blame
apply_nolint category_theory.functor.to_cone doc_blame
apply_nolint category_theory.over.colimit doc_blame
apply_nolint category_theory.over.forget_colimit_is_colimit doc_blame
apply_nolint category_theory.under.forget_limit_is_limit doc_blame
apply_nolint category_theory.under.limit doc_blame

-- category_theory/limits/preserves/basic.lean
apply_nolint category_theory.limits.preserves_colimits doc_blame
apply_nolint category_theory.limits.preserves_colimits_of_shape doc_blame
apply_nolint category_theory.limits.preserves_limits doc_blame
apply_nolint category_theory.limits.preserves_limits_of_shape doc_blame

-- category_theory/limits/shapes/products.lean
apply_nolint category_theory.limits.cofan doc_blame
apply_nolint category_theory.limits.cofan.mk doc_blame
apply_nolint category_theory.limits.fan doc_blame
apply_nolint category_theory.limits.fan.mk doc_blame
apply_nolint category_theory.limits.pi.lift doc_blame
apply_nolint category_theory.limits.pi.π doc_blame
apply_nolint category_theory.limits.sigma.desc doc_blame
apply_nolint category_theory.limits.sigma.ι doc_blame

-- category_theory/monad/adjunction.lean
apply_nolint category_theory.monad.comparison doc_blame
apply_nolint category_theory.monad.comparison_forget doc_blame

-- category_theory/monad/algebra.lean
apply_nolint category_theory.monad.algebra has_inhabited_instance
apply_nolint category_theory.monad.algebra.hom has_inhabited_instance

-- category_theory/monoidal/functor.lean
apply_nolint category_theory.lax_monoidal_functor has_inhabited_instance
apply_nolint category_theory.monoidal_functor has_inhabited_instance
apply_nolint category_theory.monoidal_functor.ε_iso doc_blame
apply_nolint category_theory.monoidal_functor.μ_iso doc_blame

-- computability/halting.lean
apply_nolint computable_pred doc_blame
apply_nolint nat.partrec'.vec doc_blame
Expand Down Expand Up @@ -228,13 +174,6 @@ apply_nolint writer_t.pass doc_blame
apply_nolint writer_t.pure doc_blame
apply_nolint writer_t.tell doc_blame

-- control/traversable/basic.lean
apply_nolint applicative_transformation doc_blame has_inhabited_instance
apply_nolint is_lawful_traversable doc_blame
apply_nolint sequence doc_blame
apply_nolint sum.traverse doc_blame
apply_nolint traversable doc_blame

-- control/traversable/derive.lean
apply_nolint tactic.interactive.derive_functor doc_blame
apply_nolint tactic.interactive.derive_lawful_functor doc_blame
Expand All @@ -260,23 +199,6 @@ apply_nolint tactic.interactive.traverse_constructor unused_arguments
apply_nolint tactic.interactive.traverse_field unused_arguments
apply_nolint tactic.interactive.with_prefix doc_blame

-- control/traversable/equiv.lean
apply_nolint equiv.functor doc_blame
apply_nolint equiv.is_lawful_traversable doc_blame
apply_nolint equiv.is_lawful_traversable' doc_blame
apply_nolint equiv.map doc_blame
apply_nolint equiv.traversable doc_blame
apply_nolint equiv.traverse doc_blame

-- control/traversable/instances.lean
apply_nolint list.comp_traverse unused_arguments
apply_nolint option.comp_traverse unused_arguments
apply_nolint sum.comp_traverse unused_arguments
apply_nolint sum.traverse_map unused_arguments

-- control/traversable/lemmas.lean
apply_nolint traversable.pure_transformation doc_blame

-- data/analysis/filter.lean
apply_nolint cfilter has_inhabited_instance
apply_nolint cfilter.to_realizer doc_blame
Expand Down Expand Up @@ -345,13 +267,6 @@ apply_nolint encodable.trunc_encodable_of_fintype doc_blame
apply_nolint equiv.list_equiv_self_of_equiv_nat doc_blame
apply_nolint equiv.list_nat_equiv_nat doc_blame

-- data/equiv/ring.lean
apply_nolint equiv.units_equiv_ne_zero doc_blame
apply_nolint ring_equiv doc_blame has_inhabited_instance
apply_nolint ring_equiv.to_add_equiv doc_blame
apply_nolint ring_equiv.to_equiv doc_blame
apply_nolint ring_equiv.to_mul_equiv doc_blame

-- data/fp/basic.lean
apply_nolint fp.div_nat_lt_two_pow doc_blame unused_arguments
apply_nolint fp.emax doc_blame
Expand Down Expand Up @@ -394,14 +309,6 @@ apply_nolint holor_index.assoc_right doc_blame
apply_nolint holor_index.drop doc_blame
apply_nolint holor_index.take doc_blame

-- data/int/basic.lean
apply_nolint int.bit_cases_on doc_blame
apply_nolint int.induction_on' doc_blame
apply_nolint int.to_nat' doc_blame

-- data/int/modeq.lean
apply_nolint int.modeq doc_blame

-- data/list/defs.lean
apply_nolint list.permutations_aux doc_blame
apply_nolint list.permutations_aux.rec doc_blame
Expand Down Expand Up @@ -487,9 +394,6 @@ apply_nolint multiset.traverse doc_blame
-- data/multiset/pi.lean
apply_nolint multiset.pi.empty unused_arguments

-- data/nat/prime.lean
apply_nolint nat.min_fac_aux doc_blame

-- data/num/basic.lean
apply_nolint cast_num doc_blame
apply_nolint cast_pos_num doc_blame unused_arguments
Expand Down Expand Up @@ -822,11 +726,6 @@ apply_nolint abelianization.lift doc_blame
apply_nolint add_con.to_setoid doc_blame
apply_nolint con.to_setoid doc_blame

-- group_theory/eckmann_hilton.lean
apply_nolint eckmann_hilton.comm_group doc_blame unused_arguments
apply_nolint eckmann_hilton.comm_monoid doc_blame
apply_nolint eckmann_hilton.is_unital doc_blame

-- group_theory/free_abelian_group.lean
apply_nolint free_abelian_group doc_blame
apply_nolint free_abelian_group.lift doc_blame
Expand Down Expand Up @@ -877,25 +776,6 @@ apply_nolint relator.lift_fun doc_blame
apply_nolint relator.right_total doc_blame
apply_nolint relator.right_unique doc_blame

-- logic/unique.lean
apply_nolint unique doc_blame

-- measure_theory/category/Meas.lean
apply_nolint Meas doc_blame

-- measure_theory/measurable_space.lean
apply_nolint measurable_equiv has_inhabited_instance

-- measure_theory/probability_mass_function.lean
apply_nolint pmf.bernoulli doc_blame
apply_nolint pmf.bind doc_blame
apply_nolint pmf.map doc_blame
apply_nolint pmf.of_fintype doc_blame
apply_nolint pmf.of_multiset doc_blame
apply_nolint pmf.pure doc_blame
apply_nolint pmf.seq doc_blame
apply_nolint pmf.support doc_blame

-- meta/coinductive_predicates.lean
apply_nolint monotonicity doc_blame
apply_nolint tactic.add_coinductive_predicate doc_blame
Expand Down Expand Up @@ -1545,10 +1425,6 @@ apply_nolint continuous_map.compact_open.gen doc_blame
apply_nolint continuous_map.ev doc_blame
apply_nolint continuous_map.induced doc_blame

-- topology/compacts.lean
apply_nolint topological_space.closeds has_inhabited_instance
apply_nolint topological_space.nonempty_compacts has_inhabited_instance

-- topology/homeomorph.lean
apply_nolint homeomorph has_inhabited_instance

Expand Down
11 changes: 11 additions & 0 deletions scripts/update-copy-mod-doc-exceptions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# This is a little wrapper around the python script
# lint-copy-mod-doc.py

# we want an empty "exceptions" array in lint-copy-mod-doc.py
> scripts/copy-mod-doc-exceptions-short.txt

find src archive -name '*.lean' | xargs ./scripts/lint-copy-mod-doc.py | sort > scripts/copy-mod-doc-exceptions.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the creative use of the > operator that makes lint-copy-mod-doc.py read its own output, which happens to be empty at first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it too evil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be be fine. I don't know if the shell guarantees to open the file before launching the subprocesses, but even if it doesn't find takes long enough to prevent the race condition in practice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it looks like the > line got removed. I'd prefer to have that done in this script. I'll open a new PR.


rm scripts/copy-mod-doc-exceptions-short.txt
jcommelin marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions scripts/update_nolints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ git fetch $remote_name
git rev-parse --verify --quiet refs/remotes/$remote_name/$branch_name && exit 0

# Exit if there are no changes relative to master
git diff-index --quiet refs/remotes/$remote_name/master -- scripts/nolints.txt && exit 0
git diff-index --quiet refs/remotes/$remote_name/master -- scripts/nolints.txt scripts/copy-mod-doc-exceptions.txt && exit 0

pr_title='chore(scripts): update nolints.txt'
pr_body='I am happy to remove some nolints for you!'

git checkout -b $branch_name
git add scripts/nolints.txt
git add scripts/nolints.txt scripts/copy-mod-doc-exceptions.txt
git commit -m "$pr_title"

gh_api() {
Expand Down