Skip to content

Upgrade runtime dependencies and harden Google Lens response parsing - #6

Merged
krishna2206 merged 3 commits into
masterfrom
copilot/update-dependencies-code-quality
Jul 22, 2026
Merged

Upgrade runtime dependencies and harden Google Lens response parsing#6
krishna2206 merged 3 commits into
masterfrom
copilot/update-dependencies-code-quality

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This updates the project’s dependency baseline and improves resilience in the Google Lens parsing path. The API surface remains unchanged while reducing failure modes from malformed/shifted upstream response structures.

  • Dependency baseline

    • Bumped runtime requirements to current package names/versions:
      • requests>=2.34.2
      • beautifulsoup4>=4.15.0
    • Aligned requirements.txt and setup.py so install paths resolve the same dependency set.
  • Parser hardening

    • Replaced fragile chained indexing with a safe nested accessor for prerender payload traversal.
    • Added explicit validation/errors when required prerender script/hash segments are missing.
    • Preserved existing output schema (match, similar) while making extraction tolerant to partial/missing fields.
  • Request/file handling quality

    • Ensured uploaded files are always closed via context-managed file IO.
    • Added request timeouts to upload/follow-up calls to avoid indefinite hangs.
with open(file_path, "rb") as image_file:
    response = self.session.post(
        self.url + "/upload",
        files={"encoded_image": (file_path, image_file), "image_content": ""},
        params={"hl": "en", "gl": "us"},
        allow_redirects=False,
        timeout=30,
    )

@krishna2206
krishna2206 marked this pull request as ready for review July 22, 2026 04:36
Copilot AI review requested due to automatic review settings July 22, 2026 04:36
@krishna2206
krishna2206 merged commit 0421cb2 into master Jul 22, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates runtime dependency minimums and makes the Google Lens prerender parsing + request flow more resilient by adding safer traversal, explicit parse failures, context-managed file IO, and request timeouts.

Changes:

  • Bumped dependency minimums in both requirements.txt and setup.py (requests>=2.34.2, beautifulsoup4>=4.15.0).
  • Reworked prerender extraction/parsing to avoid fragile chained indexing by introducing a safe nested accessor and clearer parse errors.
  • Improved request/file handling by ensuring uploaded files are closed and adding timeouts to HTTP calls.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
setup.py Updates install requirements to minimum pinned versions.
requirements.txt Aligns runtime dependency minimums with setup.py.
googlelens/googlelens.py Hardens prerender parsing, adds safe accessors, and adds timeouts + context-managed file IO.
google_lens_python.egg-info/top_level.txt Adds generated setuptools artifact.
google_lens_python.egg-info/SOURCES.txt Adds generated setuptools artifact listing package sources.
google_lens_python.egg-info/requires.txt Adds generated setuptools artifact for dependencies.
google_lens_python.egg-info/PKG-INFO Adds generated setuptools metadata artifact.
google_lens_python.egg-info/dependency_links.txt Adds generated setuptools artifact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread googlelens/googlelens.py
return prerender_script['data'][1]

@staticmethod
def __safe_get(value: Any, path: list[int]) -> Any:
Comment thread googlelens/googlelens.py
Comment on lines +167 to +170
multipart = {
'encoded_image': (file_path, image_file),
'image_content': ''
}
Comment on lines +1 to +5
README.md
setup.py
google_lens_python.egg-info/PKG-INFO
google_lens_python.egg-info/SOURCES.txt
google_lens_python.egg-info/dependency_links.txt
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.

3 participants