Skip to content

Commit b9ea794

Browse files
TheTripleVDaltz333
andauthored
Finish Implementation (#1)
* impl + tests * Fix dirhtml redirects to index.html * run black * Simplify error messages * Simplify dirhtml handling * add jinja support * Update instructions * Add details to readme * add function descriptions * add ci * ci fix os names * ci fix * Remove Pypy3 testing * Fix Formatting * Add testing section to readme * readme: Add supported builders * Fix and Add test for bad jinja template path * run black * Add missing method * run black * Add default values to stub func args * builder: Add hint for renamed files * Update setup.py Co-authored-by: Dalton Smith <[email protected]> * readme: mention rediraffe_branch can be a commit Co-authored-by: Dalton Smith <[email protected]>
1 parent bfcca35 commit b9ea794

File tree

130 files changed

+1880
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1880
-80
lines changed

.github/workflows/ci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: ci
2+
on: [push, pull_request]
3+
4+
jobs:
5+
check-format:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- uses: actions/setup-python@v2
10+
with:
11+
python-version: 3.8
12+
- name: Install Black
13+
run: |
14+
pip install black
15+
- name: Run Black
16+
run: |
17+
black --check --diff .
18+
19+
test:
20+
name: "Build (${{ matrix.os }} Python ${{ matrix.python-version }})"
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
matrix:
24+
os: [ubuntu-latest, windows-latest, macos-latest]
25+
python-version: ['3.6', '3.7', '3.8']
26+
steps:
27+
- uses: actions/checkout@v2
28+
- name: Setup Python
29+
uses: actions/setup-python@v2
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
- name: Install dev dependencies
33+
shell: bash
34+
run: |
35+
set -xe
36+
python -VV
37+
python -m site
38+
python -m pip install --upgrade pip setuptools wheel
39+
python -m pip install -r dev-requirements.txt
40+
- name: Build wheel
41+
run: |
42+
python setup.py bdist_wheel
43+
- name: Install wheel
44+
shell: bash
45+
run: |
46+
python -m pip install dist/*.whl
47+
- name: Install test dependencies
48+
run: |
49+
python -m pip install -r test-requirements.txt
50+
- name: Run Tests
51+
run: |
52+
cd tests
53+
python -m pytest -vv --headless
54+
55+
pypi-release:
56+
if: startsWith(github.ref, 'refs/tags/v') && github.repository_owner == 'wpilibsuite'
57+
needs: test
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v2
61+
with:
62+
fetch-depth: 0
63+
- name: Set up Python
64+
uses: actions/setup-python@v2
65+
with:
66+
python-version: '3.7'
67+
- name: Install Dependencies
68+
run: |
69+
python -m pip install --upgrade pip setuptools wheel
70+
python -m pip install -r dev-requirements.txt
71+
- name: Build PyPI Wheel
72+
run: |
73+
python setup.py sdist
74+
python setup.py bdist_wheel
75+
- name: Publish a Python distribution to PyPI
76+
uses: pypa/gh-action-pypi-publish@master
77+
with:
78+
user: __token__
79+
password: ${{ secrets.pypi_password }}

README.md

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33

44
Sphinx Extension to redirect files
55

6+
![Rediraffe](assets/rediraffe_logo.svg)
7+
8+
This sphinx extension redirects non-existent pages to working pages.
9+
Additionally, a builder is provided to check that deleted/renamed files in your git repo are redirected.
10+
11+
Rediraffe supports the html and dirhtml builders.
12+
13+
Note: Chained redirects will be resolved. For example, if a config has 6 chained redirects, all 6 links will redirect directly to the final link. The enduser will never experience more than 1 redirection.
14+
615
## Installation
716

8-
`python -m pip install https://github.com/TheTripleV/sphinxext-rediraffe`
17+
`python -m pip install git+https://github.com/wpilibsuite/sphinxext-rediraffe.git`
18+
919

1020
## Usage
1121
Add `sphinxext.rediraffe` to your extensions list in your `conf.py`
@@ -15,17 +25,94 @@ extensions = [
1525
sphinxext.rediraffe,
1626
]
1727
```
18-
<!-- ## Options
28+
29+
To check that deleted/renamed files in your git repo are in your redirects,
30+
1. Make sure `rediraffe_branch` and `rediraffe_redirects` are set in conf.py.
31+
2. Run the `rediraffecheckdiff` builder.
32+
33+
## Options
1934
These values are placed in the conf.py of your sphinx project.
2035

21-
* `linkcheckdiff_branch`
22-
* Required. The branch to diff against.
36+
* `rediraffe_branch`
37+
* Required for rediraffecheckdiff builder. The branch or commit to diff against.
38+
39+
* `rediraffe_redirects`
40+
* Required. A filename or dict containing redirects
2341

24-
Note: linkcheckdiff is an extension of the linkcheck builder that ships with Sphinx. linkcheckdiff respects all of linkcheck's configuration options.
42+
* `rediraffe_template`
43+
* Optional. A jinja template to use to render the inserted redirecting files. If not specified, a default template will be used. This template will only be accessed after the html/htmldir builder is finished; Therefore, this file may be generated as part of your build.
44+
* variables available to rediraffe_template:
45+
* `from_file` - the file being redirected as written in rediraffe_redirects.
46+
* `to_file` - the destination file that from_file is redirected to as written in rediraffe_redirects.
47+
* `from_url` - the path to from_url's html file (built by rediraffe) relative to the outdir.
48+
* `to_url` - the path to to_url's built html file relative to the outdir.
49+
* `rel_url` - the relative path from from_url to to_url.
2550

2651

2752
## Example Config
2853

54+
### redirects only (file)
55+
56+
conf.py:
57+
```python
58+
rediraffe_redirects = "redirects.txt"
59+
```
60+
61+
redirects.txt:
62+
```
63+
another.rst index.rst
64+
another2.rst another.rst
65+
```
66+
67+
### redirects only (dict)
68+
69+
conf.py:
2970
```python
30-
linkcheckdiff_branch = "master"
31-
``` -->
71+
rediraffe_redirects = {
72+
"another.rst": "index.rst",
73+
"another2.rst": "another.rst",
74+
}
75+
```
76+
77+
### redirects + diff checker
78+
79+
conf.py:
80+
```python
81+
rediraffe_redirects = "redirects.txt"
82+
rediraffe_branch = "master~1"
83+
```
84+
85+
### redirects with jinja template
86+
87+
conf.py:
88+
```python
89+
rediraffe_redirects = "redirects.txt"
90+
rediraffe_template = "template.html"
91+
```
92+
93+
template.html:
94+
```html
95+
<html>
96+
<body>
97+
<p>Your destination is {{to_url}}</p>
98+
</body>
99+
</html>
100+
```
101+
102+
A complex example can be found at tests/roots/ext/.
103+
104+
## Testing
105+
106+
Rediraffe uses pytest for testing.
107+
To run tests:
108+
1. Install this package
109+
2. Install test dependencies
110+
```bash
111+
python -m pip install -r test-requirements.txt
112+
```
113+
3. Navigate to the tests directory and run
114+
```bash
115+
python -m pytest --headless
116+
```
117+
118+
The `--headless` flag ensures that a browser window does not open during browser backed selenium testing.

assets/rediraffe_logo.svg

Lines changed: 44 additions & 0 deletions
Loading

assets/rediraffe_logo_1024.png

115 KB
Loading

assets/rediraffe_logo_128.png

12 KB
Loading

assets/rediraffe_logo_2048.png

255 KB
Loading

assets/rediraffe_logo_256.png

24.9 KB
Loading

assets/rediraffe_logo_4096.png

569 KB
Loading

assets/rediraffe_logo_512.png

53.1 KB
Loading

assets/rediraffe_logo_64.png

5.97 KB
Loading

0 commit comments

Comments
 (0)