Python package with custom pip config/arguments

Trying to port a core18 snap to core22. It uses and needs to pull in packages from a custom PyPI index. Previously this was on an issue, but recent version of pip have (logically) tightened requirements around use of custom indices. In this case, the most obvious solution appears to be to pass an --extra-index-url https://custom/index/ argument to pip in order to enable installation of packages from our index. But it’s not clear to me how to do that as part of the snapcraft install.

According to the pip docs I should be able to pass the above-mentioned parameter either in an environment variable or a pip.conf file inside the virtualenv. But I don’t know whether I can “inject” either of those there during the build process. Is doing an override-build my best option here? And if so, could anyone point me to the “starting point” I should use for customization? Is it basically what’s yielded by this function? I had a go with something like

override-build: |
  export PIP_EXTRA_INDEX_URL=https://custom/index/
  snapcraftctl build

but it doesn’t look like the parameter got picked up.

Thanks for any tips!

Tipped off by How to set environment variables for parts?, it seems that the correct solution (or at least one way to do this) is to use build-environment. E.g. in this case

  - PIP_EXTRA_INDEX_URL: https://...

under the respective part definition.

1 Like