Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out a plan to stabilize isolated extension usages #20186

Open
Wyverald opened this issue Nov 13, 2023 · 3 comments
Open

Figure out a plan to stabilize isolated extension usages #20186

Wyverald opened this issue Nov 13, 2023 · 3 comments
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: process

Comments

@Wyverald
Copy link
Member

Isolated extension usages (use_extension(..., isolate=True)) are currently guarded behind the flag --experimental_isolated_extension_usages.

This feature is useful in particular as it allows an extension to easily generate repos scoped to a single user module. However, it is a rather big departure in the mental model of module extensions, as it essentially allows an extension to be evaluated "multiple times" (small print -- big simplification, etc etc); certain extensions that may rely on being "used" by its hosting module might break under this model; and the ID of an extension is not just ".bzl file label + extension name" anymore.

To stabilize this feature, we should evaluate other solutions to the "user-module-scoped repos" problem, and think about ways to mitigate the downsides of isolated extension usages (documentation? intentional limitations?).

@Wyverald Wyverald added P2 We'll consider working on this in future. (Assignee optional) type: process team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests labels Nov 13, 2023
@Wyverald
Copy link
Member Author

cc @fmeum @aherrmann

@fmeum
Copy link
Collaborator

fmeum commented Dec 23, 2023

Just noting some insights I had that are relevant for the evaluation:

  1. Isolated extension usages receive independent lockfile entries, which limits the impact of tag changes for non-deterministic extensions.
  2. Without isolated extension usages, extensions may need to recommend per-module repo prefixes that include the module version if they need to distinguish module versions in the case of a multiple_version_override (e.g. because the extension relies on its own lockfile, which may conflict if multiple module versions contribute one). Nobody will realistically do this as it causes huge churn on version bumps and is only relevant in this edge case, but it may make multiple_version_override hard to use with rulesets in practice.
  3. Isolated extension instances can still share a static list of deps by having the module use_repo them from the main instance.

@aherrmann
Copy link
Contributor

Apologies for the late reply. It didn't get to this earlier.

I'll share how isolated extensions are currently used in rules_nixpkgs and what problem they solve.

The key issue that isolated extensions solve in this case is that of repo namespacing. Apart from that rules_nixpkgs does not further require the separation of extension instances. So, an alternative approach could be a common mechanism to introduce per client module namespaces.

Indeed, the possible presence of multiple extension instances has to be taken into account by each module extension author. For instance, take an extension providing toolchains that expects the generated toolchains repo to only be included by the core module and generates its extension metadata accordingly. If this extension is used in isolated mode, then it should expose the toolchains repo to the invoking module instead.

aignas added a commit to aignas/rules_python that referenced this issue Mar 10, 2024
This is a variant of bazelbuild#1625 and was inspired by bazelbuild#1788. In bazelbuild#1625, we
attempt to parse the simple API HTML files in the same `pip.parse`
extension and it brings the follownig challenges:

* The `pip.parse` cannot be easily use in `isolated` mode and it may
  be difficult to implement the isolation if bazelbuild/bazel#20186
  moves forward.
* Splitting the `pypi_index` out of the `pip.parse` allows us to accept
  the location of the parsed simple API artifacts encoded as a bazel
  label.
* Separation of the logic allows us to very easily implement usage of
  the downloader for cross-platform wheels.
* The `whl` `METADATA` might not be exposed through older versions of
  Artifactory, so having the complexity hidden in this single extension
  allows us to not increase the complexity and scope of `pip.parse` too
  much.
* The repository structure can be reused for `pypi_install` extension
  from bazelbuild#1728.

TODO:
- [ ] Add unit tests for functions in `pypi_index.bzl` bzlmod extension if
  the design looks good.
- [ ] Changelog.

Out of scope of this PR:
- Further usage of the downloaded artifacts to implement something
  similar to bazelbuild#1625 or bazelbuild#1744. This needs bazelbuild#1750 and bazelbuild#1764.
- Making the lock file the same on all platforms - We would need
  to fully parse the requirements file.
- Support for different dependency versions in the `pip.parse` hub repos
  based on each platform - we would need to be able to interpret
  platform markers in some way, but `pypi_index` should be good already.
- Implementing the parsing of METADATA to detect dependency cycles.
- Support for `requirements` files that are not created via
  `pip-compile`.
- Support for other lock formats, though that would be reasonably
  trivial to add.

Open questions:
- Support for VCS dependencies in requirements files - We should
  probably handle them as `overrides` in the `pypi_index` extension and
  treat them in `pip.parse` just as an `sdist`, but I am not sure it
  would work without any issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: process
Projects
Status: Todo
Development

No branches or pull requests

3 participants