-
Notifications
You must be signed in to change notification settings - Fork 53
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
Added source code link #172
Conversation
Thanks for the pull request @ayyucedemirbas , please run Alternatively, you can enable pre-commit hooks to do that automatically when you commit code: https://github.com/skops-dev/skops/blob/main/CONTRIBUTING.rst#using-condamamba |
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.
Thanks @ayyucedemirbas , this looks quite good already.
docs/conf.py
Outdated
if not info["module"]: | ||
return None |
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 checked bellow again (info.get("module")
is safer than info["module"]
since the latter can raise an exception if the key doesn't exist.
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.
✅ Done
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.
Now it works, I updated the PR. Could you please take a look at it? Thank you so much for everything!
docs/conf.py
Outdated
except Exception: | ||
lineno = "" | ||
return ( | ||
"https://github.com/skops-dev/skops/blob/main/skops/" + fn + "#L" + str(lineno) |
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.
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 added these lines from scikit-learn:
REVISION_CMD = "git rev-parse --short HEAD"
def _get_git_revision():
try:
revision = subprocess.check_output(REVISION_CMD.split()).strip()
except (subprocess.CalledProcessError, OSError):
print("Failed to execute git to get revision")
return None
return revision.decode("utf-8")
def linkcode_resolve(domain, info):
...
revision = _get_git_revision()
if revision is None:
return
...
return (
"https://github.com/skops-dev/skops/blob/{revision}/skops/" + fn + "#L" + str(lineno)
)
However, the source code links became something like this (https://github.com/skops-dev/skops/blob/%7Brevision%7D/skops/hub_utils/_hf_hub.py#L328) and of course, they don't work
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.
Could you try this patch:
diff --git a/docs/conf.py b/docs/conf.py
index 3ed773f..4ed5d3d 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -8,6 +8,7 @@
import inspect
import os
+import subprocess
from operator import attrgetter
from packaging.version import parse
@@ -71,6 +72,19 @@ autosummary_generate = True
issues_github_path = "skops-dev/skops"
+# -- linkcode configuration --------------------------------------------------
+REVISION_CMD = "git rev-parse --short HEAD"
+
+
+def _get_git_revision():
+ try:
+ revision = subprocess.check_output(REVISION_CMD.split()).strip()
+ except (subprocess.CalledProcessError, OSError):
+ print("Failed to execute git to get revision")
+ return None
+ return revision.decode("utf-8")
+
+
def linkcode_resolve(domain, info):
if domain != "py":
return None
@@ -93,7 +107,7 @@ def linkcode_resolve(domain, info):
try:
fn = inspect.getsourcefile(inspect.unwrap(obj))
except TypeError:
- try:
+ try:
fn = inspect.getsourcefile(inspect.unwrap(obj.fget))
except (AttributeError, TypeError):
fn = None
@@ -105,9 +119,16 @@ def linkcode_resolve(domain, info):
lineno = inspect.getsourcelines(obj)[1]
except Exception:
lineno = ""
- return (
- "https://github.com/skops-dev/skops/blob/main/skops/" + fn + "#L" + str(lineno)
+ url_fmt = (
+ "https://github.com/scikit-learn/"
+ "scikit-learn/blob/{revision}/"
+ "{package}/{path}#L{lineno}"
)
+ revision = _get_git_revision()
+ return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)
+
+
+# -- linkcode configuration --------------------------------------------------
# -- Options for HTML output -------------------------------------------------
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.
Returns something like this: https://github.com/scikit-learn/scikit-learn/blob/a6db88f/skops/hub_utils/_hf_hub.py#L594
and also doesn't work
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.
There are two problems why this doesn't work. First of all it links to sklearn but we want to link to skops (I guess Adrin forgot to adjust the copied code):
url_fmt = (
"https://github.com/skops-dev/"
"skops/blob/{revision}/"
"{package}/{path}#L{lineno}"
)
But even after that, the link wouldn't lead anywhere. However, this is probably because the git revision's hash does not lead anywhere (yet). If we replace it with the hash of an actual commit (current HEAD on main branch), it will work, e.g.:
https://github.com/skops-dev/skops/blob/69621cd/skops/hub_utils/_hf_hub.py#L594
where 69621cd
is the current git rev-parse --short HEAD
. So when you test the link locally, it might not work because the commit doesn't exist on GitHub. But that's no problem, once the code is merged, the links will be correct.
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.
Ahahahahhahahhahah I feel like an idiot. Thank you so much!
docs/conf.py
Outdated
@@ -65,6 +70,46 @@ | |||
# (note that `group` is the GitHub user or organization) | |||
issues_github_path = "skops-dev/skops" | |||
|
|||
|
|||
def linkcode_resolve(domain, info): | |||
if domain != "py": |
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.
Adrin already mentioned this, but this line and the one below
if domain not in ("py", "pyx"):
do redundant work. Only the latter is necessary.
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.
✅ Done
docs/conf.py
Outdated
return None | ||
if not info["module"]: | ||
return None | ||
filename = info["module"].replace(".", "/") |
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.
filename
is not being used and can be deleted.
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.
✅ Done
docs/conf.py
Outdated
try: | ||
fn = inspect.getsourcefile(inspect.unwrap(obj)) | ||
except TypeError: | ||
try: |
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.
try: | |
try: |
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.
✅ Done
docs/conf.py
Outdated
except Exception: | ||
lineno = "" | ||
return ( | ||
"https://github.com/skops-dev/skops/blob/main/skops/" + fn + "#L" + str(lineno) |
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.
There are two problems why this doesn't work. First of all it links to sklearn but we want to link to skops (I guess Adrin forgot to adjust the copied code):
url_fmt = (
"https://github.com/skops-dev/"
"skops/blob/{revision}/"
"{package}/{path}#L{lineno}"
)
But even after that, the link wouldn't lead anywhere. However, this is probably because the git revision's hash does not lead anywhere (yet). If we replace it with the hash of an actual commit (current HEAD on main branch), it will work, e.g.:
https://github.com/skops-dev/skops/blob/69621cd/skops/hub_utils/_hf_hub.py#L594
where 69621cd
is the current git rev-parse --short HEAD
. So when you test the link locally, it might not work because the commit doesn't exist on GitHub. But that's no problem, once the code is merged, the links will be correct.
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.
It looks good now, the documentation successfully links to the code, thanks a lot. I have only two minor comments, one about the domain check and one would be for you to add an entry to changes.rst.
docs/conf.py
Outdated
if domain not in ("py", "pyx"): | ||
return |
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 would keep this check, we just don't need the if domain != "py":
too, as it's redundant.
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.
All done! I couldn't edit the changes.rst file in this pr, so I had to create a new one, which is #186
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 couldn't edit the changes.rst file in this pr
That's strange. What error did you get? Maybe we can figure it out :)
There is no error. The problem is I don't know how to do that :)
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.
Hmm, same as with the conf.py
? You modify the changes.rst
, then git add changes.rst
, then git commit -m "blabla"
and git push
.
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.
Thanks! I use the browser. Is there any way to do that on the browser? Or I'll use the CLI.
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.
Hmm, I think it's probably possible in the browser, but I have never used it, so maybe not.
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 get this error message:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/ayyucedemirbas/skops.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
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.
Perhaps, doing that through the browser would be the best.
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.
Do a git pull
, git will merge the changes made here to your local branch. That should work without further complications because there should be no merge conflicts. After that, try git push
again.
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.
Yes, I did it (via browser) :) Thanks a lot!
That's strange. What error did you get? Maybe we can figure it out :) |
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.
Thanks a lot for your work and patience. There was a minor merge conflict that I solved on your branch, this should be ready to be merged now.
Thank you so much for everything! |
All of the links take you to the _hf_hub.py file. I must add specific lines.