Skip to content

Conversation

@nicoonoclaste
Copy link
Collaborator

@nicoonoclaste nicoonoclaste commented Aug 11, 2024

  • utils.scoped_cache: new decorator, modifying a class to memoize method calls using autogenerated object attributes
    Unlike functools.lru_cache, this ensures the cached data cannot outlive the Builder object... and does not require it
    to be hasheable (incl. its attributes, like build.{env.IsolatedEnv, ProjectBuilder})
    Not sure I like the name, so I'm definitely open to other suggestions.

    • add tests
  • builder.prepare.Bob

    • apply scoped_cache, ensuring nothing is ever built more than once (from the same Builder)
    • build: reuse metadata if it was already built
      it shouldn't be done unconditionally, since building metadata may (in the worst case) require building the wheel
    • metadata_path: directly extract metadata from the wheel
      • if a wheel was already built, extract its metadata rather than rebuild it (either metadata-only or the whole wheel)
      • if building a wheel is necessary, ensure the result is cached

I am leaving this as a draft for now, as I don't think we'll see significant improvement before refactoring the public API:
currently, the builder isn't reused between sdist+wheel, zipapps, and metadata calls (in the PyPI uploader)

Dropped the `settings` parameter, as it couldn't be cached (dict isn't
hashable) and wasn't used anyway.  If this become an issue, I could
special-case the hashing of `dict`s in `scoped_cache`

This avoids rebuilds with successive method calls.

The results are not meaningful anymore outside a given build's context,
and `scoped_cache` ties the cached outputs to the `Builder` object so
we cannot leak memory.
@nicoonoclaste
Copy link
Collaborator Author

bork/builder.py:149: error: "Bob" has no attribute "_build"; maybe "build"? [attr-defined]

I guess I'd also need to inject annotations

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.

1 participant