Skip to content

Commit

Permalink
api ref: apply get_url improvements to open and read fns
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeorpinel committed Mar 4, 2020
1 parent e440284 commit 4ee9335
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
8 changes: 4 additions & 4 deletions public/static/docs/api-reference/get_url.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ specified by its `path` in a `repo` (<abbr>DVC project</abbr>), is stored.
The URL is formed by reading the project's
[remote configuration](/doc/command-reference/config#remote) and the
[DVC-file](/doc/user-guide/dvc-file-format) where the given `path` is an
<abbr>output</abbr> The URL schema returned depends on the
<abbr>output</abbr>. The URL schema returned depends on the
[type](/doc/command-reference/remote/add#supported-storage-types) of the
`remote` used (see the [Parameters](#parameters) section).

Expand All @@ -54,9 +54,9 @@ or
relative to the project's root.

- `repo` - specifies the location of the DVC project. It can be a URL or a file
system path. Both HTTP and SSH protocols are supported for online Git
repositories (e.g. `[user@]server:project.git`). _Default_: The current
project is used (the current working directory tree is walked up to find it).
system path. Both HTTP and SSH protocols are supported for online Git repos
(e.g. `[user@]server:project.git`). _Default_: The current project is used
(the current working directory tree is walked up to find it).

- `rev` - Git commit (any [revision](https://git-scm.com/docs/revisions) such as
a branch or tag name, or a commit hash). If `repo` is not a Git repo, this
Expand Down
45 changes: 25 additions & 20 deletions public/static/docs/api-reference/open.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
Opens a tracked file.

```py
dvc.api.open(path: str, repo: str = None, rev: str = None,
remote: str = None, mode: str = "r", encoding: str = None)
dvc.api.open(path: str,
repo: str = None,
rev: str = None,
remote: str = None,
mode: str = "r",
encoding: str = None)
```

**Usage:**
#### Usage:

```py
import dvc.api
Expand All @@ -23,8 +27,7 @@ with dvc.api.open(

Open file or model (`path`) tracked in a <abbr>DVC project</abbr> (by DVC or
Git), and return a corresponding
[file object](https://docs.python.org/3/glossary.html#term-file-object). If the
file cannot be found, a `PathMissingError` is raised.
[file object](https://docs.python.org/3/glossary.html#term-file-object).

> This function is analogous to the
> [`open()`](https://docs.python.org/3/library/functions.html#open) Python
Expand All @@ -49,26 +52,18 @@ before making it accessible. The only exception is when using a Google Drive

- `repo` - specifies the location of the DVC project. It can be a URL or a file
system path. Both HTTP and SSH protocols are supported for online Git repos
(e.g. `[user@]server:project.git`).

The current project is used by default if a `repo` argument is not given (the
current working directory tree is walked up to find it).
(e.g. `[user@]server:project.git`). _Default_: The current project is used
(the current working directory tree is walked up to find it).

- `rev` - Git commit (any [revision](https://git-scm.com/docs/revisions) such as
a branch or tag name, or a commit hash). If `repo` is not a Git repo, this
option is ignored.

`HEAD` is used by default if a `rev` argument is not given.
option is ignored. _Default_: `HEAD`.

- `remote` - name of the [DVC remote](/doc/command-reference/remote) to look for
the target data.

For online projects, the
[default remote](/doc/command-reference/remote/default) of `repo` is tried if
a `remote` argument is not given. For local projects, the default is to try
the <abbr>cache</abbr> before the default remote.

A `dvc.exceptions.NoRemoteError` is raised if no `remote` is found.
the target data. _Default_: The
[default remote](/doc/command-reference/remote/default) of `repo` is used if a
`remote` argument is not given. For local projects, the <abbr>cache</abbr> is
tied before the default remote.

- `mode` - specifies the mode in which the file is opened. Defaults to `"r"`
(read). Mirrors the namesake parameter in builtin
Expand All @@ -80,6 +75,16 @@ before making it accessible. The only exception is when using a Google Drive
mode. Defaults to `"utf-8"`. Mirrors the namesake parameter in builtin
`open()`.

## Exceptions

- `dvc.exceptions.FileMissingError` - file in `path` is missing from `repo`.

- `dvc.exceptions.PathMissingError` - `path` cannot be found in `repo`.

- `dvc.api.UrlNotDvcRepoError` - `repo` is not a DVC project.

- `dvc.exceptions.NoRemoteError` - no `remote` is found.

## Example: Use data tracked in a DVC repository online

Any <abbr>data artifact</abbr> can be employed directly in your Python app by
Expand Down
42 changes: 24 additions & 18 deletions public/static/docs/api-reference/read.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
Returns the contents of a tracked file.

```py
dvc.api.open(path: str, repo: str = None, rev: str = None,
remote: str = None, mode: str = "r", encoding: str = None)
dvc.api.open(path: str,
repo: str = None,
rev: str = None,
remote: str = None,
mode: str = "r",
encoding: str = None)
```

**Usage:**
#### Usage:

```py
import dvc.api
Expand Down Expand Up @@ -39,26 +43,18 @@ or a

- `repo` - specifies the location of the DVC project. It can be a URL or a file
system path. Both HTTP and SSH protocols are supported for online Git repos
(e.g. `[user@]server:project.git`).

The current project is used by default if a `repo` argument is not given (the
current working directory tree is walked up to find it).
(e.g. `[user@]server:project.git`). _Default_: The current project is used
(the current working directory tree is walked up to find it).

- `rev` - Git commit (any [revision](https://git-scm.com/docs/revisions) such as
a branch or tag name, or a commit hash). If `repo` is not a Git repo, this
option is ignored.

`HEAD` is used by default if a `rev` argument is not given.
option is ignored. _Default_: `HEAD`.

- `remote` - name of the [DVC remote](/doc/command-reference/remote) to look for
the target data.

For online projects, the
[default remote](/doc/command-reference/remote/default) of `repo` is tried if
a `remote` argument is not given. For local projects, the default is to try
the <abbr>cache</abbr> before the default remote.

A `dvc.exceptions.NoRemoteError` is raised if no `remote` is found.
the target data. _Default_: The
[default remote](/doc/command-reference/remote/default) of `repo` is used if a
`remote` argument is not given. For local projects, the <abbr>cache</abbr> is
tied before the default remote.

- `mode` - specifies the mode in which the file is opened. Defaults to `"r"`
(read). Mirrors the namesake parameter in builtin
Expand All @@ -70,6 +66,16 @@ or a
mode. Defaults to `"utf-8"`. Mirrors the namesake parameter in builtin
`open()`.

## Exceptions

- `dvc.exceptions.FileMissingError` - file in `path` is missing from `repo`.

- `dvc.exceptions.PathMissingError` - `path` cannot be found in `repo`.

- `dvc.api.UrlNotDvcRepoError` - `repo` is not a DVC project.

- `dvc.exceptions.NoRemoteError` - no `remote` is found.

## Example: Load data tracked in a DVC repository online

Any <abbr>data artifact</abbr> can be employed directly in your Python app by
Expand Down

0 comments on commit 4ee9335

Please sign in to comment.