refactor(pypi): factor out a simple implementation of the PyPI cache#3639
Conversation
We want to keep a `dict` like interface and later we would like to use the same interface to also do more things. I expect the cache key to become different in the future (i.e. include requested versions in it) so that we can check if we have the right versions in the MODULE.bazel.lock file or if we should actually call to PyPI. Work towards bazel-contrib#2731
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the PyPI index content caching mechanism by extracting the caching logic into a dedicated Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the PyPI cache from a simple dictionary to a more structured object, which is a good step towards better encapsulation and future enhancements. The implementation is sound, but I have one suggestion to further improve the new cache implementation by using a more idiomatic Starlark pattern for creating objects with state.
rickeylev
left a comment
There was a problem hiding this comment.
This change looks too simple?
The cache is changing from a dict to custom object. How is this working? Ah, is it because it just happens that only e.g. get() and setdefault() are used, not [] ?
python/private/pypi/pypi_cache.bzl
Outdated
| def pypi_cache(): | ||
| """The cache for PyPI index queries.""" | ||
| self = struct( | ||
| store = {}, |
There was a problem hiding this comment.
Should this be _store to indicate its internal, and that the setdefault/get methods re supposed to be used?
|
Yeah, I wanted to first create a seam and change the usage to not assume a dict. Later this will grow more meat. |
We want to keep a
dictlike interface and later we would like to usethe same interface to also do more things. I expect the cache key to
become different in the future (i.e. include requested versions in it)
so that we can check if we have the right versions in the
MODULE.bazel.lock file or if we should actually call to PyPI.
Work towards #2731