Dynamically modifiy requirements through plugin #4712
Unanswered
staley-arlut
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the correct way to have a setuptools
distutils.commands
plugin dynamically add requirements and optional requirements?I have a hack of a solution that involves manipulating the
install_requires
andextras_require
attributes on thedistribution
/distribution.metadata
objects during my custom command'sfinalize_options
step. This seems to work as far back as setuptools v39.2.0, but has recently stopped working as of v75.2.0.For context, my use case is due to Google Protocol Buffers(protobuf):
The plugin command runs the protobuf compiler (protoc) at build time in order to generate python source modules. Unfortunately, using protobuf makes packaging python wheels difficult due to needing to match the runtime package
protobuf
version with the version of the protobuf compiler (protoc) used at build time.I try to keep my source code compatible with as wide a range of versions as I can. For instance, I've written package code that can work with
protobuf
versions 3.5 through 5.x. However whenprotoc
generates it's python modules, it inherently reduces the versions of theprotobuf
package my wheel is compatible with. It even seems like for now (pre-2025), the protobuf developers want you to match the versions of the generator and runtime library exactly (see (cross-version-runtime-guarantee)[https://protobuf.dev/support/cross-version-runtime-guarantee]).So, my solution to this has been to have my setuptools plugin dynamically lock the version requirement of the
protobuf
runtime package based on the version ofprotoc
it used to generate the wheel. I don't love this solution, because it means you cannot install two wheels that were built with differentprotoc
versions to the same environment, but I'm not sure how else to solve this problem.Beta Was this translation helpful? Give feedback.
All reactions