Skip to content

clean: add if __name__ == "__main__" in prepare_readme.py tto avoid modifications to README-PYPI.md when collecting tests#559

Merged
anth2o merged 1 commit into
mainfrom
antoinehoorelbeke/add-if-name-main-prepare-readme
Jun 1, 2026
Merged

clean: add if __name__ == "__main__" in prepare_readme.py tto avoid modifications to README-PYPI.md when collecting tests#559
anth2o merged 1 commit into
mainfrom
antoinehoorelbeke/add-if-name-main-prepare-readme

Conversation

@anth2o
Copy link
Copy Markdown
Contributor

@anth2o anth2o commented Jun 1, 2026

Why

README-PYPI.md kept showing up as an unstaged change in local working trees even when no one touched the repo.

Root cause: scripts/prepare_readme.py has no if __name__ == "__main__": guard, so its top-level body — which writes README-PYPI.md from README.md — runs at import time. tests/test_prepare_readme.py imports the script via spec.loader.exec_module(...), and VS Code's Python extension auto-runs pytest --collect-only on workspace open and on save, silently regenerating README-PYPI.md each time.

Change

Wrap the side-effecting code in main() behind the standard __main__ guard. Direct invocation (python scripts/prepare_readme.py, used by scripts/publish.sh and the publish workflow) is unchanged; importing it is now a no-op.

@anth2o anth2o changed the title clean: add if __name__ == "__main__" in prepare_readme.py tto avoid m… clean: add if __name__ == "__main__" in prepare_readme.py tto avoid modifications to README-PYPI.md when collecting tests Jun 1, 2026
@anth2o anth2o marked this pull request as ready for review June 1, 2026 08:50
@anth2o anth2o requested a review from andreaonofrei01 June 1, 2026 08:59
Copy link
Copy Markdown
Contributor

@andreaonofrei01 andreaonofrei01 left a comment

Choose a reason for hiding this comment

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

nice catch, lgtm

…odifications to README-PYPI.md when collecting tests
@anth2o anth2o force-pushed the antoinehoorelbeke/add-if-name-main-prepare-readme branch from 73278db to 7ff2086 Compare June 1, 2026 09:19
@anth2o anth2o merged commit b5f7f55 into main Jun 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants