From 6d057470fddb829a4346bc257e543e1d2fe89b47 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 11 Nov 2024 23:42:16 -0500 Subject: [PATCH] chore: limit the visible items for tab completion Signed-off-by: Henry Schreiner --- nox/__init__.py | 10 ++++++++++ nox/__main__.py | 4 ++++ nox/_cli.py | 6 ++++++ nox/_decorators.py | 6 ++++++ nox/_option_set.py | 17 +++++++++++++++-- nox/_options.py | 11 +++++++++-- nox/_parametrize.py | 6 ++++++ nox/_resolver.py | 7 +++++++ nox/_typing.py | 7 ++++++- nox/_version.py | 6 ++++++ nox/command.py | 11 ++++++++--- nox/logger.py | 7 +++++++ nox/manifest.py | 7 +++++++ nox/popen.py | 12 ++++++++++++ nox/registry.py | 7 +++++++ nox/sessions.py | 6 ++++++ nox/tasks.py | 16 ++++++++++++++++ nox/tox_to_nox.py | 8 ++++++++ nox/virtualenv.py | 25 +++++++++++++++++++++++++ nox/workflow.py | 6 ++++++ 20 files changed, 177 insertions(+), 8 deletions(-) diff --git a/nox/__init__.py b/nox/__init__.py index 8121e62a..8d66a755 100644 --- a/nox/__init__.py +++ b/nox/__init__.py @@ -14,6 +14,8 @@ from __future__ import annotations +from types import ModuleType + from nox import project from nox._cli import main from nox._options import noxfile_options as options @@ -34,3 +36,11 @@ "session", "main", ] + + +def __dir__() -> list[str]: + # Only nox modules are imported here, so we can safely use globals() to + # find nox modules only. Other modules, like types and __future__, are imported + # from, so don't populate the module globals with surprising entries. + modules = {k for k, v in globals().items() if isinstance(v, ModuleType)} + return sorted(set(__all__) | modules) diff --git a/nox/__main__.py b/nox/__main__.py index ac183d6a..7a4ee458 100644 --- a/nox/__main__.py +++ b/nox/__main__.py @@ -26,5 +26,9 @@ __all__ = ["main"] # pragma: no cover +def __dir__() -> list[str]: + return __all__ + + if __name__ == "__main__": # pragma: no cover main() diff --git a/nox/_cli.py b/nox/_cli.py index f25dad2a..5ad09615 100644 --- a/nox/_cli.py +++ b/nox/_cli.py @@ -23,6 +23,12 @@ from nox._version import get_nox_version from nox.logger import setup_logging +__all__ = ["main", "execute_workflow"] + + +def __dir__() -> list[str]: + return __all__ + def execute_workflow(args: Any) -> int: """ diff --git a/nox/_decorators.py b/nox/_decorators.py index 62db1452..aad2d212 100644 --- a/nox/_decorators.py +++ b/nox/_decorators.py @@ -28,6 +28,12 @@ T = TypeVar("T", bound=Callable[..., Any]) +__all__ = ["Func", "Call", "FunctionDecorator", "_copy_func"] + + +def __dir__() -> list[str]: + return __all__ + class FunctionDecorator: """This is a function decorator.""" diff --git a/nox/_option_set.py b/nox/_option_set.py index 573da600..67796882 100644 --- a/nox/_option_set.py +++ b/nox/_option_set.py @@ -21,8 +21,7 @@ import argparse import collections import functools -from argparse import ArgumentError as ArgumentError # noqa: PLC0414 -from argparse import ArgumentParser, Namespace +from argparse import ArgumentError, ArgumentParser, Namespace from collections.abc import Callable, Iterable from typing import Any, Literal @@ -30,6 +29,20 @@ import attrs import attrs.validators as av +__all__ = [ + "ArgumentError", + "NoxOptions", + "Option", + "OptionGroup", + "OptionSet", + "make_flag_pair", +] + + +def __dir__() -> list[str]: + return __all__ + + av_opt_str = av.optional(av.instance_of(str)) av_opt_list_str = av.optional( av.deep_iterable( diff --git a/nox/_options.py b/nox/_options.py index 2dc26f21..4d00c7d8 100644 --- a/nox/_options.py +++ b/nox/_options.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""All of Nox's configuration options.""" + from __future__ import annotations import argparse @@ -29,9 +31,14 @@ from nox.tasks import discover_manifest, filter_manifest, load_nox_module from nox.virtualenv import ALL_VENVS -ReuseVenvType = Literal["no", "yes", "never", "always"] +__all__ = ["options", "noxfile_options", "ReuseVenvType"] -"""All of Nox's configuration options.""" + +def __dir__() -> list[str]: + return __all__ + + +ReuseVenvType = Literal["no", "yes", "never", "always"] options = _option_set.OptionSet( description="Nox is a Python automation toolkit.", add_help=False diff --git a/nox/_parametrize.py b/nox/_parametrize.py index 281607fc..4feb0afd 100644 --- a/nox/_parametrize.py +++ b/nox/_parametrize.py @@ -19,6 +19,12 @@ from collections.abc import Callable, Sequence from typing import Any, Iterable, Union +__all__ = ["Param", "parametrize_decorator", "update_param_specs"] + + +def __dir__() -> list[str]: + return __all__ + class Param: """A class that encapsulates a single set of parameters to a parametrized diff --git a/nox/_resolver.py b/nox/_resolver.py index c5c2a8e5..5df8f760 100644 --- a/nox/_resolver.py +++ b/nox/_resolver.py @@ -18,6 +18,13 @@ from collections import OrderedDict from typing import Hashable, Iterable, Iterator, Mapping, TypeVar +__all__ = ["CycleError", "lazy_stable_topo_sort"] + + +def __dir__() -> list[str]: + return __all__ + + Node = TypeVar("Node", bound=Hashable) diff --git a/nox/_typing.py b/nox/_typing.py index ac2d5ca8..12af780e 100644 --- a/nox/_typing.py +++ b/nox/_typing.py @@ -14,8 +14,13 @@ from __future__ import annotations +from typing import Sequence, Union + __all__ = ["Python"] -from typing import Sequence, Union + +def __dir__() -> list[str]: + return __all__ + Python = Union[str, Sequence[str], bool, None] diff --git a/nox/_version.py b/nox/_version.py index 3d1026d3..a8125109 100644 --- a/nox/_version.py +++ b/nox/_version.py @@ -21,6 +21,12 @@ from packaging.specifiers import InvalidSpecifier, SpecifierSet from packaging.version import InvalidVersion, Version +__all__ = ["check_nox_version", "VersionCheckFailed", "InvalidVersionSpecifier"] + + +def __dir__() -> list[str]: + return __all__ + class VersionCheckFailed(Exception): """The Nox version does not satisfy what ``nox.needs_version`` specifies.""" diff --git a/nox/command.py b/nox/command.py index ce8f0271..e42dbfd5 100644 --- a/nox/command.py +++ b/nox/command.py @@ -20,16 +20,21 @@ import subprocess import sys from collections.abc import Iterable, Mapping, Sequence -from typing import Literal +from typing import TYPE_CHECKING, Literal from nox.logger import logger from nox.popen import DEFAULT_INTERRUPT_TIMEOUT, DEFAULT_TERMINATE_TIMEOUT, popen -TYPE_CHECKING = False - if TYPE_CHECKING: from typing import IO +__all__ = ["CommandFailed", "run", "which", "ExternalType"] + + +def __dir__() -> list[str]: + return __all__ + + ExternalType = Literal["error", True, False] diff --git a/nox/logger.py b/nox/logger.py index e3ecf650..74c89e24 100644 --- a/nox/logger.py +++ b/nox/logger.py @@ -19,6 +19,13 @@ from colorlog import ColoredFormatter +__all__ = ["logger", "setup_logging", "SUCCESS", "OUTPUT"] + + +def __dir__() -> list[str]: + return __all__ + + SUCCESS = 25 OUTPUT = logging.DEBUG - 1 diff --git a/nox/manifest.py b/nox/manifest.py index 0fb8ea37..b92b996d 100644 --- a/nox/manifest.py +++ b/nox/manifest.py @@ -26,6 +26,13 @@ from nox._resolver import CycleError, lazy_stable_topo_sort from nox.sessions import Session, SessionRunner +__all__ = ["Manifest", "keyword_match", "WARN_PYTHONS_IGNORED"] + + +def __dir__() -> list[str]: + return __all__ + + WARN_PYTHONS_IGNORED = "python_ignored" diff --git a/nox/popen.py b/nox/popen.py index 5f32a9e9..0b2510f1 100644 --- a/nox/popen.py +++ b/nox/popen.py @@ -21,6 +21,18 @@ from collections.abc import Mapping, Sequence from typing import IO +__all__ = [ + "popen", + "decode_output", + "DEFAULT_INTERRUPT_TIMEOUT", + "DEFAULT_TERMINATE_TIMEOUT", +] + + +def __dir__() -> list[str]: + return __all__ + + DEFAULT_INTERRUPT_TIMEOUT = 0.3 DEFAULT_TERMINATE_TIMEOUT = 0.2 diff --git a/nox/registry.py b/nox/registry.py index db3db9fb..85a00008 100644 --- a/nox/registry.py +++ b/nox/registry.py @@ -23,6 +23,13 @@ from ._decorators import Func from ._typing import Python +__all__ = ["session_decorator", "get"] + + +def __dir__() -> list[str]: + return __all__ + + F = TypeVar("F", bound=Callable[..., Any]) _REGISTRY: collections.OrderedDict[str, Func] = collections.OrderedDict() diff --git a/nox/sessions.py b/nox/sessions.py index f7819c51..d3280278 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -59,6 +59,12 @@ from nox.command import ExternalType from nox.manifest import Manifest +__all__ = ["Session", "Status", "nox", "SessionRunner", "Result"] + + +def __dir__() -> list[str]: + return __all__ + @contextlib.contextmanager def _chdir(path: str) -> Generator[None, None, None]: diff --git a/nox/tasks.py b/nox/tasks.py index 62bee9b5..b2456e51 100644 --- a/nox/tasks.py +++ b/nox/tasks.py @@ -33,6 +33,22 @@ from nox.manifest import WARN_PYTHONS_IGNORED, Manifest from nox.sessions import Result +__all__ = [ + "create_report", + "discover_manifest", + "filter_manifest", + "final_reduce", + "honor_list_request", + "load_nox_module", + "merge_noxfile_options", + "print_summary", + "run_manifest", +] + + +def __dir__() -> list[str]: + return __all__ + def _load_and_exec_nox_module(global_config: Namespace) -> types.ModuleType: """ diff --git a/nox/tox_to_nox.py b/nox/tox_to_nox.py index 34eeaf9e..0912f5ed 100644 --- a/nox/tox_to_nox.py +++ b/nox/tox_to_nox.py @@ -34,6 +34,14 @@ else: from importlib.resources import files + +__all__ = ["main"] + + +def __dir__() -> list[str]: + return __all__ + + TOX_VERSION = metadata.version("tox") TOX4 = int(TOX_VERSION.split(".")[0]) >= 4 diff --git a/nox/virtualenv.py b/nox/virtualenv.py index 8b9525c6..e943298f 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -36,6 +36,31 @@ from nox._typing import Python from nox.logger import logger +__all__ = [ + "find_uv", + "uv_version", + "uv_install_python", + "get_virtualenv", + "HAS_UV", + "UV", + "UV_PYTHON_SUPPORT", + "InterpreterNotFound", + "ProcessEnv", + "PassthroughEnv", + "CondaEnv", + "VirtualEnv", + "ALL_VENVS", + "OPTIONAL_VENVS", + "get_virtualenv", + "uv_version", + "uv_install_python", +] + + +def __dir__() -> list[str]: + return __all__ + + # Problematic environment variables that are stripped from all commands inside # of a virtualenv. See https://github.com/theacodes/nox/issues/44 _BLACKLISTED_ENV_VARS = frozenset( diff --git a/nox/workflow.py b/nox/workflow.py index 3b653257..175543e9 100644 --- a/nox/workflow.py +++ b/nox/workflow.py @@ -18,6 +18,12 @@ from collections.abc import Callable, Iterable from typing import Any +__all__ = ["execute"] + + +def __dir__() -> list[str]: + return __all__ + def execute( workflow: Iterable[Callable[..., Any]], global_config: argparse.Namespace