Replace deprecated web strip helpers#12507
Conversation
for more information, see https://pre-commit.ci
|
Thank you for your first pull request to Open Library, @Abhishek764! Welcome to the community. 🤖 Copilot has been assigned for an initial review. @RayBB is assigned to this PR and currently has:
Note: The linked issue (#12503) hasn't been triaged yet — triage happens on Mondays and Fridays. This doesn't block your PR from being reviewed, but priority labeling on the issue may affect queue ordering. PR triage checklist (maintainers / Pam)
Note This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting. |
There was a problem hiding this comment.
Pull request overview
Refactors the Open Library Python codebase to remove usage of deprecated web.lstrips(...) / web.rstrips(...) helpers in favor of standard-library str.removeprefix(...) / str.removesuffix(...), aligning with modern Python and reducing reliance on legacy web.py string utilities.
Changes:
- Replaced
web.lstrips(...)withstr.removeprefix(...)across scripts andopenlibrary/modules. - Replaced
web.rstrips(...)withstr.removesuffix(...)across scripts andopenlibrary/modules. - Updated related imports where needed (some unused imports remain; see PR comments).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/solr_updater/solr_updater.py | Uses removeprefix when normalizing ol_url host for Solr updates. |
| scripts/pull-templates.py | Uses removeprefix when mapping template keys to filesystem paths. |
| scripts/generate-api-docs.py | Uses removeprefix when computing submodule doc paths. |
| scripts/copydocs.py | Uses removeprefix when deriving .olrc section name from destination URL. |
| openlibrary/solr/update.py | Uses removeprefix when normalizing host passed to Solr query config. |
| openlibrary/plugins/worksearch/subjects.py | Uses removeprefix to derive subject path from a prefixed key. |
| openlibrary/plugins/upstream/code.py | Uses removesuffix to normalize a root path used for dynamic documents. |
| openlibrary/plugins/openlibrary/lists.py | Uses removeprefix when converting subject: keys to subject URLs. |
| openlibrary/plugins/openlibrary/code.py | Uses removesuffix to normalize user_root for bot user key construction. |
| openlibrary/plugins/admin/code.py | Uses removesuffix to normalize server URLs before appending /_reload. |
| openlibrary/mocks/mock_infobase.py | Uses removesuffix when normalizing flattened index key suffixes. |
| openlibrary/coverstore/utils.py | Uses removesuffix to normalize configured OL base URL. |
| openlibrary/core/processors/readableurls.py | Uses removeprefix to compute URL “extra” after regex prefix match. |
| openlibrary/core/lists/model.py | Uses removeprefix when generating subject URLs from subject: seed keys. |
RayBB
left a comment
There was a problem hiding this comment.
Working great locally and on testing.
Thank you!
Closes #12503
Summary
web.lstrips(...)calls withstr.removeprefix(...).web.rstrips(...)calls withstr.removesuffix(...).openlibrary/andscripts/files listed in the issue while preserving behavior.Testing
git grep -n web\\.lstrips\\|web\\.rstrips -- . :(exclude)vendorreturned no matches.python -m compileall -q openlibrary/core/lists/model.py openlibrary/core/processors/readableurls.py openlibrary/coverstore/utils.py openlibrary/mocks/mock_infobase.py openlibrary/plugins/admin/code.py openlibrary/plugins/openlibrary/code.py openlibrary/plugins/openlibrary/lists.py openlibrary/plugins/upstream/code.py openlibrary/plugins/worksearch/subjects.py openlibrary/solr/update.py scripts/copydocs.py scripts/generate-api-docs.py scripts/pull-templates.py scripts/solr_updater/solr_updater.pyNote: I did not run the full test suite locally because the local environment does not have the repo test dependencies installed and this checkout expects Python
>=3.12.2,<3.12.3.