Skip to content

Commit d6355fb

Browse files
committed
Better branch naming, added pygit2
1 parent 11c5fbb commit d6355fb

5 files changed

Lines changed: 73 additions & 19 deletions

File tree

docs/source/conf.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import inspect
1616
import subprocess
1717
from os.path import relpath, dirname
18+
from pygit2 import Repository
1819

1920
import gnss_lib_py
2021

@@ -114,32 +115,38 @@
114115

115116
# Function to find URLs for the source code on GitHub for built docs
116117

117-
# The following code to find the head tag is taken from:
118+
# The original code to find the head tag was taken from:
118119
# https://gist.github.com/nlgranger/55ff2e7ff10c280731348a16d569cb73
119-
120-
linkcode_revision = "main"
120+
# This code was modified to use branch names when the code differs from
121+
# main or a tag
122+
123+
#Default to the main branch
124+
branch_name = "main"
125+
126+
127+
branch_name = Repository('.').head.shorthand
128+
# lock to commit number
129+
cmd = "git log -n1 --pretty=%H"
130+
head = subprocess.check_output(cmd.split()).strip().decode('utf-8')
131+
linkcode_revision = head
132+
# if we are on main's HEAD, use main as reference irrespective of
133+
# what branch you are on
134+
cmd = "git log --first-parent main -n1 --pretty=%H"
135+
main = subprocess.check_output(cmd.split()).strip().decode('utf-8')
136+
if head == main:
137+
branch_name = "main"
138+
139+
# if we have a tag, use tag as reference, irrespective of what branch
140+
# you are actually on
121141
try:
122-
# lock to commit number
123-
cmd = "git log -n1 --pretty=%H"
124-
head = subprocess.check_output(cmd.split()).strip().decode('utf-8')
125-
linkcode_revision = head
126-
127-
# if we are on main's HEAD, use main as reference
128-
cmd = "git log --first-parent main -n1 --pretty=%H"
129-
main = subprocess.check_output(cmd.split()).strip().decode('utf-8')
130-
if head == main:
131-
linkcode_revision = "main"
132-
133-
# if we have a tag, use tag as reference
134142
cmd = "git describe --exact-match --tags " + head
135143
tag = subprocess.check_output(cmd.split(" ")).strip().decode('utf-8')
136-
linkcode_revision = tag
137-
144+
branch_name = tag
138145
except subprocess.CalledProcessError:
139146
pass
140147

141148
linkcode_url = "https://github.com/Stanford-NavLab/gnss_lib_py/blob/" \
142-
+ linkcode_revision + "/{filepath}#L{linestart}-L{linestop}"
149+
+ branch_name + "/{filepath}#L{linestart}-L{linestop}"
143150

144151

145152
def linkcode_resolve(domain, info):

docs/source/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ psutil==5.9.5 ; python_version >= "3.8" and python_version < "3.12"
9595
ptyprocess==0.7.0 ; python_version >= "3.8" and python_version < "3.12" and os_name != "nt" or python_version >= "3.8" and python_version < "3.12" and sys_platform != "win32"
9696
pure-eval==0.2.2 ; python_version >= "3.8" and python_version < "3.12"
9797
pycparser==2.21 ; python_version >= "3.8" and python_version < "3.12"
98+
pygit2==1.12.2 ; python_version >= "3.8" and python_version < "3.12"
9899
pygments==2.15.1 ; python_version >= "3.8" and python_version < "3.12"
99100
pylint-exit==1.2.0 ; python_version >= "3.8" and python_version < "3.12"
100101
pylint==2.17.4 ; python_version >= "3.8" and python_version < "3.12"

poetry.lock

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ matplotlib = "^3.5.1"
3535
plotly = "^5.8.0"
3636
kaleido = "0.2.1"
3737
requests = "^2.29.0"
38+
pygit2 = "^1.12.2"
3839

3940
[tool.poetry.group.dev.dependencies]
4041
Sphinx = "^4.1.1"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ psutil==5.9.5 ; python_version >= "3.8" and python_version < "3.12"
8888
ptyprocess==0.7.0 ; python_version >= "3.8" and python_version < "3.12" and os_name != "nt" or python_version >= "3.8" and python_version < "3.12" and sys_platform != "win32"
8989
pure-eval==0.2.2 ; python_version >= "3.8" and python_version < "3.12"
9090
pycparser==2.21 ; python_version >= "3.8" and python_version < "3.12"
91+
pygit2==1.12.2 ; python_version >= "3.8" and python_version < "3.12"
9192
pygments==2.15.1 ; python_version >= "3.8" and python_version < "3.12"
9293
pylint==2.17.4 ; python_version >= "3.8" and python_version < "3.12"
9394
pynmea2==1.19.0 ; python_version >= "3.8" and python_version < "3.12"

0 commit comments

Comments
 (0)