Skip to content

Comments

Build backend: Support data files #9197

Merged
konstin merged 4 commits intomainfrom
konsti/build-backend-wheel-data
Nov 19, 2024
Merged

Build backend: Support data files #9197
konstin merged 4 commits intomainfrom
konsti/build-backend-wheel-data

Conversation

@konstin
Copy link
Member

@konstin konstin commented Nov 18, 2024

Allow including data files in wheels, configured through pyproject.toml. This configuration is currently only read in the build backend. We'd only start using it in the frontend when we're adding a fast path.

Each data entry is a directory, whose contents are copied to the matching directory in the wheel in <name>-<version>.data/(purelib|platlib|headers|scripts|data). Upon installation, this data is moved to its target location, as defined by https://docs.python.org/3.12/library/sysconfig.html#installation-paths:

  • data: Installed over the virtualenv environment root. Warning: This may override existing files!
  • scripts: Installed to the directory for executables, <venv>/bin on Unix or <venv>\Scripts on Windows. This directory is added to PATH when the virtual environment is activated or when using uv run, so this data type can be used to install additional binaries. Consider using project.scripts instead for starting Python code.
  • headers: Installed to the include directory, where compilers building Python packages with this package as built requirement will search for header files.
  • purelib and platlib: Installed to the site-packages directory. It is not recommended to uses these two options.

For simplicity, for now we're just defining a directory to be copied for each data directory, while using the glob based include mechanism in the background. We thereby introduce a third mechanism next to the main includes and the PEP 639 mechanism, which is not what we should finalize on.

@konstin konstin added the preview Experimental behavior label Nov 18, 2024
@konstin konstin requested a review from BurntSushi November 18, 2024 13:50
@konstin konstin force-pushed the konsti/build-backend-wheel-data branch from b8d8711 to 14a60c9 Compare November 18, 2024 13:59
@cthoyt
Copy link
Contributor

cthoyt commented Nov 18, 2024

@konstin thanks for all of the great work on this. If you ever need some external testers, please ping me!

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

("platlib", self.platlib.as_deref()),
("headers", self.headers.as_deref()),
("scripts", self.scripts.as_deref()),
("data", self.data.as_deref()),
Copy link
Member

Choose a reason for hiding this comment

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

Might be more ceremony, but if you need to match on them, I might use an enum for the &'static str here.

(But if it's really just used as a label in string form, I think what you have is totally fine.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Here, I'm just mapping the key name to the folder name.

@konstin konstin force-pushed the konsti/build-backend-wheel-data branch from 6d90f68 to 83003ca Compare November 19, 2024 11:02
@konstin konstin merged commit 9460398 into main Nov 19, 2024
@konstin konstin deleted the konsti/build-backend-wheel-data branch November 19, 2024 12:00
@konstin konstin mentioned this pull request Nov 20, 2024
32 tasks
@ehrenfeu
Copy link

ehrenfeu commented Jun 6, 2025

(Sorry for hijacking this PR thread, please let me know if you prefer me to open a separate issue...)

Quick question: I'd love to use this feature, but from my brief tests using version 0.7.11, this is not yet possible via uv build, correct?

I'm having an entry like this in my pyproject.toml:

[tool.uv.wheel.data]
data = "conffiles"

When calling uv build it tells me (output truncated):

warning: Failed to parse `pyproject.toml` during settings discovery:
  TOML parse error at line 22, column 10
     |
  22 | [tool.uv.wheel.data]
     |          ^^^^^
  unknown field `wheel`

💡 Which is probably what is stated in the 3rd phrase of this PR issue (at least that's my interpretation):

We'd only start using it in the frontend when we're adding a fast path.

❓ So, is it currently possible somehow to include extra stuff into wheels built by uv, in a similar fashion as through setuptool's Data Files fashion? I've spent quite some time reading docs and testing stuff in my project config, without success though...

Many thanks! 💚
~Niko

@ehrenfeu
Copy link

ehrenfeu commented Jun 6, 2025

Never mind. Found it right after submitting this message:

https://docs.astral.sh/uv/reference/settings/#build-backend_data

These entries do the job for me:

[tool.uv]
package = true

[tool.uv.build-backend]
data = { "data" = "extra_files" }

[build-system]
requires = ["uv_build>=0.7.11,<0.8.0"]
build-backend = "uv_build"

Thanks again! 💚
~Niko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants