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

Support variant specific patches #485

Conversation

fabiendupont
Copy link

@fabiendupont fabiendupont commented Oct 25, 2024

When building wheels for different variants, the code base might be
different from one variant to the other, for example when the code comes
from a fork with variant specific features. And with a different code
base, the patches may fail to be applied.

This changes proposes to support patch files stored in a variant
specific path under the existing unversioned and versioned patch
directories. Below is an example of a patch tree:

.../patches
.../patches/deepspeed
.../pacthes/deepspeed/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed/brie/0001-unversioned.patch
.../patches/deepspeed/feta/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch
.../patches/deepspeed-0.5.0/brie/0003-versioned.patch

When applying the patches for the brie variant, the following patches
would be applied:

.../pacthes/deepspeed/0001-unversioned.patch
.../patches/deepspeed/brie/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch
.../patches/deepspeed-0.5.0/brie/0003-versioned.patch

When applying the patches for the feta variant, the following patches
would be applied:

.../pacthes/deepspeed/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed/feta/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch

Fixes #486

@mergify mergify bot added the ci label Oct 25, 2024
@dhellmann dhellmann requested a review from shubhbapna October 25, 2024 13:21
Copy link
Collaborator

@tiran tiran left a comment

Choose a reason for hiding this comment

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

I would prefer patch_dir / ctx.variant / "*.patch".

There is also code in packagesettings that deals with patches. You have to extend the code and its test it, too.

Please add documentation.

src/fromager/overrides.py Outdated Show resolved Hide resolved
@@ -98,6 +98,7 @@ def patches_for_requirement(
patches_dir: pathlib.Path,
req: Requirement,
version: Version,
variant: str = "",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The variant name should be passed by passing a Context object as first argument.

Copy link
Author

Choose a reason for hiding this comment

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

That would be the only method with a Context object in this package. This is mostly helpers. And an extra variable with a default value reduces the size of the change.

Not saying I'm against the idea. Just giving more context about why I did it this way.

return itertools.chain(
# Apply all of the unversioned patches first, in order based on
# filename.
sorted(unversioned_patch_dir.glob("*.patch")),
sorted(unversioned_patch_files),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to sort by the file's name, not the full path.

Copy link
Member

Choose a reason for hiding this comment

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

Should we be explicit about the precedence of variant-specific patches vs. the general ones by including them in this itertools.chain() call separately?

We probably want

  1. unversioned
  2. versioned
  3. unversioned variant
  4. versioned variant

right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds complicated. I won't be able to recall the correct order in a week from now. How about we throw everything in a single list, then sort all files by their base name?

Copy link
Member

Choose a reason for hiding this comment

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

We already give precedence to the files in the directory without the version. I think we don't have any of those downstream, so we probably wouldn't break anything making the change you propose. I guess it lets users manage precedence themselves using numerical prefixes, too, so maybe that's a good thing?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that was the idea. The prefix is what decides the order. The user can easily insert a variant specific patch by using the same number as the global patch. variant/0001-xx.patch will have precedence over 0002-aa.patch.

@fabiendupont fabiendupont force-pushed the allow-variant-specific-patches branch from f0d43f9 to ef9e36b Compare October 28, 2024 11:29
When building wheels for different variants, the code base might be
different from one variant to the other, for example when the code comes
from a fork with variant specific features. And with a different code
base, the patches may fail to be applied.

This changes proposes to support patch files stored in a variant
specific path under the existing unversioned and versioned patch
directories. Below is an example of a patch tree:

```
.../patches
.../patches/deepspeed
.../pacthes/deepspeed/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed/brie/0001-unversioned.patch
.../patches/deepspeed/feta/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch
.../patches/deepspeed-0.5.0/brie/0003-versioned.patch
```

When applying the patches for the `brie` variant, the following patches
would be applied:

```
.../pacthes/deepspeed/0001-unversioned.patch
.../patches/deepspeed/brie/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch
.../patches/deepspeed-0.5.0/brie/0003-versioned.patch
```

When applying the patches for the `feta` variant, the following patches
would be applied:

```
.../pacthes/deepspeed/0001-unversioned.patch
.../pacthes/deepspeed/0002-unversioned.patch
.../patches/deepspeed/feta/0002-unversioned.patch
.../patches/deepspeed-0.5.0/0001-versioned.patch
```

Signed-off-by: Fabien Dupont <[email protected]>
@fabiendupont fabiendupont force-pushed the allow-variant-specific-patches branch from ef9e36b to ae2774a Compare October 28, 2024 13:09
Copy link
Contributor

@rd4398 rd4398 left a comment

Choose a reason for hiding this comment

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

LGTM!
I will leave it to other reviewers to approve and merge

@fabiendupont
Copy link
Author

fabiendupont commented Oct 29, 2024

Seems that #488 is also implementing this change. @tiran, @dhellmann, I guess this PR can be closed, right?

@dhellmann
Copy link
Member

Seems that #488 is also implementing this change. @tiran, @dhellmann, I guess this PR can be closed, right?

I think so, yes.

@fabiendupont
Copy link
Author

Closing in favor of #488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support variant specific patches
4 participants