@@ -14,21 +14,17 @@ Key features:
14
14
* Link to source code on github
15
15
* Incorporate into tests or git hooks
16
16
17
- Supports Python 3.6 +
17
+ Supports Python 3.7 +
18
18
19
19
20
- Installation
21
- ============
20
+ ## Installation
22
21
23
22
Install::
24
23
25
24
pip install sphinx-gitref
26
25
27
26
28
- Modify your Sphinx `` conf.py `` :
29
-
30
- 1 . Add `` sphinx_gitref `` to the `` extensions `` list in your Sphinx `` conf.py `` :
31
-
27
+ In your Sphinx `` conf.py `` , add `` sphinx_gitref `` to the `` extensions `` list:
32
28
33
29
``` python
34
30
extensions = [
@@ -37,35 +33,9 @@ Modify your Sphinx ``conf.py``:
37
33
]
38
34
```
39
35
40
- 2 . Optional: Explicitly specify the remote URL.
41
-
42
- Gitref will try to detect your remote origin URL from the `` .git `` dir in your docs'
43
- parent dir. If it can't find it, or detects the wrong remote, you can set or override
44
- the remote URL explicitly with::
45
-
46
- ``` python
47
- gitref_remote_url = " https://github.com/username/repository.git"
48
- ```
49
-
50
- 3 . Optional: Explicitly specify the branch to link to.
51
-
52
- Gitref will try to detect your current branch from the `` .git `` dir in your docs'
53
- parent dir. If it can't find it, or you'd like it to use a different branch, you can
54
- set or override it explicitly with::
55
-
56
- ``` python
57
- gitref_branch = " master"
58
- ```
59
-
60
- 4 . Optional: Change the link label format when a coderef is provided without an
61
- explicit label, eg `` :gitref:`filename.py::coderef` ``
36
+ Gitref should now work for most projects, but see "Configuration" below to customise its
37
+ defaults.
62
38
63
- Gitref defaults to using showing the coderef and dropping the filename. This can be
64
- overridden by setting a format string::
65
-
66
- ``` python
67
- gitref_label_format = " {filename} {coderef} "
68
- ```
69
39
70
40
## Usage
71
41
@@ -131,9 +101,71 @@ class Gitea(Remote):
131
101
```
132
102
133
103
104
+ ## Configuration
105
+
106
+ Define the following variables in Sphinx `` conf.py `` .
107
+
108
+
109
+ ### `` gitref_relative_project_root ``
110
+
111
+ Explicitly specify the relative path to the project root form your docs' source dir.
112
+
113
+ The project root is the root directory of your git repository.
114
+
115
+ Gitref will walk up the directory tree from your documentation source, looking for the
116
+ first directory with a `` .git `` dir. It will use this as the project root.
117
+
118
+ If it mis-detects the path, you can configure it with a relative path. For example, if
119
+ your docs are in `` docs/ `` , you can specify one parent up as:
120
+
121
+ ``` python
122
+ gitref_relative_project_root = " .."
123
+ ```
124
+
125
+
126
+ ### `` gitref_remote_url ``
127
+
128
+ Explicitly specify the remote URL.
129
+
130
+ Gitref will try to detect your remote origin URL from the `` .git `` dir in your project
131
+ root. If it can't find it, or detects the wrong remote, you can set or override the
132
+ remote URL explicitly with:
133
+
134
+ ``` python
135
+ gitref_remote_url = " https://github.com/username/repository.git"
136
+ ```
137
+
138
+
139
+ ### `` gitref_branch ``
140
+
141
+ Explicitly specify the branch to link to.
142
+
143
+ Gitref will try to detect your current branch from the `` .git `` dir in your project
144
+ root. If it can't find it, or you'd like it to use a different branch, you can set or
145
+ override it explicitly with::
146
+
147
+ ``` python
148
+ gitref_branch = " master"
149
+ ```
150
+
151
+ ### `` gitref_label_format ``
152
+
153
+ Change the link label format when a coderef is provided without an explicit label, eg
154
+ `` :gitref:`filename.py::coderef` ``
155
+
156
+ Gitref defaults to using showing the coderef and dropping the filename. This can be
157
+ overridden by setting a format string::
158
+
159
+ ``` python
160
+ gitref_label_format = " {filename} {coderef} "
161
+ ```
162
+
163
+
164
+
134
165
## Changelog
135
166
136
167
0.3.0 - 2024-05-19
168
+ * Better project root detection with override support (fixes #12 )
137
169
* Support latest Sphinx
138
170
139
171
0.2.1 - 2022-02-19
0 commit comments