Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bpdavis86 opened this issue Sep 2, 2021 · 1 comment
Labels
feature:new something does not exist yet, but should

Comments

@bpdavis86
Copy link

bpdavis86 commented Sep 2, 2021

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.

@bpdavis86 bpdavis86 added the feature:new something does not exist yet, but should label Sep 2, 2021
@gaborbernat
Copy link
Member

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.

You can change that via https://virtualenv.pypa.io/en/latest/extend.html#seed-mechanism

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:new something does not exist yet, but should
Projects
None yet
Development

No branches or pull requests

2 participants