-
Notifications
You must be signed in to change notification settings - Fork 1.3k
api: better code documentation #3130
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,11 @@ def __init__(self, url): | |
|
|
||
|
|
||
| def get_url(path, repo=None, rev=None, remote=None): | ||
| """Returns an url of a resource specified by path in repo""" | ||
| """ | ||
| Returns the full URL to the data artifact specified by its `path` in a | ||
| `repo`. | ||
| NOTE: There is no guarantee that the file actually exists in that location. | ||
| """ | ||
| try: | ||
| with _make_repo(repo, rev=rev) as _repo: | ||
| abspath = os.path.join(_repo.root_dir, path) | ||
|
|
@@ -67,7 +71,7 @@ def get_url(path, repo=None, rev=None, remote=None): | |
|
|
||
|
|
||
| def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | ||
| """Opens a specified resource as a file descriptor""" | ||
| """Context manager to open a file artifact as a file object.""" | ||
| args = (path,) | ||
| kwargs = { | ||
| "repo": repo, | ||
|
|
@@ -86,7 +90,7 @@ def __init__(self, func, args, kwds): | |
|
|
||
| def __getattr__(self, name): | ||
| raise AttributeError( | ||
| "dvc.api.open() should be used in a with statement" | ||
| "dvc.api.open() should be used in a with statement." | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -100,7 +104,7 @@ def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | |
|
|
||
|
|
||
| def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | ||
| """Read a specified resource into string""" | ||
| """Returns the contents of a file artifact.""" | ||
| with open( | ||
| path, repo=repo, rev=rev, remote=remote, mode=mode, encoding=encoding | ||
| ) as fd: | ||
|
|
@@ -110,15 +114,17 @@ def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | |
| @contextmanager | ||
| def _make_repo(repo_url, rev=None): | ||
| if not repo_url or os.path.exists(repo_url): | ||
| assert rev is None, "Custom revision is not supported for local repo" | ||
| assert ( | ||
| rev is None | ||
| ), "Git revisions are not supported for local DVC projects." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not "local repositories"? Not sure I understand what's a local DVC project.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A DVC project isn't always a repo. It can be initialized with |
||
| yield Repo(repo_url) | ||
| else: | ||
| with external_repo(url=repo_url, rev=rev) as repo: | ||
| yield repo | ||
|
|
||
|
|
||
| def summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml", args=None): | ||
| """Instantiate an object described in the summon file.""" | ||
| """Instantiate an object described in the `summon_file`.""" | ||
| with prepare_summon( | ||
| name, repo=repo, rev=rev, summon_file=summon_file | ||
| ) as desc: | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like backticks, we don't use them anywhere else. Python stdlib doesn't use them either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any suggestions? is there a standard way of doing markup that is understood by the tools that generate a view for this (like F1 in PyCharm, quick help in VS Code, docs generators, etc)
btw, we do use them as far as I can tell internally, also, Markdown markup or some markup is being used in other libraries for external APIs
Python stdlib:
double backtics to highlight the code (and probably make it linkable).
Am I missing something here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shcheklein , there are plenty docstring formats: https://stackoverflow.com/questions/3898572/what-is-the-standard-python-docstring-format
From PEP 287:
Not sure if any particular IDE takes advantages of such feature.
@Suor, we actually do 😅 but it is quite inconsistent:
grep -R '`.*`' dvcI'd say that there's no need to block a PR for this. I created a separate issue to discuss the formatting across the code base: #3176
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, all of those I've used at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was going for here. So keep it for now guys? I don't initially have a strong opinion.
Yeah great question @shcheklein! I'll look it up.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted docstring format discussion fully to #3176 (comment)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to resolve this one @Suor, as most available formats use backquotes except Google's, are you able to approve this for the time being? We will revisit this once #3176 is resolved anyway.