mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-04 04:10:20 +03:00
Support fetching a file from a git repo as an asset
Our Git fetcher code assumed that the asset to be copied was a directory. Support files as well and add tests to check both the file and directory cases. Fixes #12168.
This commit is contained in:
parent
57ba37bc52
commit
e92f4de49e
|
@ -414,7 +414,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)
|
||||
if os.path.isdir(source_path):
|
||||
shutil.copytree(str(source_path), str(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)
|
||||
|
|
|
@ -20,7 +20,7 @@ from spacy.cli._util import is_subpath_of, load_project_config, walk_directory
|
|||
from spacy.cli._util import parse_config_overrides, string_to_list
|
||||
from spacy.cli._util import substitute_project_variables
|
||||
from spacy.cli._util import validate_project_commands
|
||||
from spacy.cli._util import upload_file, download_file
|
||||
from spacy.cli._util import upload_file, download_file, git_checkout
|
||||
from spacy.cli.debug_data import _compile_gold, _get_labels_from_model
|
||||
from spacy.cli.debug_data import _get_labels_from_spancat
|
||||
from spacy.cli.debug_data import _get_distribution, _get_kl_divergence
|
||||
|
@ -145,6 +145,31 @@ def test_issue11235():
|
|||
assert cfg["commands"][0]["script"][0] == f"hello {lang_var}"
|
||||
|
||||
|
||||
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(12168)
|
||||
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")
|
||||
|
||||
|
||||
def test_cli_info():
|
||||
nlp = Dutch()
|
||||
nlp.add_pipe("textcat")
|
||||
|
|
Loading…
Reference in New Issue
Block a user