pybuilder icon indicating copy to clipboard operation
pybuilder copied to clipboard

Installing a plugin from a private PyPI repository

Open kvalev opened this issue 8 years ago • 11 comments

I am trying to integrate a pybuilder plugin that is deployed in a private PyPI repository, but it seems that the link to the repository is being ignored by the plugin downloader. It appears that the plugin is loaded right when the use_plugin() statement is encountered, but the project properties are not set at that point, leading to those 3 parameters being None

@init
def initialize(project):
    # ....
    project.set_property('install_dependencies_extra_index_url', 'url goes here')

kvalev avatar Oct 26 '17 18:10 kvalev

After some digging it seems that things are done a bit out of order - first the project module is loaded, which implies loading all plugins and the initializers are executed much later.

As a workaround one can access the project object from the Reactor instance and set the properties required for loading the plugin there:

from pybuilder.core import init, use_plugin
from pybuilder.reactor import Reactor

# loading other plugins...

# required to access a private PyPI repository
project = Reactor.current_instance().project
project.set_property('install_dependencies_extra_index_url', 'pypi url')
project.set_property('install_dependencies_trusted_host', 'hostname')

use_plugin('pypi:pybuilder_private_pypi_plugin')

@init
def initialize(project):
    # the usual stuff

kvalev avatar Oct 26 '17 18:10 kvalev

Hi, @kvalev Great workaround.

AlexeySanko avatar Oct 26 '17 19:10 AlexeySanko

Unfortunately, workaround doesn't work for me - I need to pass install_dependencies_extra_index_url from command line. But PyBuilder applies properties from command line later.

AlexeySanko avatar Oct 27 '17 12:10 AlexeySanko

Created #515 which provides global properties from command line to properties immediately.

AlexeySanko avatar Oct 27 '17 13:10 AlexeySanko

Did corresponding changes into pypi_server plugin Now it sets properties on use_plugin step. So usage is:

use_plugin('...')
use_plugin('...')
....
use_plugin('pypi:pybuilder_pypi_server')
use_plugin('pypi:pybuilder_private_pypi_plugin')

And call with -P pypi_server=... like

pyb clean install_dependencies analyze publish --debug --environment=dev -P pypi_server=my-pypi-dev

AlexeySanko avatar Oct 27 '17 18:10 AlexeySanko

@arcivanov we are planning to use pybuilder and build many custom plugins, is this issue regarding using a private repository handled and is a there a recommended way to do it ?

pavan-kumar222 avatar Sep 11 '21 09:09 pavan-kumar222

@pavan-kumar222 What kind of authentication are you looking for in the private repository?

arcivanov avatar Sep 11 '21 19:09 arcivanov

You can see here the way private repository authentication can be configured outside of PyB: https://pip.pypa.io/en/stable/topics/authentication/

arcivanov avatar Sep 11 '21 19:09 arcivanov

@arcivanov I will use either username/pwd based authentication or a user token. We will try to use Nexus to host Pypi type private repo.

However my question was in similar lines as the first comment in this issue, Should I use the workaround mentioned here to load the plugin from my private repo or is there a better way, where a plugin is first searched in public pypi and also private repo automatically.

pavan-kumar222 avatar Sep 14 '21 01:09 pavan-kumar222

I'll need to create/find a test harness that allows PIP503-compliant repository to test your use case. A lot of things changed since 2017, including internal pip logic.

arcivanov avatar Sep 15 '21 01:09 arcivanov

I've done some debugging, and while the workaround above does works for me - the url for my private PIP repo does indeed get added when PIP is being executed - I'm getting an SSL error, because my repo is using a SSL certificate not trusted by default by PIP. The workaround would work for my, if the --cert option for PIP was exposed I guess.

lyager avatar Jul 27 '22 12:07 lyager