Skip to content

Commit

Permalink
build(typing): add missing type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp authored and yajo committed Oct 1, 2023
1 parent 59b8d6d commit bc1dfc0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ def run_update(
return worker


def _remove_old_files(prefix: Path, cmp: dircmp, rm_common: bool = False):
def _remove_old_files(prefix: Path, cmp: dircmp, rm_common: bool = False) -> None:
"""Remove files and directories only found in "old" template.
This is an internal helper method used to process a comparison of 2
Expand Down
4 changes: 2 additions & 2 deletions copier/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


# TODO Remove these two functions as well as DEFAULT_DATA in a future release
def _now():
def _now() -> datetime:
warnings.warn(
"'now' will be removed in a future release of Copier.\n"
"Please use this instead: {{ '%Y-%m-%d %H:%M:%S' | strftime }}\n"
Expand All @@ -37,7 +37,7 @@ def _now():
return datetime.utcnow()


def _make_secret():
def _make_secret() -> str:
warnings.warn(
"'make_secret' will be removed in a future release of Copier.\n"
"Please use this instead: {{ 999999999999999999999999999999999|ans_random|hash('sha512') }}\n"
Expand Down
5 changes: 3 additions & 2 deletions copier/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
from packaging import version
from packaging.version import InvalidVersion, Version
from plumbum import TF, ProcessExecutionError, colors, local
from plumbum.machines import LocalCommand

from .errors import DirtyLocalWarning, ShallowCloneWarning
from .types import OptBool, OptStr, OptStrOrPath, StrOrPath


def get_git(context_dir: OptStrOrPath = None):
def get_git(context_dir: OptStrOrPath = None) -> LocalCommand:
"""Gets `git` command, or fails if it's not available"""
command = local["git"]
if context_dir:
command = command["-C", context_dir]
return command


def get_git_version():
def get_git_version() -> Version:
git = get_git()

return Version(re.findall(r"\d+\.\d+\.\d+", git("version"))[0])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_subdirectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .helpers import BRACKET_ENVOPS_JSON, SUFFIX_TMPL, build_file_tree


def git_init(message="hello world"):
def git_init(message="hello world") -> None:
git("init")
git("config", "user.name", "Copier Test")
git("config", "user.email", "test@copier")
Expand Down
28 changes: 17 additions & 11 deletions tests/test_symlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .helpers import build_file_tree


def test_copy_symlink(tmp_path_factory):
def test_copy_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_copy_symlink(tmp_path_factory):
assert readlink(dst / "symlink.txt") == Path("target.txt")


def test_copy_symlink_templated_name(tmp_path_factory):
def test_copy_symlink_templated_name(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -83,7 +83,9 @@ def test_copy_symlink_templated_name(tmp_path_factory):
assert readlink(dst / "symlink.txt") == Path("target.txt")


def test_copy_symlink_templated_target(tmp_path_factory):
def test_copy_symlink_templated_target(
tmp_path_factory: pytest.TempPathFactory,
) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -125,7 +127,7 @@ def test_copy_symlink_templated_target(tmp_path_factory):
assert readlink(dst / "symlink2.txt") == Path("{{ target_name }}.txt")


def test_copy_symlink_missing_target(tmp_path_factory):
def test_copy_symlink_missing_target(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -160,7 +162,9 @@ def test_copy_symlink_missing_target(tmp_path_factory):
) # exists follows symlinks, It returns False as the target doesn't exist


def test_option_preserve_symlinks_false(tmp_path_factory):
def test_option_preserve_symlinks_false(
tmp_path_factory: pytest.TempPathFactory,
) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -194,7 +198,9 @@ def test_option_preserve_symlinks_false(tmp_path_factory):
assert not os.path.islink(dst / "symlink.txt")


def test_option_preserve_symlinks_default(tmp_path_factory):
def test_option_preserve_symlinks_default(
tmp_path_factory: pytest.TempPathFactory,
) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -227,7 +233,7 @@ def test_option_preserve_symlinks_default(tmp_path_factory):
assert not os.path.islink(dst / "symlink.txt")


def test_update_symlink(tmp_path_factory):
def test_update_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))

build_file_tree(
Expand Down Expand Up @@ -287,7 +293,7 @@ def test_update_symlink(tmp_path_factory):
assert readlink(dst / "symlink.txt") == Path("bbbb.txt")


def test_exclude_symlink(tmp_path_factory):
def test_exclude_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -320,7 +326,7 @@ def test_exclude_symlink(tmp_path_factory):
assert not (dst / "symlink.txt").is_symlink()


def test_pretend_symlink(tmp_path_factory):
def test_pretend_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -353,7 +359,7 @@ def test_pretend_symlink(tmp_path_factory):
assert not (dst / "symlink.txt").is_symlink()


def test_copy_symlink_none_path(tmp_path_factory):
def test_copy_symlink_none_path(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
# Prepare repo bundle
repo = src / "repo"
Expand Down Expand Up @@ -388,7 +394,7 @@ def test_copy_symlink_none_path(tmp_path_factory):
assert not os.path.islink(dst / "symlink.txt")


def test_recursive_symlink(tmp_path_factory: pytest.TempPathFactory):
def test_recursive_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
build_file_tree(
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def template_path(tmp_path_factory: pytest.TempPathFactory) -> str:
return str(root)


def empty_dir(dir: Path):
def empty_dir(dir: Path) -> None:
assert dir.is_dir()
assert dir.exists()
assert len(list(dir.iterdir())) == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_update_using_local_source_path_with_tilde(tmp_path: Path) -> None:
assert worker.answers.combined["_src_path"] == user_src_path


def test_invalid_version(tmp_path):
def test_invalid_version(tmp_path: Path) -> None:
sample = tmp_path / "sample.txt"
with local.cwd(tmp_path):
git("init")
Expand Down

0 comments on commit bc1dfc0

Please sign in to comment.