Skip to content

Commit

Permalink
remove Sequence aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Feb 11, 2024
1 parent 1e38962 commit 26d724e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
5 changes: 2 additions & 3 deletions copier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from os import PathLike
from pathlib import Path
from textwrap import dedent
from typing import Any, Callable
from typing import Any, Callable, Sequence

import yaml
from plumbum import cli, colors
Expand All @@ -63,7 +63,6 @@
from .errors import UnsafeTemplateError, UserMessageError
from .main import Worker
from .tools import copier_version
from .types import StrSeq

P = ParamSpec("P")

Expand Down Expand Up @@ -169,7 +168,7 @@ def __init__(self, executable: PathLike) -> None:
list=True,
help="Make VARIABLE available as VALUE when rendering the template",
)
def data_switch(self, values: StrSeq) -> None:
def data_switch(self, values: Sequence[str]) -> None:
"""Update [data][] with provided values.
Arguments:
Expand Down
3 changes: 1 addition & 2 deletions copier/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING, Sequence

from .tools import printf_exception
from .types import PathSeq

if TYPE_CHECKING: # always false
from .template import Template
Expand Down Expand Up @@ -41,7 +40,7 @@ def __init__(self, conf_path: Path, quiet: bool):
class MultipleConfigFilesError(ConfigFileError):
"""Both copier.yml and copier.yaml found, and that's an error."""

def __init__(self, conf_paths: PathSeq):
def __init__(self, conf_paths: Sequence[Path]):
msg = str(conf_paths)
printf_exception(self, "MULTIPLE CONFIG FILES", msg=msg)
super().__init__(msg)
Expand Down
8 changes: 4 additions & 4 deletions copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from .subproject import Subproject
from .template import Task, Template
from .tools import OS, Style, normalize_git_path, printf, readlink
from .types import MISSING, JSONSerializable, RelativePath, StrSeq
from .types import MISSING, JSONSerializable, RelativePath
from .user_data import DEFAULT_DATA, AnswersMap, Question
from .vcs import get_git

Expand Down Expand Up @@ -156,9 +156,9 @@ class Worker:
answers_file: RelativePath | None = None
vcs_ref: str | None = None
data: dict[str, Any] = field(default_factory=dict)
exclude: StrSeq = ()
exclude: Sequence[str] = ()
use_prereleases: bool = False
skip_if_exists: StrSeq = ()
skip_if_exists: Sequence[str] = ()
cleanup_on_error: bool = True
defaults: bool = False
user_defaults: dict[str, Any] = field(default_factory=dict)
Expand Down Expand Up @@ -458,7 +458,7 @@ def answers_relpath(self) -> Path:
return Path(template.render(**self.answers.combined))

@cached_property
def all_exclusions(self) -> StrSeq:
def all_exclusions(self) -> Sequence[str]:
"""Combine default, template and user-chosen exclusions."""
return self.template.exclude + tuple(self.exclude)

Expand Down
4 changes: 2 additions & 2 deletions copier/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
UnsupportedVersionError,
)
from .tools import copier_version, handle_remove_readonly
from .types import Env, StrSeq, VCSTypes
from .types import Env, VCSTypes
from .vcs import checkout_latest_tag, clone, get_git, get_repo

# Default list of files in the template to exclude from the rendered project
Expand Down Expand Up @@ -423,7 +423,7 @@ def secret_questions(self) -> set[str]:
return result

@cached_property
def skip_if_exists(self) -> StrSeq:
def skip_if_exists(self) -> Sequence[str]:
"""Get skip patterns from the template.
These files will never be rewritten when rendering the template.
Expand Down
16 changes: 7 additions & 9 deletions copier/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@
from importlib.metadata import version
from pathlib import Path
from types import TracebackType
from typing import Any, Callable, Literal, TextIO, cast
from typing import Any, Callable, Literal, Sequence, TextIO, cast

import colorama
from packaging.version import Version
from pydantic import StrictBool

from .types import IntSeq

colorama.just_fix_windows_console()


class Style:
"""Common color styles."""

OK: IntSeq = [colorama.Fore.GREEN, colorama.Style.BRIGHT]
WARNING: IntSeq = [colorama.Fore.YELLOW, colorama.Style.BRIGHT]
IGNORE: IntSeq = [colorama.Fore.CYAN]
DANGER: IntSeq = [colorama.Fore.RED, colorama.Style.BRIGHT]
RESET: IntSeq = [colorama.Fore.RESET, colorama.Style.RESET_ALL]
OK: Sequence[int] = [colorama.Fore.GREEN, colorama.Style.BRIGHT]
WARNING: Sequence[int] = [colorama.Fore.YELLOW, colorama.Style.BRIGHT]
IGNORE: Sequence[int] = [colorama.Fore.CYAN]
DANGER: Sequence[int] = [colorama.Fore.RED, colorama.Style.BRIGHT]
RESET: Sequence[int] = [colorama.Fore.RESET, colorama.Style.RESET_ALL]


INDENT = " " * 2
Expand Down Expand Up @@ -64,7 +62,7 @@ def copier_version() -> Version:
def printf(
action: str,
msg: Any = "",
style: IntSeq | None = None,
style: Sequence[int] | None = None,
indent: int = 10,
quiet: bool | StrictBool = False,
file_: TextIO = sys.stdout,
Expand Down
7 changes: 1 addition & 6 deletions copier/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys
from pathlib import Path
from typing import Literal, Mapping, NewType, Sequence, TypeVar
from typing import Literal, Mapping, NewType, TypeVar

from pydantic import AfterValidator

Expand All @@ -13,11 +13,6 @@
else:
from typing_extensions import Annotated

# sequences
IntSeq = Sequence[int]
StrSeq = Sequence[str]
PathSeq = Sequence[Path]

# miscellaneous
T = TypeVar("T")
JSONSerializable = (dict, list, str, int, float, bool, type(None))
Expand Down

0 comments on commit 26d724e

Please sign in to comment.