Skip to content

Commit

Permalink
chore: limit the visible items for tab completion (#889)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Dec 13, 2024
1 parent 5f36a5b commit ea95a1e
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 5 deletions.
10 changes: 10 additions & 0 deletions nox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,3 +36,11 @@
"project",
"session",
]


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)
4 changes: 4 additions & 0 deletions nox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
__all__ = ["main"] # pragma: no cover


def __dir__() -> list[str]:
return __all__


if __name__ == "__main__": # pragma: no cover
main()
6 changes: 6 additions & 0 deletions nox/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
from nox._version import get_nox_version
from nox.logger import setup_logging

__all__ = ["execute_workflow", "main"]


def __dir__() -> list[str]:
return __all__


def execute_workflow(args: Any) -> int:
"""
Expand Down
6 changes: 6 additions & 0 deletions nox/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

T = TypeVar("T", bound=Callable[..., Any])

__all__ = ["Call", "Func", "FunctionDecorator", "_copy_func"]


def __dir__() -> list[str]:
return __all__


class FunctionDecorator:
"""This is a function decorator."""
Expand Down
18 changes: 16 additions & 2 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
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 TYPE_CHECKING, Any, Literal

import argcomplete
Expand All @@ -32,6 +32,20 @@
if TYPE_CHECKING:
from collections.abc import Callable, Iterable

__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(
Expand Down
12 changes: 10 additions & 2 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,9 +34,15 @@

from nox._option_set import NoxOptions

ReuseVenvType = Literal["no", "yes", "never", "always"]

"""All of Nox's configuration options."""
__all__ = ["ReuseVenvType", "noxfile_options", "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
Expand Down
6 changes: 6 additions & 0 deletions nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
if TYPE_CHECKING:
from collections.abc import Callable, Sequence

__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
Expand Down
7 changes: 7 additions & 0 deletions nox/_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 6 additions & 1 deletion nox/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
6 changes: 6 additions & 0 deletions nox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import InvalidVersion, Version

__all__ = ["InvalidVersionSpecifier", "VersionCheckFailed", "check_nox_version"]


def __dir__() -> list[str]:
return __all__


class VersionCheckFailed(Exception):
"""The Nox version does not satisfy what ``nox.needs_version`` specifies."""
Expand Down
7 changes: 7 additions & 0 deletions nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
from collections.abc import Iterable, Mapping, Sequence
from typing import IO

__all__ = ["CommandFailed", "ExternalType", "run", "which"]


def __dir__() -> list[str]:
return __all__


ExternalType = Literal["error", True, False]


Expand Down
7 changes: 7 additions & 0 deletions nox/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

from colorlog import ColoredFormatter

__all__ = ["OUTPUT", "SUCCESS", "logger", "setup_logging"]


def __dir__() -> list[str]:
return __all__


SUCCESS = 25
OUTPUT = logging.DEBUG - 1

Expand Down
7 changes: 7 additions & 0 deletions nox/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import argparse
from collections.abc import Iterable, Iterator, Sequence

__all__ = ["WARN_PYTHONS_IGNORED", "Manifest", "keyword_match"]


def __dir__() -> list[str]:
return __all__


WARN_PYTHONS_IGNORED = "python_ignored"


Expand Down
12 changes: 12 additions & 0 deletions nox/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
if TYPE_CHECKING:
from collections.abc import Mapping, Sequence

__all__ = [
"DEFAULT_INTERRUPT_TIMEOUT",
"DEFAULT_TERMINATE_TIMEOUT",
"decode_output",
"popen",
]


def __dir__() -> list[str]:
return __all__


DEFAULT_INTERRUPT_TIMEOUT = 0.3
DEFAULT_TERMINATE_TIMEOUT = 0.2

Expand Down
7 changes: 7 additions & 0 deletions nox/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@

from ._typing import Python

__all__ = ["get", "session_decorator"]


def __dir__() -> list[str]:
return __all__


RawFunc = Callable[..., Any]

_REGISTRY: collections.OrderedDict[str, Func] = collections.OrderedDict()
Expand Down
6 changes: 6 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
from nox.command import ExternalType
from nox.manifest import Manifest

__all__ = ["Result", "Session", "SessionRunner", "Status", "nox"]


def __dir__() -> list[str]:
return __all__


@contextlib.contextmanager
def _chdir(path: str) -> Generator[None, None, None]:
Expand Down
16 changes: 16 additions & 0 deletions nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
import types
from argparse import Namespace

__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:
"""
Expand Down
8 changes: 8 additions & 0 deletions nox/tox_to_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@

from nox._typing import Python

__all__ = [
"ALL_VENVS",
"HAS_UV",
"OPTIONAL_VENVS",
"UV",
"UV_PYTHON_SUPPORT",
"CondaEnv",
"InterpreterNotFound",
"PassthroughEnv",
"ProcessEnv",
"VirtualEnv",
"find_uv",
"get_virtualenv",
"get_virtualenv",
"uv_install_python",
"uv_install_python",
"uv_version",
"uv_version",
]


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(
Expand Down
6 changes: 6 additions & 0 deletions nox/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import argparse
from collections.abc import Callable, Iterable

__all__ = ["execute"]


def __dir__() -> list[str]:
return __all__


def execute(
workflow: Iterable[Callable[..., Any]], global_config: argparse.Namespace
Expand Down

0 comments on commit ea95a1e

Please sign in to comment.