From c2884b90665ebc4e633d266c95c3d49f55940821 Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 18 Mar 2024 07:59:41 +0000 Subject: [PATCH 1/3] style: enable more ruff lints --- copier/__init__.py | 2 +- copier/main.py | 6 ++-- copier/template.py | 2 +- copier/tools.py | 23 ++++++++------- copier/user_data.py | 4 +-- copier/vcs.py | 17 +++++------ devtasks.py | 3 +- pyproject.toml | 6 ++++ tests/test_complex_questions.py | 19 ++++-------- tests/test_conditional_file_name.py | 4 +-- tests/test_config.py | 8 ++--- tests/test_interrupts.py | 7 +++-- tests/test_output.py | 30 +++++++++---------- tests/test_prompt.py | 46 +++++++++++------------------ tests/test_templated_prompt.py | 4 +-- tests/test_unsafe.py | 9 ++---- tests/test_updatediff.py | 4 +-- 17 files changed, 88 insertions(+), 106 deletions(-) diff --git a/copier/__init__.py b/copier/__init__.py index 664a838fb..80e92eb7f 100644 --- a/copier/__init__.py +++ b/copier/__init__.py @@ -3,7 +3,7 @@ Docs: https://copier.readthedocs.io/ """ -from .main import * # noqa: F401,F403 +from .main import * # noqa: F403 # This version is a placeholder autoupdated by poetry-dynamic-versioning __version__ = "0.0.0" diff --git a/copier/main.py b/copier/main.py index 3aad6b25c..bee200c12 100644 --- a/copier/main.py +++ b/copier/main.py @@ -747,7 +747,7 @@ def run_copy(self) -> None: self._render_folder(src_abspath) if not self.quiet: # TODO Unify printing tools - print("") # padding space + print() # padding space self._execute_tasks(self.template.tasks) except Exception: if not was_existing and self.cleanup_on_error: @@ -756,7 +756,7 @@ def run_copy(self) -> None: self._print_message(self.template.message_after_copy) if not self.quiet: # TODO Unify printing tools - print("") # padding space + print() # padding space def run_recopy(self) -> None: """Update a subproject, keeping answers but discarding evolution.""" @@ -818,7 +818,7 @@ def run_update(self) -> None: self._apply_update() self._print_message(self.template.message_after_update) - def _apply_update(self): # noqa: C901 + def _apply_update(self): git = get_git() subproject_top = Path( git( diff --git a/copier/template.py b/copier/template.py index 1a90660b7..c489db57d 100644 --- a/copier/template.py +++ b/copier/template.py @@ -243,7 +243,7 @@ def _raw_config(self) -> AnyByStrDict: conf_paths = [ p for p in self.local_abspath.glob("copier.*") - if p.is_file() and re.match(r"\.ya?ml", p.suffix, re.I) + if p.is_file() and re.match(r"\.ya?ml", p.suffix, re.IGNORECASE) ] if len(conf_paths) > 1: raise MultipleConfigFilesError(conf_paths) diff --git a/copier/tools.py b/copier/tools.py index f4eb61c65..1a359c16c 100644 --- a/copier/tools.py +++ b/copier/tools.py @@ -1,4 +1,5 @@ """Some utility functions.""" + from __future__ import annotations import errno @@ -13,7 +14,7 @@ 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, ClassVar, Literal, TextIO, cast import colorama from packaging.version import Version @@ -27,11 +28,11 @@ 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: ClassVar[IntSeq] = [colorama.Fore.GREEN, colorama.Style.BRIGHT] + WARNING: ClassVar[IntSeq] = [colorama.Fore.YELLOW, colorama.Style.BRIGHT] + IGNORE: ClassVar[IntSeq] = [colorama.Fore.CYAN] + DANGER: ClassVar[IntSeq] = [colorama.Fore.RED, colorama.Style.BRIGHT] + RESET: ClassVar[IntSeq] = [colorama.Fore.RESET, colorama.Style.RESET_ALL] INDENT = " " * 2 @@ -64,22 +65,22 @@ def copier_version() -> Version: def printf( action: str, msg: Any = "", - style: IntSeq | None = None, + style: list[str] | None = None, indent: int = 10, quiet: bool | StrictBool = False, file_: TextIO = sys.stdout, ) -> str | None: """Print string with common format.""" if quiet: - return None # HACK: Satisfy MyPy + return None _msg = str(msg) action = action.rjust(indent, " ") if not style: return action + _msg - out = style + [action] + Style.RESET + [INDENT, _msg] # type: ignore[operator] + out = [*style, action, *Style.RESET, INDENT, _msg] print(*out, sep="", file=file_) - return None # HACK: Satisfy MyPy + return None def printf_exception( @@ -87,7 +88,7 @@ def printf_exception( ) -> None: """Print exception with common format.""" if not quiet: - print("", file=sys.stderr) + print(file=sys.stderr) printf(action, msg=msg, style=Style.DANGER, indent=indent, file_=sys.stderr) print(HLINE, file=sys.stderr) print(e, file=sys.stderr) diff --git a/copier/user_data.py b/copier/user_data.py index 7995d9afa..c4f5d3194 100644 --- a/copier/user_data.py +++ b/copier/user_data.py @@ -314,9 +314,9 @@ def _formatted_choices(self) -> Sequence[Choice]: # The value can be templated value = self.render_value(value) checked = ( - self.multiselect + (self.multiselect and isinstance(default, list) - and self.cast_answer(value) in default + and self.cast_answer(value) in default) or None ) c = Choice(name, value, disabled=disabled, checked=checked) diff --git a/copier/vcs.py b/copier/vcs.py index a26552238..0a755c24d 100644 --- a/copier/vcs.py +++ b/copier/vcs.py @@ -1,4 +1,5 @@ """Utilities related to VCS.""" + import os import re import sys @@ -74,10 +75,11 @@ def is_git_bundle(path: Path) -> bool: """Indicate if a path is a valid git bundle.""" with suppress(OSError): path = path.resolve() - with TemporaryDirectory(prefix=f"{__name__}.is_git_bundle.") as dirname: - with local.cwd(dirname): - get_git()("init") - return bool(get_git()["bundle", "verify", path] & TF) + with TemporaryDirectory(prefix=f"{__name__}.is_git_bundle.") as dirname, local.cwd( + dirname + ): + get_git()("init") + return bool(get_git()["bundle", "verify", path] & TF) def get_repo(url: str) -> OptStr: @@ -103,7 +105,7 @@ def get_repo(url: str) -> OptStr: if url.startswith("git+"): url = url[4:] elif url.startswith("https://") and not url.endswith(GIT_POSTFIX): - url = "".join((url, GIT_POSTFIX)) + url = f"{url}{GIT_POSTFIX}" return url url_path = Path(url) @@ -166,10 +168,7 @@ def clone(url: str, ref: OptStr = None) -> str: # Faster clones if possible if git_version >= Version("2.27"): url_match = re.match("(file://)?(.*)", url) - if url_match is not None: - file_url = url_match.groups()[-1] - else: - file_url = url + file_url = url_match.groups()[-1] if url_match is not None else url if is_git_shallow_repo(file_url): warn( f"The repository '{url}' is a shallow clone, this might lead to unexpected " diff --git a/devtasks.py b/devtasks.py index d6ccbde60..3ca99cee5 100644 --- a/devtasks.py +++ b/devtasks.py @@ -1,4 +1,5 @@ """Development helper tasks.""" + import logging import shutil from pathlib import Path @@ -25,7 +26,7 @@ def clean(): "**/*.pyc", "**/*.pyo", ) - project_dir = Path(".").resolve() + project_dir = Path.cwd() for pattern in build_artefacts + python_artefacts: for matching_path in project_dir.glob(pattern): print(f"Deleting {matching_path}") diff --git a/pyproject.toml b/pyproject.toml index 7549f5335..dac759ad6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,13 +113,19 @@ extend-select = [ "ARG", "B", "C90", + "C4", "D", "E", "F", "FA", + "FLY", + "FURB", "I", "PERF", + "PIE", "PGH", + "RUF", + "SIM", "UP", ] extend-ignore = ['B028', "B904", "D105", "D107", "E501"] diff --git a/tests/test_complex_questions.py b/tests/test_complex_questions.py index 829060cf9..200dd02af 100644 --- a/tests/test_complex_questions.py +++ b/tests/test_complex_questions.py @@ -168,7 +168,7 @@ def test_api(template_path: str, tmp_path: Path) -> None: def test_cli_interactive(template_path: str, tmp_path: Path, spawn: Spawn) -> None: """Test copier correctly processes advanced questions and answers through CLI.""" - tui = spawn(COPIER_PATH + ("copy", template_path, str(tmp_path)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", template_path, str(tmp_path)), timeout=10) expect_prompt(tui, "love_me", "bool", help="I need to know it. Do you love me?") tui.send("y") expect_prompt(tui, "your_name", "str", help="Please tell me your name.") @@ -310,16 +310,7 @@ def test_cli_interatively_with_flag_data_and_type_casts( ) -> None: """Assert how choices work when copier is invoked with --data interactively.""" tui = spawn( - COPIER_PATH - + ( - "copy", - "--data=choose_list=second", - "--data=choose_dict=first", - "--data=choose_tuple=third", - "--data=choose_number=1", - template_path, - str(tmp_path), - ), + (*COPIER_PATH, "copy", "--data=choose_list=second", "--data=choose_dict=first", "--data=choose_tuple=third", "--data=choose_number=1", template_path, str(tmp_path)), timeout=10, ) expect_prompt(tui, "love_me", "bool", help="I need to know it. Do you love me?") @@ -405,7 +396,7 @@ def test_tui_inherited_default( git("add", "--all") git("commit", "--message", "init template") git("tag", "1") - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "owner1", "str") tui.sendline("example") expect_prompt(tui, "has_2_owners", "bool") @@ -464,7 +455,7 @@ def test_tui_typed_default( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) tui.expect_exact(pexpect.EOF) assert json.loads((dst / "answers.json").read_text()) == {"_src_path": str(src)} assert json.loads((dst / "context.json").read_text()) == { @@ -505,7 +496,7 @@ def test_selection_type_cast( (src / "answers.json.jinja"): "{{ _copier_answers|to_json }}", } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt( tui, "postgres1", "yaml", help="Which PostgreSQL version do you want to deploy?" ) diff --git a/tests/test_conditional_file_name.py b/tests/test_conditional_file_name.py index 4c19941aa..a98d23de6 100644 --- a/tests/test_conditional_file_name.py +++ b/tests/test_conditional_file_name.py @@ -84,7 +84,7 @@ def test_answer_changes( git("tag", "v1") if interactive: - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "condition", "bool") tui.expect_exact("(y/N)") tui.sendline("y") @@ -101,7 +101,7 @@ def test_answer_changes( git("commit", "-mv1") if interactive: - tui = spawn(COPIER_PATH + ("update", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "update", str(dst)), timeout=10) expect_prompt(tui, "condition", "bool") tui.expect_exact("(Y/n)") tui.sendline("n") diff --git a/tests/test_config.py b/tests/test_config.py index 9105789b3..bf7241110 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -126,7 +126,7 @@ def test_invalid_config_data( ) -> None: template = Template(conf_path) with pytest.raises(InvalidConfigFileError): - template.config_data # noqa: B018 + template.config_data # noqa: B018 if check_err: _, err = capsys.readouterr() assert check_err(err) @@ -261,7 +261,7 @@ def test_config_data_empty() -> None: def test_multiple_config_file_error() -> None: template = Template("tests/demo_multi_config") with pytest.raises(MultipleConfigFilesError): - template.config_data # noqa: B018 + template.config_data # noqa: B018 # ConfigData @@ -295,7 +295,7 @@ def test_missing_template(tmp_path: Path) -> None: def is_subdict(small: dict[Any, Any], big: dict[Any, Any]) -> bool: - return {**big, **small} == big + return big == {**big, **small} def test_worker_good_data(tmp_path: Path) -> None: @@ -316,7 +316,7 @@ def test_worker_good_data(tmp_path: Path) -> None: # func_args > defaults ( {"src_path": ".", "exclude": ["aaa"]}, - tuple(DEFAULT_EXCLUDE) + ("aaa",), + (*tuple(DEFAULT_EXCLUDE), "aaa"), ), # func_args > user_data ( diff --git a/tests/test_interrupts.py b/tests/test_interrupts.py index d9b17d071..08a553c5a 100644 --- a/tests/test_interrupts.py +++ b/tests/test_interrupts.py @@ -34,9 +34,10 @@ def test_keyboard_interrupt( ) worker = Worker(str(src), dst, defaults=False) - with patch("copier.main.unsafe_prompt", side_effect=side_effect): - with pytest.raises(KeyboardInterrupt): - worker.run_copy() + with patch("copier.main.unsafe_prompt", side_effect=side_effect), pytest.raises( + KeyboardInterrupt + ): + worker.run_copy() def test_multiple_questions_interrupt(tmp_path_factory: pytest.TempPathFactory) -> None: diff --git a/tests/test_output.py b/tests/test_output.py index f33abf604..995fd7ccf 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -146,7 +146,7 @@ def test_messages_with_inline_text( # copy if interactive: - tui = spawn(COPIER_PATH + ("copy", "-r", "v1", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", "-r", "v1", str(src), str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("myproj") tui.expect_exact(pexpect.EOF) @@ -161,12 +161,12 @@ def test_messages_with_inline_text( Project\ myproj\ successfully\ created\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) # recopy if interactive: - tui = spawn(COPIER_PATH + ("recopy", "-r", "v1", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "recopy", "-r", "v1", str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("_new") tui.expect_exact(pexpect.EOF) @@ -181,7 +181,7 @@ def test_messages_with_inline_text( Project\ myproj_new\ successfully\ created\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) with local.cwd(dst): @@ -194,7 +194,7 @@ def test_messages_with_inline_text( # update if interactive: - tui = spawn(COPIER_PATH + ("update", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "update", str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("_update") tui.expect_exact(pexpect.EOF) @@ -209,7 +209,7 @@ def test_messages_with_inline_text( Project\ myproj_new_update\ successfully\ updated\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) @@ -286,7 +286,7 @@ def test_messages_with_included_text( # copy if interactive: - tui = spawn(COPIER_PATH + ("copy", "-r", "v1", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", "-r", "v1", str(src), str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("myproj") tui.expect_exact(pexpect.EOF) @@ -301,12 +301,12 @@ def test_messages_with_included_text( Project\ myproj\ successfully\ created\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) # recopy if interactive: - tui = spawn(COPIER_PATH + ("recopy", "-r", "v1", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "recopy", "-r", "v1", str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("_new") tui.expect_exact(pexpect.EOF) @@ -321,7 +321,7 @@ def test_messages_with_included_text( Project\ myproj_new\ successfully\ created\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) with local.cwd(dst): @@ -334,7 +334,7 @@ def test_messages_with_included_text( # update if interactive: - tui = spawn(COPIER_PATH + ("update", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "update", str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("_update") tui.expect_exact(pexpect.EOF) @@ -349,7 +349,7 @@ def test_messages_with_included_text( Project\ myproj_new_update\ successfully\ updated\s*$ """, err, - flags=re.S | re.X, + flags=re.DOTALL | re.VERBOSE, ) @@ -406,7 +406,7 @@ def test_messages_quiet( # copy if interactive: tui = spawn( - COPIER_PATH + ("copy", "--quiet", "-r", "v1", str(src), str(dst)), + (*COPIER_PATH, "copy", "--quiet", "-r", "v1", str(src), str(dst)), timeout=10, ) expect_prompt(tui, "project_name", "str") @@ -425,7 +425,7 @@ def test_messages_quiet( # recopy if interactive: tui = spawn( - COPIER_PATH + ("recopy", "--quiet", "-r", "v1", str(dst)), timeout=10 + (*COPIER_PATH, "recopy", "--quiet", "-r", "v1", str(dst)), timeout=10 ) expect_prompt(tui, "project_name", "str") tui.sendline("_new") @@ -448,7 +448,7 @@ def test_messages_quiet( # update if interactive: - tui = spawn(COPIER_PATH + ("update", "--quiet", str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "update", "--quiet", str(dst)), timeout=10) expect_prompt(tui, "project_name", "str") tui.sendline("_update") tui.expect_exact(pexpect.EOF) diff --git a/tests/test_prompt.py b/tests/test_prompt.py index 1911e334f..42d9c61e2 100644 --- a/tests/test_prompt.py +++ b/tests/test_prompt.py @@ -109,7 +109,7 @@ def test_copy_default_advertised( with local.cwd(dst): # Copy the v1 template tui = spawn( - COPIER_PATH + ("copy", str(src), ".", "--vcs-ref=v1") + args, timeout=10 + (*COPIER_PATH, "copy", str(src), ".", "--vcs-ref=v1", *args), timeout=10 ) # Check what was captured expect_prompt(tui, "in_love", "bool") @@ -133,7 +133,7 @@ def test_copy_default_advertised( # Update subproject git_save() assert "_commit: v1" in Path(".copier-answers.yml").read_text() - tui = spawn(COPIER_PATH + ("update",), timeout=30) + tui = spawn((*COPIER_PATH, "update"), timeout=30) # Check what was captured expect_prompt(tui, "in_love", "bool") tui.expect_exact("(Y/n)") @@ -177,7 +177,7 @@ def test_update_skip_answered( with local.cwd(dst): # Copy the v1 template tui = spawn( - COPIER_PATH + ("copy", str(src), ".", "--vcs-ref=v1") + args, timeout=10 + (*COPIER_PATH, "copy", str(src), ".", "--vcs-ref=v1", *args), timeout=10 ) # Check what was captured expect_prompt(tui, "in_love", "bool") @@ -201,11 +201,7 @@ def test_update_skip_answered( # Update subproject git_save() tui = spawn( - COPIER_PATH - + ( - update_action, - "--skip-answered", - ), + (*COPIER_PATH, update_action, "--skip-answered"), timeout=30, ) # Check what was captured @@ -240,7 +236,7 @@ def test_update_with_new_field_in_new_version_skip_answered( with local.cwd(dst): # Copy the v1 template tui = spawn( - COPIER_PATH + ("copy", str(src), ".", "--vcs-ref=v1") + args, timeout=10 + (*COPIER_PATH, "copy", str(src), ".", "--vcs-ref=v1", *args), timeout=10 ) # Check what was captured expect_prompt(tui, "in_love", "bool") @@ -264,11 +260,7 @@ def test_update_with_new_field_in_new_version_skip_answered( # Update subproject git_save() tui = spawn( - COPIER_PATH - + ( - "update", - "-A", - ), + (*COPIER_PATH, "update", "-A"), timeout=30, ) # Check what was captured @@ -355,7 +347,7 @@ def test_when( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question_1", type(question_1).__name__) tui.sendline() if asks: @@ -393,7 +385,7 @@ def test_placeholder(tmp_path_factory: pytest.TempPathFactory, spawn: Spawn) -> ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question_1", "str") tui.expect_exact("answer 1") tui.sendline() @@ -438,7 +430,7 @@ def test_multiline( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question_1", "str") tui.expect_exact("answer 1") tui.sendline() @@ -513,7 +505,7 @@ def test_update_choice( git("commit", "-m one") git("tag", "v1") # Copy - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "pick_one", "float") tui.sendline(Keyboard.Up) tui.expect_exact(pexpect.EOF) @@ -525,11 +517,7 @@ def test_update_choice( git("commit", "-m1") # Update tui = spawn( - COPIER_PATH - + ( - "update", - str(dst), - ), + (*COPIER_PATH, "update", str(dst)), timeout=10, ) expect_prompt(tui, "pick_one", "float") @@ -574,7 +562,7 @@ def test_multiline_defaults( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "yaml_single", "yaml") # This test will always fail here, because python prompt toolkit gives # syntax highlighting to YAML and JSON outputs, encoded into terminal @@ -619,7 +607,7 @@ def test_partial_interrupt( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question_1", "str") tui.expect_exact("answer 1") # Answer the first question using the default. @@ -659,7 +647,7 @@ def test_var_name_value_allowed( } ) # Copy - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "value", "str") tui.expect_exact("string") tui.send(Keyboard.Alt + Keyboard.Enter) @@ -700,7 +688,7 @@ def test_required_text_question( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question", type_name) tui.expect_exact("") tui.sendline() @@ -734,7 +722,7 @@ def test_required_bool_question( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question", "bool") tui.expect_exact("(y/N)") tui.sendline() @@ -781,7 +769,7 @@ def test_required_choice_question( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "question", type_name) tui.sendline() tui.expect_exact(pexpect.EOF) diff --git a/tests/test_templated_prompt.py b/tests/test_templated_prompt.py index b6fb2c3ed..4028f7a39 100644 --- a/tests/test_templated_prompt.py +++ b/tests/test_templated_prompt.py @@ -166,7 +166,7 @@ def test_templated_prompt( ), } ) - tui = spawn(COPIER_PATH + ("copy", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", str(src), str(dst)), timeout=10) expect_prompt(tui, "main", "str") tui.expect_exact(main_default) tui.sendline() @@ -356,7 +356,7 @@ def test_templated_prompt_with_conditional_choices( } ) tui = spawn( - COPIER_PATH + ("copy", f"--data=cloud={cloud}", str(src), str(dst)), + (*COPIER_PATH, "copy", f"--data=cloud={cloud}", str(src), str(dst)), timeout=10, ) expect_prompt(tui, "iac", "str", help="Which IaC tool do you use?") diff --git a/tests/test_unsafe.py b/tests/test_unsafe.py index e501edb17..584f8383d 100644 --- a/tests/test_unsafe.py +++ b/tests/test_unsafe.py @@ -345,7 +345,7 @@ def test_update_cli( git("tag", "v1") _, retcode = CopierApp.run( - ["copier", "copy", str(src), str(dst)] + unsafe_args, + ["copier", "copy", str(src), str(dst), *unsafe_args], exit=False, ) assert retcode == 0 @@ -368,12 +368,7 @@ def test_update_cli( git("tag", "v2") _, retcode = CopierApp.run( - [ - "copier", - "update", - str(dst), - ] - + unsafe_args, + ["copier", "update", str(dst), *unsafe_args], exit=False, ) if unsafe: diff --git a/tests/test_updatediff.py b/tests/test_updatediff.py index 263ae9fb2..ee70bc6de 100644 --- a/tests/test_updatediff.py +++ b/tests/test_updatediff.py @@ -726,7 +726,7 @@ def test_update_inline_changed_answers_and_questions( git("tag", "2") # Init project if interactive: - tui = spawn(COPIER_PATH + ("copy", "-r1", str(src), str(dst)), timeout=10) + tui = spawn((*COPIER_PATH, "copy", "-r1", str(src), str(dst)), timeout=10) tui.expect_exact("b (bool)") tui.expect_exact("(y/N)") tui.send("y") @@ -752,7 +752,7 @@ def test_update_inline_changed_answers_and_questions( git("commit", "-am2") # Update from template, inline, with answer changes if interactive: - tui = spawn(COPIER_PATH + ("update", "--conflict=inline"), timeout=10) + tui = spawn((*COPIER_PATH, "update", "--conflict=inline"), timeout=10) tui.expect_exact("b (bool)") tui.expect_exact("(Y/n)") tui.sendline() From ebdd0f304005ba6423115c771d870d2dcc193e2b Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 18 Mar 2024 08:03:59 +0000 Subject: [PATCH 2/3] fixup --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index bf7241110..d0f897632 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -316,7 +316,7 @@ def test_worker_good_data(tmp_path: Path) -> None: # func_args > defaults ( {"src_path": ".", "exclude": ["aaa"]}, - (*tuple(DEFAULT_EXCLUDE), "aaa"), + (*DEFAULT_EXCLUDE, "aaa"), ), # func_args > user_data ( From a59e4baaee85c9628aaaba42b449d16be44ee00e Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 18 Mar 2024 08:35:42 +0000 Subject: [PATCH 3/3] fixup --- copier/tools.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/copier/tools.py b/copier/tools.py index 1a359c16c..e78edc075 100644 --- a/copier/tools.py +++ b/copier/tools.py @@ -28,11 +28,11 @@ class Style: """Common color styles.""" - OK: ClassVar[IntSeq] = [colorama.Fore.GREEN, colorama.Style.BRIGHT] - WARNING: ClassVar[IntSeq] = [colorama.Fore.YELLOW, colorama.Style.BRIGHT] - IGNORE: ClassVar[IntSeq] = [colorama.Fore.CYAN] - DANGER: ClassVar[IntSeq] = [colorama.Fore.RED, colorama.Style.BRIGHT] - RESET: ClassVar[IntSeq] = [colorama.Fore.RESET, colorama.Style.RESET_ALL] + OK: ClassVar[list[str]] = [colorama.Fore.GREEN, colorama.Style.BRIGHT] + WARNING: ClassVar[list[str]] = [colorama.Fore.YELLOW, colorama.Style.BRIGHT] + IGNORE: ClassVar[list[str]] = [colorama.Fore.CYAN] + DANGER: ClassVar[list[str]] = [colorama.Fore.RED, colorama.Style.BRIGHT] + RESET: ClassVar[list[str]] = [colorama.Fore.RESET, colorama.Style.RESET_ALL] INDENT = " " * 2