Conversation
pyproject.toml declares requires-python = ">=3.12", but check_env() still admitted Python 3.10, and WebUI-driven upgrades bypass pip's requires-python enforcement entirely. A 3.10 install therefore kept booting until a plugin or code path using 3.12 syntax exploded at runtime. Raise the runtime check to match pyproject and cover 3.10/3.11 with the regression test. Fixes AstrBotDevs#9945
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="main.py" line_range="66" />
<code_context>
+ # Keep this aligned with pyproject.toml's `requires-python = ">=3.12"`.
+ # WebUI upgrades skip pip's requires-python enforcement, so this runtime
+ # check is the only guard for installs that predate the 3.12 requirement.
+ if not (sys.version_info.major == 3 and sys.version_info.minor >= 12):
+ logger.error("Please run this project with Python 3.12 or later.")
exit()
</code_context>
<issue_to_address>
**issue (broader_impact):** The documented `astrbot run` console entry point never calls `check_env()`; it invokes `astrbot.cli.commands.cmd_run.run()` instead. Consequently, a WebUI or console-script startup on Python 3.10 or 3.11 bypasses this new floor check and can still boot.
**Triggers:** When AstrBot is started with the installed `astrbot run` command rather than by executing `main.py` directly.
**Suggested fix:** Invoke `check_env()` from the console-script startup path before launching `run_astrbot()`, or centralize startup through a single entry point.
</issue_to_address>
### Comment 2
<location path="main.py" line_range="66" />
<code_context>
+ # Keep this aligned with pyproject.toml's `requires-python = ">=3.12"`.
+ # WebUI upgrades skip pip's requires-python enforcement, so this runtime
+ # check is the only guard for installs that predate the 3.12 requirement.
+ if not (sys.version_info.major == 3 and sys.version_info.minor >= 12):
+ logger.error("Please run this project with Python 3.12 or later.")
exit()
</code_context>
<issue_to_address>
**nitpick (bug_risk):** The condition rejects every Python with a major version other than 3, including Python 4, even though `requires-python = ">=3.12"` and the error message say Python 3.12 or later is supported. A Python 4 installation that satisfies the declared requirement exits before startup.
**Triggers:** When the project is run under Python 4 or a later major version.
**Suggested fix:** Use `if sys.version_info < (3, 12):` unless Python 4 is intentionally unsupported and the project metadata is updated with an upper bound.
```suggestion
if sys.version_info < (3, 12):
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the Python floor is raised incorrectly or downstream users still depend on Python 3.10 or 3.11, the startup guard will prevent the application from launching for those users. Reverting restores compatibility, but any outage or failed startup attempts during the interval are not undone.
Blocking findings: main.py:66
| # Keep this aligned with pyproject.toml's `requires-python = ">=3.12"`. | ||
| # WebUI upgrades skip pip's requires-python enforcement, so this runtime | ||
| # check is the only guard for installs that predate the 3.12 requirement. | ||
| if not (sys.version_info.major == 3 and sys.version_info.minor >= 12): |
There was a problem hiding this comment.
issue (broader_impact): The documented astrbot run console entry point never calls check_env(); it invokes astrbot.cli.commands.cmd_run.run() instead. Consequently, a WebUI or console-script startup on Python 3.10 or 3.11 bypasses this new floor check and can still boot.
Triggers: When AstrBot is started with the installed astrbot run command rather than by executing main.py directly.
Suggested fix: Invoke check_env() from the console-script startup path before launching run_astrbot(), or centralize startup through a single entry point.
| # Keep this aligned with pyproject.toml's `requires-python = ">=3.12"`. | ||
| # WebUI upgrades skip pip's requires-python enforcement, so this runtime | ||
| # check is the only guard for installs that predate the 3.12 requirement. | ||
| if not (sys.version_info.major == 3 and sys.version_info.minor >= 12): |
There was a problem hiding this comment.
nitpick (bug_risk): The condition rejects every Python with a major version other than 3, including Python 4, even though requires-python = ">=3.12" and the error message say Python 3.12 or later is supported. A Python 4 installation that satisfies the declared requirement exits before startup.
Triggers: When the project is run under Python 4 or a later major version.
Suggested fix: Use if sys.version_info < (3, 12): unless Python 4 is intentionally unsupported and the project metadata is updated with an upper bound.
| if not (sys.version_info.major == 3 and sys.version_info.minor >= 12): | |
| if sys.version_info < (3, 12): |
pyproject.toml declares requires-python = ">=3.12", but check_env()
still admitted Python 3.10, and WebUI-driven upgrades bypass pip's
requires-python enforcement entirely. A 3.10 install therefore kept
booting until a plugin or code path using 3.12 syntax exploded at
runtime.
Raise the runtime check to match pyproject and cover 3.10/3.11 with
the regression test.
Fixes #9945
Testing
tests/test_main.py::test_check_envnow covers three cases: 3.12 passes, 3.10 exits, 3.9 exits. The 3.10 case failed withDID NOT RAISE SystemExiton unpatchedmaster(95e98b8) and passes with the fix; the full file passes 18/18.ruff format --checkandruff checkclean on both touched files.Why (context)
Users who deployed on Python 3.10 before the 3.12 requirement and have been upgrading through the WebUI never hit pip's
requires-pythongate (WebUI upgrades replace code, not the interpreter), so their instance boots until a plugin or dependency using 3.12 syntax crashes. The startup check is the only place the floor can be enforced at runtime.Summary by Sourcery
Align the startup Python version check with the project’s declared Python 3.12 requirement.
Bug Fixes:
Tests: