Skip to content

[Merged by Bors] - fix(scripts/rm_set_option.py): make more usable in downstream projects - #38532

Closed
bryangingechen wants to merge 7 commits into
leanprover-community:masterfrom
bryangingechen:rm_set_option_downstream_fix
Closed

bryangingechen wants to merge 7 commits into
leanprover-community:masterfrom
bryangingechen:rm_set_option_downstream_fix

Conversation

@bryangingechen

@bryangingechen bryangingechen commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor
  • Only attempt to process lakefile.lean if it exists.
  • Added a new --directories command-line option to specify which directories to scan (copied from dag_traversal.py, and passed directly to that script).

cf. https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency/near/590911742


@github-actions

github-actions Bot commented Apr 25, 2026 •

Copy link
Copy Markdown

PR summary 2113b17760

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the CI Modifies the continuous integration setup or other automation label Apr 25, 2026
Comment thread scripts/rm_set_option.py Resolved
Comment thread scripts/rm_set_option.py Resolved
@grunweg grunweg changed the title fix(scripts/ rm_set_option.py): make more usable in downstream projects fix(scripts/rm_set_option.py): make more usable in downstream projects Apr 26, 2026
@grunweg

grunweg commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Thanks, looks good to me! Have to tested this locally? If so, I'm happy to just merge this.
bors d+

@mathlib-bors

mathlib-bors Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

✌️ bryangingechen can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@mathlib-triage mathlib-triage Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Apr 26, 2026
@kbuzzard

kbuzzard commented Apr 26, 2026 •

Copy link
Copy Markdown
Member

Can we please have instructions somewhere on how to run this in your own project? Or did I miss them? Just one line of text near the top of something saying "to use this tool, just do this simple thing"? I guess it's "copy some things into /scripts and then run this command in the root directory of your lean repo"? Can this sort of thing go at the top of a python file? I don't know the first thing about python.

I'm no computer scientist, but my default approach ("copy one file into FLT/scripts and run it with no arguments") didn't work and left me trying to figure out how to install python packages onto my machine because I had the error "no module named dag_traversal" which I misinterpreted. Does the default approach now work?

@bryangingechen

Copy link
Copy Markdown
Contributor Author

Thanks, looks good to me! Have to tested this locally? If so, I'm happy to just merge this. bors d+

I tested this with --dry-run but not with an actual run. I think that's fine for the changes in this PR, though.

Comment thread scripts/rm_set_option.py Outdated
Comment on lines +323 to +326
description="Remove unnecessary `set_option ... false in` lines in a Lean project.\n\n"
"To use outside mathlib, copy `rm_set_option.py`, `dag_traversal.py` and "
"`set_option_utils.py` to a subdirectory of your project named `scripts/` "
"and then run from the project root with `scripts/rm_set_optyion.py`.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kbuzzard Does this text address your concerns? It shows up if you run the script with the -h or --help flags.

Comment thread scripts/rm_set_option.py Resolved
Comment thread scripts/dag_traversal.py Resolved
@bryangingechen

Copy link
Copy Markdown
Contributor Author

bors r+

mathlib-bors Bot pushed a commit that referenced this pull request Apr 28, 2026
#38532)

- Only attempt to process `lakefile.lean` if it exists.
- Added a new `--directories` command-line option to specify which directories to scan (copied from `dag_traversal.py`, and passed directly to that script).

cf. https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency/near/590911742
@mathlib-triage mathlib-triage Bot added the ready-to-merge This PR has been sent to bors. label Apr 28, 2026
@mathlib-bors

mathlib-bors Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title fix(scripts/rm_set_option.py): make more usable in downstream projects [Merged by Bors] - fix(scripts/rm_set_option.py): make more usable in downstream projects Apr 28, 2026
@mathlib-bors mathlib-bors Bot closed this Apr 28, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Apr 29, 2026
…ng-line fixers (#38602)

This PR cherry-picks a set of adaptation-helper scripts that @nomeata developed on the `lean-pr-testing-13492` branch during the adaptation for leanprover/lean4#13492 (now merged). He flagged on Zulip ([thread](https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/lean.2313492.2C.20stricter.20.40.5Bdefeq.5D.20inference/near/591078800)) that he plans to delete them from the adaptation branch and offered them up for adoption.

Changes:

- `scripts/add_set_option.py`, `scripts/rm_set_option.py`: new `--value` flag, so the scripts work for options whose default is `false` (where you want to insert `set_option X true in`) as well as the existing `false` case.
- `scripts/add_module_set_option.py` (new): file-level variant of `add_set_option.py` — inserts a module-scoped `set_option` after the imports (and module docstring, if present) rather than scoped to a declaration. Needed for eqn-affecting options.
- `scripts/rm_module_set_option.py` (new): file-level variant of `rm_set_option.py`. Traverses the import DAG backward, with resume support keyed on toolchain.
- `scripts/fix_nonlocal_set_option.py` (new): given failing modules, adds the option to all transitive deps then binary-search minimizes back to the smallest set whose modules need it.
- `scripts/fix_unused_simp_args.py` (new): parses `This simp argument is unused: X` warnings from `lake build` and removes `X` from the corresponding `simp` / `simp only` call. For `← X` it rewrites to `- X` because the `←` has simp-set side effects.
- `scripts/fix_long_lines.py` (new): breaks too-long lines at the last comma before column 100 and indents the continuation. Useful as a follow-up to scripts that rewrite simp lists.
- `scripts/README.md`: documents all of the above.

The defaults for `--option` in the new module-level scripts point at `backward.defeq.atInstanceTransparency` (the option from leanprover/lean4#13492); for current options pass `--option <name>` explicitly.

Original commits from `lean-pr-testing-13492`:
- `6f1a3512906` chore(scripts): add `--value` flag to add/rm_set_option.py (had a small conflict with #38532's `lakefile.lean` existence check; resolved by combining)
- `36625b2a675` chore(scripts): bring back module-level / nonlocal scripts
- `de2a59b5839` chore(scripts): thread `--value` through `fix_nonlocal_set_option.py`
- `45f3ee41b94` (extracted) `fix_unused_simp_args.py`
- `4278b885305` (extracted) `fix_long_lines.py`
- `80852596213` doc(scripts): document new helpers

I sanity-checked each script: all parse, all `--help`s render, and `fix_long_lines.py` / `fix_unused_simp_args.py` produce the expected output on synthetic inputs.

🤖 Prepared with Claude Code

Co-authored-by: Joachim Breitner <[email protected]>
xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request May 2, 2026
leanprover-community#38532)

- Only attempt to process `lakefile.lean` if it exists.
- Added a new `--directories` command-line option to specify which directories to scan (copied from `dag_traversal.py`, and passed directly to that script).

cf. https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency/near/590911742
xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request May 2, 2026
…ng-line fixers (leanprover-community#38602)

This PR cherry-picks a set of adaptation-helper scripts that @nomeata developed on the `lean-pr-testing-13492` branch during the adaptation for leanprover/lean4#13492 (now merged). He flagged on Zulip ([thread](https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/lean.2313492.2C.20stricter.20.40.5Bdefeq.5D.20inference/near/591078800)) that he plans to delete them from the adaptation branch and offered them up for adoption.

Changes:

- `scripts/add_set_option.py`, `scripts/rm_set_option.py`: new `--value` flag, so the scripts work for options whose default is `false` (where you want to insert `set_option X true in`) as well as the existing `false` case.
- `scripts/add_module_set_option.py` (new): file-level variant of `add_set_option.py` — inserts a module-scoped `set_option` after the imports (and module docstring, if present) rather than scoped to a declaration. Needed for eqn-affecting options.
- `scripts/rm_module_set_option.py` (new): file-level variant of `rm_set_option.py`. Traverses the import DAG backward, with resume support keyed on toolchain.
- `scripts/fix_nonlocal_set_option.py` (new): given failing modules, adds the option to all transitive deps then binary-search minimizes back to the smallest set whose modules need it.
- `scripts/fix_unused_simp_args.py` (new): parses `This simp argument is unused: X` warnings from `lake build` and removes `X` from the corresponding `simp` / `simp only` call. For `← X` it rewrites to `- X` because the `←` has simp-set side effects.
- `scripts/fix_long_lines.py` (new): breaks too-long lines at the last comma before column 100 and indents the continuation. Useful as a follow-up to scripts that rewrite simp lists.
- `scripts/README.md`: documents all of the above.

The defaults for `--option` in the new module-level scripts point at `backward.defeq.atInstanceTransparency` (the option from leanprover/lean4#13492); for current options pass `--option <name>` explicitly.

Original commits from `lean-pr-testing-13492`:
- `6f1a3512906` chore(scripts): add `--value` flag to add/rm_set_option.py (had a small conflict with leanprover-community#38532's `lakefile.lean` existence check; resolved by combining)
- `36625b2a675` chore(scripts): bring back module-level / nonlocal scripts
- `de2a59b5839` chore(scripts): thread `--value` through `fix_nonlocal_set_option.py`
- `45f3ee41b94` (extracted) `fix_unused_simp_args.py`
- `4278b885305` (extracted) `fix_long_lines.py`
- `80852596213` doc(scripts): document new helpers

I sanity-checked each script: all parse, all `--help`s render, and `fix_long_lines.py` / `fix_unused_simp_args.py` produce the expected output on synthetic inputs.

🤖 Prepared with Claude Code

Co-authored-by: Joachim Breitner <[email protected]>
gaetanserre pushed a commit to gaetanserre/mathlib4 that referenced this pull request May 5, 2026
leanprover-community#38532)

- Only attempt to process `lakefile.lean` if it exists.
- Added a new `--directories` command-line option to specify which directories to scan (copied from `dag_traversal.py`, and passed directly to that script).

cf. https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency/near/590911742
gaetanserre pushed a commit to gaetanserre/mathlib4 that referenced this pull request May 5, 2026
…ng-line fixers (leanprover-community#38602)

This PR cherry-picks a set of adaptation-helper scripts that @nomeata developed on the `lean-pr-testing-13492` branch during the adaptation for leanprover/lean4#13492 (now merged). He flagged on Zulip ([thread](https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/lean.2313492.2C.20stricter.20.40.5Bdefeq.5D.20inference/near/591078800)) that he plans to delete them from the adaptation branch and offered them up for adoption.

Changes:

- `scripts/add_set_option.py`, `scripts/rm_set_option.py`: new `--value` flag, so the scripts work for options whose default is `false` (where you want to insert `set_option X true in`) as well as the existing `false` case.
- `scripts/add_module_set_option.py` (new): file-level variant of `add_set_option.py` — inserts a module-scoped `set_option` after the imports (and module docstring, if present) rather than scoped to a declaration. Needed for eqn-affecting options.
- `scripts/rm_module_set_option.py` (new): file-level variant of `rm_set_option.py`. Traverses the import DAG backward, with resume support keyed on toolchain.
- `scripts/fix_nonlocal_set_option.py` (new): given failing modules, adds the option to all transitive deps then binary-search minimizes back to the smallest set whose modules need it.
- `scripts/fix_unused_simp_args.py` (new): parses `This simp argument is unused: X` warnings from `lake build` and removes `X` from the corresponding `simp` / `simp only` call. For `← X` it rewrites to `- X` because the `←` has simp-set side effects.
- `scripts/fix_long_lines.py` (new): breaks too-long lines at the last comma before column 100 and indents the continuation. Useful as a follow-up to scripts that rewrite simp lists.
- `scripts/README.md`: documents all of the above.

The defaults for `--option` in the new module-level scripts point at `backward.defeq.atInstanceTransparency` (the option from leanprover/lean4#13492); for current options pass `--option <name>` explicitly.

Original commits from `lean-pr-testing-13492`:
- `6f1a3512906` chore(scripts): add `--value` flag to add/rm_set_option.py (had a small conflict with leanprover-community#38532's `lakefile.lean` existence check; resolved by combining)
- `36625b2a675` chore(scripts): bring back module-level / nonlocal scripts
- `de2a59b5839` chore(scripts): thread `--value` through `fix_nonlocal_set_option.py`
- `45f3ee41b94` (extracted) `fix_unused_simp_args.py`
- `4278b885305` (extracted) `fix_long_lines.py`
- `80852596213` doc(scripts): document new helpers

I sanity-checked each script: all parse, all `--help`s render, and `fix_long_lines.py` / `fix_unused_simp_args.py` produce the expected output on synthetic inputs.

🤖 Prepared with Claude Code

Co-authored-by: Joachim Breitner <[email protected]>
gasparattila pushed a commit to gasparattila/mathlib4 that referenced this pull request May 9, 2026
leanprover-community#38532)

- Only attempt to process `lakefile.lean` if it exists.
- Added a new `--directories` command-line option to specify which directories to scan (copied from `dag_traversal.py`, and passed directly to that script).

cf. https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/backward.2EisDefEq.2ErespectTransparency/near/590911742
gasparattila pushed a commit to gasparattila/mathlib4 that referenced this pull request May 9, 2026
…ng-line fixers (leanprover-community#38602)

This PR cherry-picks a set of adaptation-helper scripts that @nomeata developed on the `lean-pr-testing-13492` branch during the adaptation for leanprover/lean4#13492 (now merged). He flagged on Zulip ([thread](https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/lean.2313492.2C.20stricter.20.40.5Bdefeq.5D.20inference/near/591078800)) that he plans to delete them from the adaptation branch and offered them up for adoption.

Changes:

- `scripts/add_set_option.py`, `scripts/rm_set_option.py`: new `--value` flag, so the scripts work for options whose default is `false` (where you want to insert `set_option X true in`) as well as the existing `false` case.
- `scripts/add_module_set_option.py` (new): file-level variant of `add_set_option.py` — inserts a module-scoped `set_option` after the imports (and module docstring, if present) rather than scoped to a declaration. Needed for eqn-affecting options.
- `scripts/rm_module_set_option.py` (new): file-level variant of `rm_set_option.py`. Traverses the import DAG backward, with resume support keyed on toolchain.
- `scripts/fix_nonlocal_set_option.py` (new): given failing modules, adds the option to all transitive deps then binary-search minimizes back to the smallest set whose modules need it.
- `scripts/fix_unused_simp_args.py` (new): parses `This simp argument is unused: X` warnings from `lake build` and removes `X` from the corresponding `simp` / `simp only` call. For `← X` it rewrites to `- X` because the `←` has simp-set side effects.
- `scripts/fix_long_lines.py` (new): breaks too-long lines at the last comma before column 100 and indents the continuation. Useful as a follow-up to scripts that rewrite simp lists.
- `scripts/README.md`: documents all of the above.

The defaults for `--option` in the new module-level scripts point at `backward.defeq.atInstanceTransparency` (the option from leanprover/lean4#13492); for current options pass `--option <name>` explicitly.

Original commits from `lean-pr-testing-13492`:
- `6f1a3512906` chore(scripts): add `--value` flag to add/rm_set_option.py (had a small conflict with leanprover-community#38532's `lakefile.lean` existence check; resolved by combining)
- `36625b2a675` chore(scripts): bring back module-level / nonlocal scripts
- `de2a59b5839` chore(scripts): thread `--value` through `fix_nonlocal_set_option.py`
- `45f3ee41b94` (extracted) `fix_unused_simp_args.py`
- `4278b885305` (extracted) `fix_long_lines.py`
- `80852596213` doc(scripts): document new helpers

I sanity-checked each script: all parse, all `--help`s render, and `fix_long_lines.py` / `fix_unused_simp_args.py` produce the expected output on synthetic inputs.

🤖 Prepared with Claude Code

Co-authored-by: Joachim Breitner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Modifies the continuous integration setup or other automation delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants