|
1 | 1 | """Tox hook implementations.""" |
2 | 2 | from __future__ import print_function |
| 3 | + |
3 | 4 | import os |
4 | | -import sys |
| 5 | + |
5 | 6 | import tox |
6 | 7 |
|
7 | 8 | try: |
@@ -39,6 +40,18 @@ def tox_addoption(parser): |
39 | 40 | help="Prepend OS type to factors, such as linux, macos, windows.", |
40 | 41 | ) |
41 | 42 |
|
| 43 | + parser.add_argument( |
| 44 | + "--prepend-username-factor", |
| 45 | + action="store_true", |
| 46 | + help="Prepend username to factors.", |
| 47 | + ) |
| 48 | + |
| 49 | + parser.add_argument( |
| 50 | + "--add-ci-factor", |
| 51 | + action="store_true", |
| 52 | + help="Add CI factors if environment variable is set, such as appveyor, travis or fallback ci.", |
| 53 | + ) |
| 54 | + |
42 | 55 |
|
43 | 56 | @tox.hookimpl(trylast=True) |
44 | 57 | def tox_configure(config): |
@@ -76,6 +89,33 @@ def tox_configure(config): |
76 | 89 | else: |
77 | 90 | config.option.prepend_factor.insert(0, _get_os_type().lower()) |
78 | 91 |
|
| 92 | + if config.option.add_ci_factor and "CI" in os.environ: |
| 93 | + extra_factor = None |
| 94 | + if "APPVEYOR" in os.environ or "TRAVIS" in os.environ: |
| 95 | + config.option.prepend_username_factor = True |
| 96 | + elif "CIRRUS_CI" in os.environ: |
| 97 | + extra_factor = "cirrusci" |
| 98 | + else: |
| 99 | + extra_factor = "ci" |
| 100 | + |
| 101 | + if extra_factor: |
| 102 | + if not config.option.append_factor: |
| 103 | + config.option.append_factor = [extra_factor] |
| 104 | + else: |
| 105 | + config.option.append_factor.insert(0, extra_factor) |
| 106 | + |
| 107 | + if config.option.prepend_username_factor: |
| 108 | + import getpass # noqa |
| 109 | + |
| 110 | + username = getpass.getuser() |
| 111 | + if username: |
| 112 | + username = username.lower() |
| 113 | + |
| 114 | + if not config.option.prepend_factor: |
| 115 | + config.option.prepend_factor = [username] |
| 116 | + else: |
| 117 | + config.option.prepend_factor.insert(0, username) |
| 118 | + |
79 | 119 | if config.option.prepend_factor: |
80 | 120 | add_factors(config, config.option.prepend_factor, position=BEFORE) |
81 | 121 | if config.option.append_factor: |
|
0 commit comments