1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
from __future__ import annotations
import sys
from pathlib import Path
from textwrap import dedent
from packaging.version import Version
from tox.config.cli.parser import ToxParser
from tox.plugin import impl
from tox.session.state import State
from tox.version import version as __version__
@impl
def tox_add_option(parser: ToxParser) -> None:
our = parser.add_command(
"quickstart",
["q"],
"Command line script to quickly create a tox config file for a Python project",
quickstart,
)
our.add_argument(
"quickstart_root",
metavar="root",
default=Path().absolute(),
help="folder to create the tox.ini file",
type=Path,
)
def quickstart(state: State) -> int:
root = state.conf.options.quickstart_root.absolute()
tox_ini = root / "tox.ini"
if tox_ini.exists():
print(f"{tox_ini} already exist, refusing to overwrite")
return 1
version = str(Version(__version__.split("+")[0]))
text = f"""
[tox]
env_list =
py{''.join(str(i) for i in sys.version_info[0:2])}
minversion = {version}
[testenv]
description = run the tests with pytest
package = wheel
wheel_build_env = .pkg
deps =
pytest>=6
commands =
pytest {{tty:--color=yes}} {{posargs}}
"""
content = dedent(text).lstrip()
print(f"tox {__version__} quickstart utility, will create {tox_ini}:")
print(content, end="")
root.mkdir(parents=True, exist_ok=True)
tox_ini.write_text(content)
return 0
|