Skip to content

Commit

Permalink
chore: limit the visible items for tab completion
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 12, 2024
1 parent 2c43214 commit 5d2c843
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 8 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 @@
"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)
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__ = ["main", "execute_workflow"]


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__ = ["Func", "Call", "FunctionDecorator", "_copy_func"]


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


class FunctionDecorator:
"""This is a function decorator."""
Expand Down
16 changes: 14 additions & 2 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@
import collections
import dataclasses
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

import argcomplete

__all__ = [
"ArgumentError",
"NoxOptions",
"Option",
"OptionGroup",
"OptionSet",
"make_flag_pair",
]


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


# Python 3.10+ has slots=True (or attrs does), also kwonly=True
@dataclasses.dataclass
Expand Down
11 changes: 9 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 @@ -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
Expand Down
6 changes: 6 additions & 0 deletions nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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__ = ["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."""
Expand Down
11 changes: 8 additions & 3 deletions nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


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__ = ["logger", "setup_logging", "SUCCESS", "OUTPUT"]


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 @@ -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"


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

Expand Down
7 changes: 7 additions & 0 deletions nox/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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__ = ["Session", "Status", "nox", "SessionRunner", "Result"]


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 @@ -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:
"""
Expand Down
7 changes: 7 additions & 0 deletions nox/tox_to_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
import jinja2
import tox.config

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

0 comments on commit 5d2c843

Please sign in to comment.