Skip to content

Commit

Permalink
style: format with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp committed May 17, 2024
1 parent 6c3728a commit 66fa72c
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 62 deletions.
1 change: 1 addition & 0 deletions copier/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Copier CLI entrypoint."""

from .cli import CopierApp

# HACK https://github.com/nix-community/poetry2nix/issues/504
Expand Down
20 changes: 10 additions & 10 deletions copier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions copier/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main functions and classes, used to generate or update projects."""

from __future__ import annotations

import os
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions copier/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions copier/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tools related to template management."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions copier/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Some utility functions."""

from __future__ import annotations

import errno
Expand Down
1 change: 1 addition & 0 deletions copier/user_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions used to load user data."""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions copier/vcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities related to VCS."""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions devtasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Development helper tasks."""

import logging
import shutil
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_legacy_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 17 additions & 34 deletions tests/test_symlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
""",
Expand Down Expand Up @@ -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
""",
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
""",
Expand Down
3 changes: 1 addition & 2 deletions tests/test_unsafe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from .helpers import build_file_tree


class JinjaExtension(Extension):
...
class JinjaExtension(Extension): ...


@pytest.mark.parametrize(
Expand Down

0 comments on commit 66fa72c

Please sign in to comment.