Skip to content

Commit 9f08ea8

Browse files
authored
Merge pull request explosion#6047 from svlandeg/feature/doc-fixes
Fix branch for spacy clone + UX
2 parents 763e302 + a36766d commit 9f08ea8

File tree

9 files changed

+34
-18
lines changed

9 files changed

+34
-18
lines changed

spacy/cli/_util.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import srsly
77
import hashlib
88
import typer
9+
import subprocess
910
from click import NoSuchOption
1011
from typer.main import get_command
1112
from contextlib import contextmanager
@@ -326,22 +327,33 @@ def git_sparse_checkout(repo: str, subpath: str, dest: Path, *, branch: str = "m
326327
f"--filter=blob:none " # <-- The key bit
327328
f"-b {branch}"
328329
)
329-
run_command(cmd, capture=True)
330+
_attempt_run_command(cmd)
330331
# Now we need to find the missing filenames for the subpath we want.
331332
# Looking for this 'rev-list' command in the git --help? Hah.
332333
cmd = f"git -C {tmp_dir} rev-list --objects --all --missing=print -- {subpath}"
333-
ret = run_command(cmd, capture=True)
334-
repo = _from_http_to_git(repo)
334+
ret = _attempt_run_command(cmd)
335+
git_repo = _from_http_to_git(repo)
335336
# Now pass those missings into another bit of git internals
336337
missings = " ".join([x[1:] for x in ret.stdout.split() if x.startswith("?")])
337-
cmd = f"git -C {tmp_dir} fetch-pack {repo} {missings}"
338-
run_command(cmd, capture=True)
338+
if not missings:
339+
err = f"Could not find any relevant files for '{subpath}'. " \
340+
f"Did you specify a correct and complete path within repo '{repo}' " \
341+
f"and branch {branch}?"
342+
msg.fail(err, exits=1)
343+
cmd = f"git -C {tmp_dir} fetch-pack {git_repo} {missings}"
344+
_attempt_run_command(cmd)
339345
# And finally, we can checkout our subpath
340346
cmd = f"git -C {tmp_dir} checkout {branch} {subpath}"
341-
run_command(cmd)
347+
_attempt_run_command(cmd)
342348
# We need Path(name) to make sure we also support subdirectories
343349
shutil.move(str(tmp_dir / Path(subpath)), str(dest))
344350

351+
def _attempt_run_command(cmd):
352+
try:
353+
return run_command(cmd, capture=True)
354+
except subprocess.CalledProcessError as e:
355+
err = f"Could not run command: {cmd}."
356+
msg.fail(err, exits=1)
345357

346358
def _from_http_to_git(repo):
347359
if repo.startswith("http://"):

spacy/cli/project/clone.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def project_clone_cli(
2828
"""
2929
if dest is None:
3030
dest = Path.cwd() / name
31-
project_clone(name, dest, repo=repo)
31+
project_clone(name, dest, repo=repo, branch=branch)
3232

3333

3434
def project_clone(
@@ -43,13 +43,14 @@ def project_clone(
4343
name (str): Name of subdirectory to clone.
4444
dest (Path): Destination path of cloned project.
4545
repo (str): URL of Git repo containing project templates.
46+
branch (str): The branch to clone from
4647
"""
4748
dest = ensure_path(dest)
4849
check_clone(name, dest, repo)
4950
project_dir = dest.resolve()
5051
repo_name = re.sub(r"(http(s?)):\/\/github.com/", "", repo)
5152
try:
52-
git_sparse_checkout(repo, name, dest)
53+
git_sparse_checkout(repo, name, dest, branch=branch)
5354
except subprocess.CalledProcessError:
5455
err = f"Could not clone '{name}' from repo '{repo_name}'"
5556
msg.fail(err, exits=1)

website/docs/api/dependencyparser.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ Add a new label to the pipe. Note that you don't have to call this method if you
297297
provide a **representative data sample** to the
298298
[`begin_training`](#begin_training) method. In this case, all labels found in
299299
the sample will be automatically added to the model, and the output dimension
300-
will be [inferred](/usage/layers-architectures#shape-inference) automatically.
300+
will be [inferred](/usage/layers-architectures#thinc-shape-inference)
301+
automatically.
301302
302303
> #### Example
303304
>

website/docs/api/entityrecognizer.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ Add a new label to the pipe. Note that you don't have to call this method if you
285285
provide a **representative data sample** to the
286286
[`begin_training`](#begin_training) method. In this case, all labels found in
287287
the sample will be automatically added to the model, and the output dimension
288-
will be [inferred](/usage/layers-architectures#shape-inference) automatically.
288+
will be [inferred](/usage/layers-architectures#thinc-shape-inference)
289+
automatically.
289290
290291
> #### Example
291292
>

website/docs/api/language.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ examples can either be the full training data or a representative sample. They
205205
are used to **initialize the models** of trainable pipeline components and are
206206
passed each component's [`begin_training`](/api/pipe#begin_training) method, if
207207
available. Initialization includes validating the network,
208-
[inferring missing shapes](/usage/layers-architectures#shape-inference) and
209-
setting up the label scheme based on the data.
208+
[inferring missing shapes](/usage/layers-architectures#thinc-shape-inference)
209+
and setting up the label scheme based on the data.
210210
211211
If no `get_examples` function is provided when calling `nlp.begin_training`, the
212212
pipeline components will be initialized with generic data. In this case, it is

website/docs/api/morphologizer.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ already been fully [initialized](#begin_training). Note that you don't have to
263263
call this method if you provide a **representative data sample** to the
264264
[`begin_training`](#begin_training) method. In this case, all labels found in
265265
the sample will be automatically added to the model, and the output dimension
266-
will be [inferred](/usage/layers-architectures#shape-inference) automatically.
266+
will be [inferred](/usage/layers-architectures#thinc-shape-inference)
267+
automatically.
267268
268269
> #### Example
269270
>

website/docs/api/pipe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Note that in general, you don't have to call `pipe.add_label` if you provide a
317317
representative data sample to the [`begin_training`](#begin_training) method. In
318318
this case, all labels found in the sample will be automatically added to the
319319
model, and the output dimension will be
320-
[inferred](/usage/layers-architectures#shape-inference) automatically.
320+
[inferred](/usage/layers-architectures#thinc-shape-inference) automatically.
321321
322322
## Pipe.is_resizable {#is_resizable tag="method"}
323323

website/docs/api/tagger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ set, or if the model has already been fully [initialized](#begin_training). Note
293293
that you don't have to call this method if you provide a **representative data
294294
sample** to the [`begin_training`](#begin_training) method. In this case, all
295295
labels found in the sample will be automatically added to the model, and the
296-
output dimension will be [inferred](/usage/layers-architectures#shape-inference)
297-
automatically.
296+
output dimension will be
297+
[inferred](/usage/layers-architectures#thinc-shape-inference) automatically.
298298
299299
> #### Example
300300
>

website/docs/api/textcategorizer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ set, or if the model has already been fully [initialized](#begin_training). Note
302302
that you don't have to call this method if you provide a **representative data
303303
sample** to the [`begin_training`](#begin_training) method. In this case, all
304304
labels found in the sample will be automatically added to the model, and the
305-
output dimension will be [inferred](/usage/layers-architectures#shape-inference)
306-
automatically.
305+
output dimension will be
306+
[inferred](/usage/layers-architectures#thinc-shape-inference) automatically.
307307
308308
> #### Example
309309
>

0 commit comments

Comments
 (0)