Skip to content

Commit

Permalink
Group CLI arguments in functional groups (#305) (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrGFreeman authored Jun 11, 2021
1 parent 24fc263 commit 0fb841d
Showing 1 changed file with 54 additions and 34 deletions.
88 changes: 54 additions & 34 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,34 @@

options.add_groups(
_option_set.OptionGroup(
"primary",
"Primary arguments",
"These are the most common arguments used when invoking Nox.",
"general",
"General options",
"These are general arguments used when invoking Nox.",
),
_option_set.OptionGroup(
"secondary",
"Additional arguments & flags",
"These arguments are used to control Nox's behavior or control advanced features.",
"sessions",
"Sessions options",
"These arguments are used to control which Nox session(s) to execute.",
),
_option_set.OptionGroup(
"python",
"Python options",
"These arguments are used to control which Python version(s) to use.",
),
_option_set.OptionGroup(
"environment",
"Environment options",
"These arguments are used to control Nox's creation and usage of virtual environments.",
),
_option_set.OptionGroup(
"execution",
"Execution options",
"These arguments are used to control execution of sessions.",
),
_option_set.OptionGroup(
"reporting",
"Reporting options",
"These arguments are used to control Nox's reporting during execution.",
),
)

Expand Down Expand Up @@ -209,14 +229,14 @@ def _session_completer(
"help",
"-h",
"--help",
group=options.groups["primary"],
group=options.groups["general"],
action="store_true",
help="Show this help message and exit.",
),
_option_set.Option(
"version",
"--version",
group=options.groups["primary"],
group=options.groups["general"],
action="store_true",
help="Show the Nox version and exit.",
),
Expand All @@ -225,7 +245,7 @@ def _session_completer(
"-l",
"--list-sessions",
"--list",
group=options.groups["primary"],
group=options.groups["sessions"],
action="store_true",
help="List all available sessions and exit.",
),
Expand All @@ -235,7 +255,7 @@ def _session_completer(
"-e",
"--sessions",
"--session",
group=options.groups["primary"],
group=options.groups["sessions"],
noxfile=True,
merge_func=functools.partial(_sessions_and_keywords_merge_func, "sessions"),
nargs="*",
Expand All @@ -248,7 +268,7 @@ def _session_completer(
"-p",
"--pythons",
"--python",
group=options.groups["primary"],
group=options.groups["python"],
noxfile=True,
nargs="*",
help="Only run sessions that use the given python interpreter versions.",
Expand All @@ -257,15 +277,15 @@ def _session_completer(
"keywords",
"-k",
"--keywords",
group=options.groups["primary"],
group=options.groups["sessions"],
noxfile=True,
merge_func=functools.partial(_sessions_and_keywords_merge_func, "keywords"),
help="Only run sessions that match the given expression.",
),
_option_set.Option(
"posargs",
"posargs",
group=options.groups["primary"],
group=options.groups["general"],
nargs=argparse.REMAINDER,
help="Arguments following ``--`` that are passed through to the session(s).",
finalizer_func=_posargs_finalizer,
Expand All @@ -274,7 +294,7 @@ def _session_completer(
"verbose",
"-v",
"--verbose",
group=options.groups["secondary"],
group=options.groups["reporting"],
action="store_true",
help="Logs the output of all commands run including commands marked silent.",
noxfile=True,
Expand All @@ -283,7 +303,7 @@ def _session_completer(
"add_timestamp",
"-ts",
"--add-timestamp",
group=options.groups["secondary"],
group=options.groups["reporting"],
action="store_true",
help="Adds a timestamp to logged output.",
noxfile=True,
Expand All @@ -292,7 +312,7 @@ def _session_completer(
"default_venv_backend",
"-db",
"--default-venv-backend",
group=options.groups["secondary"],
group=options.groups["environment"],
noxfile=True,
merge_func=_default_venv_backend_merge_func,
help="Virtual environment backend to use by default for nox sessions, this is ``'virtualenv'`` by default but "
Expand All @@ -303,7 +323,7 @@ def _session_completer(
"force_venv_backend",
"-fb",
"--force-venv-backend",
group=options.groups["secondary"],
group=options.groups["environment"],
noxfile=True,
merge_func=_force_venv_backend_merge_func,
help="Virtual environment backend to force-use for all nox sessions in this run, overriding any other venv "
Expand All @@ -314,7 +334,7 @@ def _session_completer(
_option_set.Option(
"no_venv",
"--no-venv",
group=options.groups["secondary"],
group=options.groups["environment"],
default=False,
action="store_true",
help="Runs the selected sessions directly on the current interpreter, without creating a venv. This is an alias "
Expand All @@ -324,14 +344,14 @@ def _session_completer(
"reuse_existing_virtualenvs",
("-r", "--reuse-existing-virtualenvs"),
("--no-reuse-existing-virtualenvs",),
group=options.groups["secondary"],
group=options.groups["environment"],
help="Re-use existing virtualenvs instead of recreating them.",
),
_option_set.Option(
"R",
"-R",
default=False,
group=options.groups["secondary"],
group=options.groups["environment"],
action="store_true",
help=(
"Re-use existing virtualenvs and skip package re-installation."
Expand All @@ -343,7 +363,7 @@ def _session_completer(
"noxfile",
"-f",
"--noxfile",
group=options.groups["secondary"],
group=options.groups["general"],
default="noxfile.py",
help="Location of the Python file containing nox sessions.",
),
Expand All @@ -352,22 +372,22 @@ def _session_completer(
"--envdir",
noxfile=True,
merge_func=_envdir_merge_func,
group=options.groups["secondary"],
group=options.groups["environment"],
help="Directory where nox will store virtualenvs, this is ``.nox`` by default.",
),
_option_set.Option(
"extra_pythons",
"--extra-pythons",
"--extra-python",
group=options.groups["secondary"],
group=options.groups["python"],
nargs="*",
help="Additionally, run sessions using the given python interpreter versions.",
),
_option_set.Option(
"force_pythons",
"--force-pythons",
"--force-python",
group=options.groups["secondary"],
group=options.groups["python"],
nargs="*",
help=(
"Run sessions with the given interpreters instead of those listed in the Noxfile."
Expand All @@ -379,35 +399,35 @@ def _session_completer(
"stop_on_first_error",
("-x", "--stop-on-first-error"),
("--no-stop-on-first-error",),
group=options.groups["secondary"],
group=options.groups["execution"],
help="Stop after the first error.",
),
*_option_set.make_flag_pair(
"error_on_missing_interpreters",
("--error-on-missing-interpreters",),
("--no-error-on-missing-interpreters",),
group=options.groups["secondary"],
group=options.groups["execution"],
help="Error instead of skipping sessions if an interpreter can not be located.",
),
*_option_set.make_flag_pair(
"error_on_external_run",
("--error-on-external-run",),
("--no-error-on-external-run",),
group=options.groups["secondary"],
group=options.groups["execution"],
help="Error if run() is used to execute a program that isn't installed in a session's virtualenv.",
),
_option_set.Option(
"install_only",
"--install-only",
group=options.groups["secondary"],
group=options.groups["execution"],
action="store_true",
help="Skip session.run invocations in the Noxfile.",
),
_option_set.Option(
"no_install",
"--no-install",
default=False,
group=options.groups["secondary"],
group=options.groups["execution"],
action="store_true",
help=(
"Skip invocations of session methods for installing packages"
Expand All @@ -418,22 +438,22 @@ def _session_completer(
_option_set.Option(
"report",
"--report",
group=options.groups["secondary"],
group=options.groups["reporting"],
noxfile=True,
help="Output a report of all sessions to the given filename.",
),
_option_set.Option(
"non_interactive",
"--non-interactive",
group=options.groups["secondary"],
group=options.groups["execution"],
action="store_true",
help="Force session.interactive to always be False, even in interactive sessions.",
),
_option_set.Option(
"nocolor",
"--nocolor",
"--no-color",
group=options.groups["secondary"],
group=options.groups["reporting"],
default=lambda: "NO_COLOR" in os.environ,
action="store_true",
help="Disable all color output.",
Expand All @@ -442,15 +462,15 @@ def _session_completer(
"forcecolor",
"--forcecolor",
"--force-color",
group=options.groups["secondary"],
group=options.groups["reporting"],
default=False,
action="store_true",
help="Force color output, even if stdout is not an interactive terminal.",
),
_option_set.Option(
"color",
"--color",
group=options.groups["secondary"],
group=options.groups["reporting"],
hidden=True,
finalizer_func=_color_finalizer,
),
Expand Down

0 comments on commit 0fb841d

Please sign in to comment.