Skip to content

Support for bootstrapping keyring package to create virtualenv with private index- preinstall script #2199

Closed
@bpdavis86

Description

@bpdavis86

Let me first describe my issue. I have one or more packages that come from a private PyPi repo. This repo is described in my pip config file with install.extra-index-url. (I know there are security issues now associated with this approach, we'll ignore those for now). I do not wish to embed the password information for the private repo in this URL, therefore, I am using the keyring package to store the credential in the system credential manager. This works without a hitch in my normal operations, as I can do

pip install my-private-package

with no issue.

However, when it comes to setting up a tox environment with this package, this workflow fails due to the fact that keyring is not part of the virtualenv seed package set. Unfortunately I can't simply do

[testenv]
deps = 
    keyring
    pytest
    ...
    my-private-package

because these packages appear to all get installed with a single pip command, so pip cannot make use of keyring to install the later package.

Neither does it seem to help to include keyring in tox.requires, because that places limitations on the base environment that tox runs out of, not the virtualenv starting packages. (I already have keyring satisfied in the base environment).

My current workaround for this is to add PIP_FIND_LINKS to testenv.passenv and call tox with

pip download --no-deps -d ./downloads my-private-package
PIP_FIND_LINKS=./downloads tox

There are a few ways I could see solving this from within tox. The first would be to use a custom virtualenv with keyring as an included seed package. I have not looked into this yet due to the relative difficulty of building and integrating such a package.

Another solution that appeals to me would be to add a commands_pre_install section to the environment definition. These commands would run after the virtualenv is created but before the deps and artifact under test are installed.
For example, for my use case

[testenv]
commands_pre_install = 
    pip install keyring
deps = 
    pytest
    ...
    my-private-package

Such a command could also be used for upgrading the virtualenv seed packages if desired before the main install. If necessary, one could just skip the deps section entirely and completely customize the virtualenv setup process using these commands. This would alleviate issues caused by e.g. the deprecation of the indexserver option.

I should clarify this is not the same as command_pre. This setup does not work either.

[testenv]
commands_pre = 
    pip install keyring
deps = 
    pytest
    ...
    my-private-package

It seems a similar solution was proposed in #715 as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:newsomething does not exist yet, but should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions