Skip to content
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

Merged
merged 9 commits into from
Oct 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import inspect
import os
import subprocess
from operator import attrgetter

from packaging.version import parse
Expand Down Expand Up @@ -70,17 +71,25 @@
# (note that `group` is the GitHub user or organization)
issues_github_path = "skops-dev/skops"

REVISION_CMD = "git rev-parse --short HEAD"

def linkcode_resolve(domain, info):
if domain != "py":
return None
if not info["module"]:

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
filename = info["module"].replace(".", "/")
if domain not in ("py", "pyx"):
return
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 :)

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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!

return revision.decode("utf-8")


def linkcode_resolve(domain, info):
if not info.get("module") or not info.get("fullname"):
return
revision = _get_git_revision()

if revision is None:
return

class_name = info["fullname"].split(".")[0]
module = __import__(info["module"], fromlist=[class_name])
Expand All @@ -93,7 +102,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
Expand All @@ -105,9 +114,11 @@ 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/skops-dev/skops/blob/{revision}/{package}/{path}#L{lineno}"
)
revision = _get_git_revision()
return url_fmt.format(revision=revision, package=package, path=fn, lineno=lineno)


# -- Options for HTML output -------------------------------------------------
Expand Down