Skip to content

Commit fd833ff

Browse files
committed
Update project structure and dependencies
1 parent 15d8dda commit fd833ff

14 files changed

+323
-389
lines changed

Diff for: .github/workflows/ci.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,33 @@ on:
55
pull_request:
66

77
jobs:
8-
test-sqlite:
8+
test:
99
name: py-${{ matrix.python }}
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
1313
include:
14-
- python: "3.9"
14+
- python: "3.11"
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1818
- name: Set up Python ${{ matrix.python }}
19-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: ${{ matrix.python }}
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
2525
pip install -r requirements-dev.txt
26+
- name: Set Python path
27+
run: |
28+
echo "PYTHONPATH=." >> $GITHUB_ENV
2629
- name: Test
2730
run: |
2831
pytest
2932
- name: Upload coverage to Codecov
30-
uses: codecov/codecov-action@v1
33+
uses: codecov/codecov-action@v4
3134
with:
3235
name: ${{ matrix.python }}
36+
env:
37+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Diff for: .github/workflows/pypi.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ jobs:
1010
name: Build and publish to PyPI
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Set up Python 3.9
15-
uses: actions/setup-python@v2
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
1615
with:
17-
python-version: 3.9
16+
python-version: 3.11
1817
- name: Install dependencies
1918
run: |
2019
python -m pip install --upgrade pip
21-
pip install setuptools wheel
20+
pip install --upgrade setuptools build wheel
2221
- name: Build a binary wheel and a source tarball
2322
run: |
24-
python setup.py sdist bdist_wheel
23+
python -m build
2524
- name: Publish to PyPI
2625
if: startsWith(github.ref, 'refs/tags')
27-
uses: pypa/gh-action-pypi-publish@master
28-
with:
29-
password: ${{ secrets.pypi_password }}
26+
uses: pypa/gh-action-pypi-publish@release/v1

Diff for: .pre-commit-config.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exclude: .*migrations\/.*
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.4.0
5+
hooks:
6+
- id: check-merge-conflict
7+
- id: trailing-whitespace
8+
- repo: https://github.com/pycqa/isort
9+
rev: 5.12.0
10+
hooks:
11+
- id: isort
12+
name: isort (python)
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.3.4
15+
hooks:
16+
# Run the linter.
17+
- id: ruff
18+
# Run the formatter.
19+
- id: ruff-format

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Sphinx-Gitref is licensed under the BSD License (BSD-3-Clause)
22
================================================================
33

4-
Copyright (c) 2020, Wildfish, https://wildfish.com
4+
Copyright (c) 2020, Richard Terry, https://radiac.net/
55

66
All rights reserved.
77

Diff for: README.md

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Sphinx Gitref
2+
3+
4+
[![PyPI](https://img.shields.io/pypi/v/sphinx-gitref.svg)](https://pypi.org/project/sphinx-gitref/)
5+
[![Tests](https://github.com/radiac/sphinx-gitref/actions/workflows/ci.yml/badge.svg)](https://github.com/radiac/sphinx-gitref/actions/workflows/ci.yml)
6+
[![Coverage](https://codecov.io/gh/radiac/sphinx-gitref/branch/main/graph/badge.svg?token=Q9AKPHRJF5)](https://codecov.io/gh/radiac/sphinx-gitref)
7+
8+
Adds a `` :gitref:`..` `` role to sphinx to link to your code on GitHub, GitLab or
9+
Bitbucket, and to make sure the references in your docs match the code.
10+
11+
Key features:
12+
13+
* Check code references are up to date
14+
* Link to source code on github
15+
* Incorporate into tests or git hooks
16+
17+
Supports Python 3.6+
18+
19+
20+
Installation
21+
============
22+
23+
Install::
24+
25+
pip install sphinx-gitref
26+
27+
28+
Modify your Sphinx ``conf.py``:
29+
30+
1. Add ``sphinx_gitref`` to the ``extensions`` list in your Sphinx ``conf.py``:
31+
32+
33+
```python
34+
extensions = [
35+
...
36+
'sphinx_gitref',
37+
]
38+
```
39+
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` ``
62+
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+
70+
## Usage
71+
72+
The `` :gitref:`..` `` role supports the following features:
73+
74+
* `` :gitref:`path/to/filename` ``
75+
* `` :gitref:`path/to/filename.py::coderef` ``
76+
77+
You can optionally use them with a text label:
78+
79+
* `` :gitref:`text <path/to/filename>` ``
80+
* `` :gitref:`text <path/to/filename.py::coderef>` ``
81+
82+
where ``coderef`` is a Python class, function or variable. You can also refer to class
83+
attributes as you would in python, eg ``MyClass.attribute``.
84+
85+
These will be replaced by a link to the code.
86+
87+
If you do not provide a ``coderef``, gitref will just check that the file exists.
88+
89+
Where you provide a ``coderef``, gitref will check that an object with that name exists
90+
in the code, and will add its line number to the link.
91+
92+
93+
### Examples
94+
95+
Link to a file on gitref::
96+
97+
```
98+
This file is :gitref:`README.rst`
99+
For more information, see the :gitref:`project README <README.rst>`
100+
```
101+
102+
Link to a variable, function or class in a python file::
103+
104+
```
105+
The method which turns a reference into a line number
106+
is :gitref:`sphinx_python/parse.py::python_to_lineno` -
107+
this will raise a warning if the reference is not found.
108+
109+
Reference class attributes as you would in Python, such
110+
as :gitref:`sphinx_python/git.py::Repo.path`.
111+
```
112+
113+
### Using in tests
114+
115+
Because ``sphinx-gitref`` integrates into Sphinx, you can test the references are valid
116+
by performing a test build of your documentation.
117+
118+
119+
### Custom remotes
120+
121+
If your code is stored somewhere other than one of the supported platforms, you can add
122+
a custom remote by subclassing ``sphinx_github.remotes.Remote`` in your Sphinx
123+
``conf.py``; for example::
124+
125+
```python
126+
from sphinx_github.remotes import Remote
127+
class Gitea(Remote):
128+
remote_match = re.compile(r"^git@gitea.example.com:(?P<repo>.+?)\.git$")
129+
url_pattern = "https://gitea.example.com/{repo}/blob/{branch}/{filename}{line}"
130+
url_pattern_line = "#L{line}"
131+
```
132+
133+
134+
## Changelog
135+
136+
0.3.0 - 2024-05-19
137+
* Support latest Sphinx
138+
139+
0.2.1 - 2022-02-19
140+
* Improve repository pattern matching
141+
142+
0.2.0 - 2022-02-13
143+
* Add custom label formatting with ``gitref_label_format``
144+
* Fix bug when node target has no id
145+
* Improve branch detection to support a recently detached ``HEAD``
146+
147+
0.1.0 - 2020-04-18
148+
* Initial release

Diff for: README.rst

-153
This file was deleted.

0 commit comments

Comments
 (0)