Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting explosion/spaCy#12181 solution into weasel #83

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ install_requires =
console_scripts =
weasel = weasel.cli:app

[tool:pytest]
markers =
issue: references specific issue

[mypy]
ignore_missing_imports = True
no_implicit_optional = True
Expand Down
27 changes: 26 additions & 1 deletion weasel/tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from weasel.cli.remote_storage import RemoteStorage
from weasel.schemas import ProjectConfigSchema, validate
from weasel.util import is_subpath_of, load_project_config, make_tempdir
from weasel.util import git_checkout, is_subpath_of, load_project_config, make_tempdir
from weasel.util import validate_project_commands


Expand Down Expand Up @@ -165,3 +165,28 @@ def test_local_remote_storage_pull_missing():
remote = RemoteStorage(d / "root", str(d / "remote"))
assert remote.pull(filename, command_hash="aaaa") is None
assert remote.pull(filename) is None


def test_project_git_dir_asset():
with make_tempdir() as d:
# Use a very small repo.
git_checkout(
"https://github.com/explosion/os-signpost.git",
"os_signpost",
d / "signpost",
branch="v0.0.3",
)
assert os.path.isdir(d / "signpost")


@pytest.mark.issue(66)
def test_project_git_file_asset():
with make_tempdir() as d:
# Use a very small repo.
git_checkout(
"https://github.com/explosion/os-signpost.git",
"README.md",
d / "readme.md",
branch="v0.0.3",
)
assert os.path.isfile(d / "readme.md")
6 changes: 5 additions & 1 deletion weasel/util/git.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
from pathlib import Path
from typing import Tuple
Expand Down Expand Up @@ -41,7 +42,10 @@ def git_checkout(
if not is_subpath_of(tmp_dir, source_path):
err = f"'{subpath}' is a path outside of the cloned repository."
msg.fail(err, repo, exits=1)
shutil.copytree(str(source_path), str(dest))
if os.path.isdir(source_path):
shutil.copytree(source_path, dest)
else:
shutil.copyfile(source_path, dest)
except FileNotFoundError:
err = f"Can't clone {subpath}. Make sure the directory exists in the repo (branch '{branch}')"
msg.fail(err, repo, exits=1)
Expand Down
Loading