From 66fa72c26f6039e49f9e974d8da13e68d735aac1 Mon Sep 17 00:00:00 2001 From: Sigurd Spieckermann Date: Fri, 17 May 2024 11:04:38 +0200 Subject: [PATCH] style: format with Ruff --- copier/__main__.py | 1 + copier/cli.py | 20 ++++++------- copier/main.py | 11 ++++---- copier/subproject.py | 1 + copier/template.py | 1 + copier/tools.py | 1 + copier/user_data.py | 1 + copier/vcs.py | 1 + devtasks.py | 1 + tests/helpers.py | 3 +- tests/test_legacy_migration.py | 7 ++++- tests/test_output.py | 6 ++-- tests/test_prompt.py | 6 ++-- tests/test_symlinks.py | 51 ++++++++++++---------------------- tests/test_unsafe.py | 3 +- 15 files changed, 52 insertions(+), 62 deletions(-) diff --git a/copier/__main__.py b/copier/__main__.py index 76d070a07..16951f8ba 100644 --- a/copier/__main__.py +++ b/copier/__main__.py @@ -1,4 +1,5 @@ """Copier CLI entrypoint.""" + from .cli import CopierApp # HACK https://github.com/nix-community/poetry2nix/issues/504 diff --git a/copier/cli.py b/copier/cli.py index 36143042f..6c55bafee 100644 --- a/copier/cli.py +++ b/copier/cli.py @@ -84,21 +84,18 @@ class CopierApp(cli.Application): # type: ignore[misc] """The Copier CLI application.""" DESCRIPTION = "Create a new project from a template." - DESCRIPTION_MORE = ( - dedent( - """\ + DESCRIPTION_MORE = dedent( + """\ Docs in https://copier.readthedocs.io/ """ - ) - + ( - colors.yellow - | dedent( - """\ + ) + ( + colors.yellow + | dedent( + """\ WARNING! Use only trusted project templates, as they might execute code with the same level of access as your user.\n """ - ) ) ) VERSION = copier_version() @@ -201,7 +198,10 @@ def data_file_switch(self, path: cli.ExistingFile) -> None: self.data.update(updates_without_cli_overrides) def _worker( - self, src_path: Optional[str] = None, dst_path: str = ".", **kwargs: Any # noqa: FA100 + self, + src_path: Optional[str] = None, + dst_path: str = ".", + **kwargs: Any, # noqa: FA100 ) -> Worker: """Run Copier's internal API using CLI switches. diff --git a/copier/main.py b/copier/main.py index c862f34ec..87040ffd7 100644 --- a/copier/main.py +++ b/copier/main.py @@ -1,4 +1,5 @@ """Main functions and classes, used to generate or update projects.""" + from __future__ import annotations import os @@ -204,14 +205,12 @@ def __enter__(self) -> Worker: return self @overload - def __exit__(self, type: None, value: None, traceback: None) -> None: - ... + def __exit__(self, type: None, value: None, traceback: None) -> None: ... @overload def __exit__( self, type: type[BaseException], value: BaseException, traceback: TracebackType - ) -> None: - ... + ) -> None: ... def __exit__( self, @@ -488,7 +487,9 @@ def _ask(self) -> None: # noqa: C901 # Try to validate the answer value if the question has a # validator. if err_msg := question.validate_answer(answer): - raise ValueError(f"Validation error for question '{var_name}': {err_msg}") + raise ValueError( + f"Validation error for question '{var_name}': {err_msg}" + ) # At this point, the answer value is valid. Do not ask the # question again, but set answer as the user's answer instead. result.user[var_name] = answer diff --git a/copier/subproject.py b/copier/subproject.py index 81d3e968d..b037baa97 100644 --- a/copier/subproject.py +++ b/copier/subproject.py @@ -2,6 +2,7 @@ A *subproject* is a project that gets rendered and/or updated with Copier. """ + from __future__ import annotations from dataclasses import field diff --git a/copier/template.py b/copier/template.py index feb71db54..0300e8a7d 100644 --- a/copier/template.py +++ b/copier/template.py @@ -1,4 +1,5 @@ """Tools related to template management.""" + from __future__ import annotations import re diff --git a/copier/tools.py b/copier/tools.py index 23077a83a..929a3c85b 100644 --- a/copier/tools.py +++ b/copier/tools.py @@ -1,4 +1,5 @@ """Some utility functions.""" + from __future__ import annotations import errno diff --git a/copier/user_data.py b/copier/user_data.py index ad68f1651..e0cec7a09 100644 --- a/copier/user_data.py +++ b/copier/user_data.py @@ -1,4 +1,5 @@ """Functions used to load user data.""" + from __future__ import annotations import json diff --git a/copier/vcs.py b/copier/vcs.py index c0dcf2605..2e590eded 100644 --- a/copier/vcs.py +++ b/copier/vcs.py @@ -1,4 +1,5 @@ """Utilities related to VCS.""" + from __future__ import annotations import os diff --git a/devtasks.py b/devtasks.py index e92ddfc96..a84139484 100644 --- a/devtasks.py +++ b/devtasks.py @@ -1,4 +1,5 @@ """Development helper tasks.""" + import logging import shutil from pathlib import Path diff --git a/tests/helpers.py b/tests/helpers.py index 9eb1840f4..b4aadc5f0 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -65,8 +65,7 @@ class Spawn(Protocol): - def __call__(self, cmd: tuple[str, ...], *, timeout: int | None) -> PopenSpawn: - ... + def __call__(self, cmd: tuple[str, ...], *, timeout: int | None) -> PopenSpawn: ... class Keyboard(str, Enum): diff --git a/tests/test_legacy_migration.py b/tests/test_legacy_migration.py index c560127e0..45ed544fd 100644 --- a/tests/test_legacy_migration.py +++ b/tests/test_legacy_migration.py @@ -15,6 +15,7 @@ SRC = Path(f"{PROJECT_TEMPLATE}_legacy_migrations").absolute() + # This fails on windows CI because, when the test tries to execute # `migrations.py`, it doesn't understand that it should be interpreted # by python.exe. Or maybe it fails because CI is using Git bash instead @@ -240,7 +241,11 @@ def test_prereleases(tmp_path_factory: pytest.TempPathFactory) -> None: # Update it with prereleases with pytest.deprecated_call(): run_update( - dst_path=dst, defaults=True, overwrite=True, use_prereleases=True, unsafe=True + dst_path=dst, + defaults=True, + overwrite=True, + use_prereleases=True, + unsafe=True, ) answers = yaml.safe_load((dst / ".copier-answers.yml").read_text()) assert answers["_commit"] == "v2.0.0.alpha1" diff --git a/tests/test_output.py b/tests/test_output.py index f33abf604..74a1ddb3c 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -61,8 +61,7 @@ def test_question_with_invalid_type(tmp_path_factory: pytest.TempPathFactory) -> src, dst = map(tmp_path_factory.mktemp, ["src", "dst"]) build_file_tree( { - src - / "copier.yaml": """ + src / "copier.yaml": """ bad: type: invalid default: 1 @@ -79,8 +78,7 @@ def test_answer_with_invalid_type(tmp_path_factory: pytest.TempPathFactory) -> N src, dst = map(tmp_path_factory.mktemp, ["src", "dst"]) build_file_tree( { - src - / "copier.yaml": """ + src / "copier.yaml": """ bad: type: int default: null diff --git a/tests/test_prompt.py b/tests/test_prompt.py index 7346cdb0c..cc7e5fd26 100644 --- a/tests/test_prompt.py +++ b/tests/test_prompt.py @@ -810,8 +810,7 @@ def test_required_choice_question( class QuestionTreeFixture(Protocol): - def __call__(self, **kwargs) -> tuple[Path, Path]: - ... + def __call__(self, **kwargs) -> tuple[Path, Path]: ... @pytest.fixture @@ -838,8 +837,7 @@ def builder(**question) -> tuple[Path, Path]: class CopierFixture(Protocol): - def __call__(self, *args, **kwargs) -> PopenSpawn: - ... + def __call__(self, *args, **kwargs) -> PopenSpawn: ... @pytest.fixture diff --git a/tests/test_symlinks.py b/tests/test_symlinks.py index c787c9e09..20dccde9c 100644 --- a/tests/test_symlinks.py +++ b/tests/test_symlinks.py @@ -19,8 +19,7 @@ def test_copy_symlink(tmp_path_factory: pytest.TempPathFactory) -> None: repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true """, repo / "target.txt": "Symlink target", @@ -54,8 +53,7 @@ def test_copy_symlink_templated_name(tmp_path_factory: pytest.TempPathFactory) - repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true symlink_name: symlink """, @@ -92,8 +90,7 @@ def test_copy_symlink_templated_target( repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true target_name: target """, @@ -134,8 +131,7 @@ def test_copy_symlink_missing_target(tmp_path_factory: pytest.TempPathFactory) - repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true """, repo / "symlink.txt": Path("target.txt"), @@ -171,8 +167,7 @@ def test_option_preserve_symlinks_false( repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: false """, repo / "target.txt": "Symlink target", @@ -207,8 +202,7 @@ def test_option_preserve_symlinks_default( repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ """, repo / "target.txt": "Symlink target", repo / "symlink.txt": Path("target.txt"), @@ -238,21 +232,17 @@ def test_update_symlink(tmp_path_factory: pytest.TempPathFactory) -> None: build_file_tree( { - src - / ".copier-answers.yml.jinja": """\ + src / ".copier-answers.yml.jinja": """\ # Changes here will be overwritten by Copier {{ _copier_answers|to_nice_yaml }} """, - src - / "copier.yml": """\ + src / "copier.yml": """\ _preserve_symlinks: true """, - src - / "aaaa.txt": """ + src / "aaaa.txt": """ Lorem ipsum """, - src - / "bbbb.txt": """ + src / "bbbb.txt": """ dolor sit amet """, src / "symlink.txt": Path("./aaaa.txt"), @@ -298,21 +288,17 @@ def test_update_file_to_symlink(tmp_path_factory: pytest.TempPathFactory) -> Non build_file_tree( { - src - / ".copier-answers.yml.jinja": """\ + src / ".copier-answers.yml.jinja": """\ # Changes here will be overwritten by Copier {{ _copier_answers|to_nice_yaml }} """, - src - / "copier.yml": """\ + src / "copier.yml": """\ _preserve_symlinks: true """, - src - / "aaaa.txt": """ + src / "aaaa.txt": """ Lorem ipsum """, - src - / "bbbb.txt": """ + src / "bbbb.txt": """ dolor sit amet """, src / "cccc.txt": Path("./aaaa.txt"), @@ -361,8 +347,7 @@ def test_exclude_symlink(tmp_path_factory: pytest.TempPathFactory) -> None: repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true """, repo / "target.txt": "Symlink target", @@ -394,8 +379,7 @@ def test_pretend_symlink(tmp_path_factory: pytest.TempPathFactory) -> None: repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true """, repo / "target.txt": "Symlink target", @@ -427,8 +411,7 @@ def test_copy_symlink_none_path(tmp_path_factory: pytest.TempPathFactory) -> Non repo.mkdir() build_file_tree( { - repo - / "copier.yaml": """\ + repo / "copier.yaml": """\ _preserve_symlinks: true render: false """, diff --git a/tests/test_unsafe.py b/tests/test_unsafe.py index e501edb17..a149f6ba4 100644 --- a/tests/test_unsafe.py +++ b/tests/test_unsafe.py @@ -17,8 +17,7 @@ from .helpers import build_file_tree -class JinjaExtension(Extension): - ... +class JinjaExtension(Extension): ... @pytest.mark.parametrize(