<@U04S45AHA> can u provide some pointers on how I ...
# development
p
@enough-analyst-54434 can u provide some pointers on how I would go about patching pip in pex (context: https://github.com/pantsbuild/pex/pull/1833) I have looked at the code under https://github.com/pantsbuild/pex/tree/main/pex/pip (including some of the code that patches pip) but I could not figure out where is the appropriate place to put the patch code, which will basically replace the
_build_session
method https://github.com/pantsbuild/pex/blob/main/pex/vendor/_vendored/pip/pip/_internal/cli/req_command.py#L85 i.e. call the original method and then modify the returned PipSession by modifying
PipSession.headers['User-Agent']
see: https://github.com/pantsbuild/pex/blob/887607e1ca461001519214eba7fb7f8f3cc31978/pex/vendor/_vendored/pip/pip/_internal/network/session.py#L248
e
I think this should be a physical patch applied post vendoring. That venodring has its entrypoint here: https://github.com/pantsbuild/pex/blob/ddc2d23799b976d301626d1ca8ee27947674d738/tox.ini#L97-L112 So the patch could either be applied after the format-run step in tox or else in the vendoring main: https://github.com/pantsbuild/pex/blob/887607e1ca461001519214eba7fb7f8f3cc31978/pex/vendor/__main__.py#L359-L378
So, basically a call to
git apply
with a patch file.
p
looking at this code and I am somewhat confused... is there a similar patch we apply to pip or to any of the other vendored packages (not including the common/generic stuff to change imports)
e
There is not, this would be new. So: 1. We vendor a patched version of Pip from the pantsbuild fork that works around bugs: https://github.com/pantsbuild/pex/blob/887607e1ca461001519214eba7fb7f8f3cc31978/pex/vendor/__init__.py#L163-L181 2. We apply runtime monkeypatches for the purposes of a bug Pip won't fix yet (https://github.com/pypa/pip/issues/10050) and `pex3 lock create --style universal`: + https://github.com/pantsbuild/pex/blob/9d916dac75fb418b52c0ef9536f2dd72ac124d5c/pex/pip/foreign_platform.py#L110-L136 + https://github.com/pantsbuild/pex/blob/c9370a4a00a7b5e6909c8a8b214211a37d34a9d0/pex/resolve/locker.py#L331-L385 1. will go away with the next Pip vendoring upgrade and we'll be back to stock Pip. I think it makes more sense to maintain the patches to Pip in the form of a patch file at that point, since there should be no patching of Pip anymore to work around bugs. 2. currently has the limitation of 1 patch per invocation. That could be loosened, but I'd prefer to limit the runtime patching. I can't justify that last sentence too well, but just applying via
git apply patch
is simpler anyhow and minds could be changed later if you agree.