1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2025-11-23 18:58:58 +01:00

Add --print-deps-to-file option for easier parsable dependencies

Fixes https://github.com/fedora-python/tox-current-env/issues/13
This commit is contained in:
Miro Hrončok
2019-08-01 12:39:12 +02:00
parent 6b2fe8ea56
commit 71d21b8266
3 changed files with 62 additions and 5 deletions

View File

@@ -20,11 +20,23 @@ def tox_addoption(parser):
default=False,
help="Don't run tests, only print the dependencies",
)
parser.add_argument(
"--print-deps-to-file",
action="store",
dest="print_deps_path",
metavar="PATH",
default=None,
help="Like --print-deps-only, but to a file (overrides the file)",
)
@tox.hookimpl
def tox_configure(config):
"""Stores options in the config. Makes all commands external and skips sdist"""
if config.option.print_deps_path is not None:
config.option.print_deps_only = True
with open(config.option.print_deps_path, "w", encoding="utf-8") as f:
f.write("")
if config.option.current_env or config.option.print_deps_only:
config.skipsdist = True
for testenv in config.envconfigs:
@@ -136,7 +148,10 @@ def tox_runtest(venv, redirect):
"""If --print-deps-only, prints deps instead of running tests"""
config = venv.envconfig.config
unsupported_raise(config, venv)
if config.option.print_deps_only:
for dependency in venv.get_resolved_dependencies():
print(dependency)
if config.option.print_deps_path is not None:
with open(config.option.print_deps_path, "a", encoding="utf-8") as f:
print(*venv.get_resolved_dependencies(), sep="\n", file=f)
return True
if config.option.print_deps_only:
print(*venv.get_resolved_dependencies(), sep="\n")
return True