Skip to content

Commit

Permalink
remove 'decorator' dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Feb 11, 2024
1 parent ece7c9c commit 69057c6
Show file tree
Hide file tree
Showing 3 changed files with 482 additions and 485 deletions.
51 changes: 27 additions & 24 deletions copier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,60 @@
```
"""

import functools
import sys
from os import PathLike
from pathlib import Path
from textwrap import dedent
from typing import Callable

import yaml
from decorator import decorator
from plumbum import cli, colors
from typing_extensions import ParamSpec

from .errors import UnsafeTemplateError, UserMessageError
from .main import Worker
from .tools import copier_version
from .types import AnyByStrDict, OptStr, StrSeq

P = ParamSpec("P")

@decorator
def handle_exceptions(method, *args, **kwargs):
"""Handle keyboard interruption while running a method."""
try:

def handle_exceptions(method: Callable[P, int]) -> Callable[P, int]:
@functools.wraps(method)
def inner(*args: P.args, **kwargs: P.kwargs) -> int:
try:
return method(*args, **kwargs)
except KeyboardInterrupt:
raise UserMessageError("Execution stopped by user")
except UserMessageError as error:
print(colors.red | "\n".join(error.args), file=sys.stderr)
return 1
except UnsafeTemplateError as error:
print(colors.red | "\n".join(error.args), file=sys.stderr)
# DOCS https://github.com/copier-org/copier/issues/1328#issuecomment-1723214165
return 0b100
try:
return method(*args, **kwargs)
except KeyboardInterrupt:
raise UserMessageError("Execution stopped by user")
except UserMessageError as error:
print(colors.red | "\n".join(error.args), file=sys.stderr)
return 1
except UnsafeTemplateError as error:
print(colors.red | "\n".join(error.args), file=sys.stderr)
# DOCS https://github.com/copier-org/copier/issues/1328#issuecomment-1723214165
return 0b100

return inner


class CopierApp(cli.Application):
"""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
Loading

0 comments on commit 69057c6

Please sign in to comment.