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

Building variant wheels from same source code #1669

Open
sponsfreixes opened this issue Aug 7, 2024 · 5 comments
Open

Building variant wheels from same source code #1669

sponsfreixes opened this issue Aug 7, 2024 · 5 comments

Comments

@sponsfreixes
Copy link

Is there a way of building two different Python wheels from the same source code, with one of the wheels not including some specific module/package?

I could use two different pyproject.toml files, but it seems that hatch build doesn't accept the --config option.

I looked at the documentation for environments and versions, but if they are the solution, I can't figure out how to use them for my scenario.

Thanks!

@teruokun
Copy link

teruokun commented Aug 9, 2024

It would be good to understand your use-case in a bit more detail to understand why the following options aren't good choices:

  • Using standard extras metadata to define an added named feature set which requires additional dependencies
  • Conditional dependencies which are based on platform, python version, or the version of another dependency

@sponsfreixes
Copy link
Author

sponsfreixes commented Aug 9, 2024

Sure, let me explain better the use case, I didn't do a good job on the initial post.

I work on a company that wants to create a Python library. This library will be distributed in two ways:

  • Internally, using a devpi repository that only company workers can access. The plan is to create a wheel with all the features of the library, and push it to the devpi repo.
  • We want to share that same library with some customers. We will share with them the wheel file (copying it to some artifact repository), and they can manually download and install it. The catch is that we want them to only access a subset of the functionality.

I can create these two wheels by building first with:

[tool.hatch.build.targets.wheel]
packages = ["src/my-library"]

And then building again after changing it to:

[tool.hatch.build.targets.wheel]
packages = ["src/my-library"]
exclude = ["src/my-library/extra-features"]

I'm currently doing it manually, but once we put that on a CI, it becomes awkward to automate. I would be OK with having two different pyproject.toml files, but it seems that hatch build doesn't accept the --config option.

I know that an option would be to put the extra functionality on a separate package, but then we have to tell our internal users to either do pip install my-library my-library-extra-features or pip install my-library[extra-features], and it's not as nice as just pip install my-library, plus the fact than now we have two separate code bases.

@ofek
Copy link
Collaborator

ofek commented Aug 9, 2024

That makes more sense, thanks for triaging this Jeff!

What you could do is create a custom build target and invoke hatch build -t custom. The file would look basically like:

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.builders.wheel import WheelBuilder

def get_builder():
    return CustomWheelBuilder

class CustomWheelBuilder(WheelBuilder):
    pass

@teruokun
Copy link

teruokun commented Aug 9, 2024 via email

@ovidiu-eremia
Copy link

ovidiu-eremia commented Aug 12, 2024

Hi @ofek @teruokun,

Sorry for bothering you here, but I have a similar situation in a monorepo:
#1676

Could you please take a look? I would just need an advice on how to best implement the builder plugin to do such a thing...

Thank you!

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

No branches or pull requests

4 participants