Skip to content
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

Allow this project to bootstrap itself with tox #9

Merged
merged 5 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test-tox-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
name: Tox plugin - Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install tox
- run: python -m pip install -e .
- run: python -m tox -c tests/tox-plugin/tox.ini
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
build/
.eggs/
*.egg-info/
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,37 @@ To use the keyring backend:
* `keyrings.gauth.GooglePyPIAuth (priority: 9)`
* `keyring.backends.chainer.ChainerBackend (priority: 10)`
* `keyring.backends.fail.Keyring (priority: 0)`

## Usage with other tools

### Usage with `tox`

The [`tox` tool](https://pypi.org/project/tox/) is a testing and automation tool.

Because the credential helper needs to be installed _before_ any private
dependencies are installed, it needs to be bootstrapped into the `tox`
environment via a plugin.

To do this, specify the `keyrings.google-artifactregistry-auth` package via the
[`requires`](https://tox.readthedocs.io/en/latest/config.html#conf-requires)
requirement in your `tox.ini` file:

```
[tox]
envlist = py
requires = keyrings.google-artifactregistry-auth
```

You can then configure your `tox.ini` file to use the Artifact Registry repo as
an extra index, and specify both public and private dependencies:

```
[testenv]
setenv =
PIP_EXTRA_INDEX_URL = https://[REGION]-pypi.pkg.dev/[PROJECT_ID]/[REPOSITORY]/simple
deps =
# samplepackage will be installed directly from PyPI
samplepackage
# mypackage will be installed from the Artifact Registry repository
mypackage
```
1 change: 1 addition & 0 deletions google_artifactregistry_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.2"
17 changes: 17 additions & 0 deletions google_artifactregistry_auth/tox_bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pluggy

import google_artifactregistry_auth

hookimpl = pluggy.HookimplMarker("tox")


@hookimpl
def tox_testenv_install_deps(venv, action):
venv._install(
[
"keyrings.google-artifactregistry-auth=={}".format(
google_artifactregistry_auth.__version__
)
],
action=action,
)
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools>=46.4.0", "wheel"]
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
license_file = LICENSE
name = keyrings.google-artifactregistry-auth
version = 0.0.2
version = attr: google_artifactregistry_auth.__version__
author = Megan Kuo
author_email = megankuo@google.com
description = Keyring backend for Google Auth tokens
Expand All @@ -23,6 +23,7 @@ install_requires =
keyring
google-auth
requests
pluggy
setup_requires = setuptools_scm[toml] >= 3.4.1

[options.extras_require]
Expand All @@ -40,4 +41,5 @@ testing =
[options.entry_points]
keyring.backends =
Google Auth = keyrings.gauth

tox =
tox_bootstrap = google_artifactregistry_auth.tox_bootstrap
3 changes: 3 additions & 0 deletions tests/tox-plugin/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()
6 changes: 6 additions & 0 deletions tests/tox-plugin/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tox]
envlist = py
requires = keyrings.google-artifactregistry-auth

[testenv]
commands = python -m pip show keyrings.google-artifactregistry-auth