Skip to content

Commit fd02899

Browse files
Bugfix/pyobject fix (#17)
* Change ModuleAnalyzer.for_file to for_string * Add a test for the pyobject to make sure it is working * Change \n in tests to os.linesep * Run black, add black to dev requirements * Remove sphinx pytest extensions since that is what was breaking with jinja>=3 * Fix github workflow file * Delete no longere needed files from test dir * Squashed commit of the following: commit 1363aad Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:25:17 2022 -0400 Return workflow.yml on section commit abb513c Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:18:51 2022 -0400 Messing with install requirements for testing commit 8073cde Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:17:28 2022 -0400 Messing with install requirements for testing commit b52b648 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:15:54 2022 -0400 Messing with install requirements for testing commit 73d9392 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:11:31 2022 -0400 Fix python versions in matrix for workflow commit 99317f6 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:10:22 2022 -0400 Fix matrix for workflow commit e1d7519 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:08:18 2022 -0400 Update sphinx req for py3.10 commit 5c4e8d0 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 20:02:30 2022 -0400 Update pytest to a version that works with python 3.6-3.10 commit d11ffa0 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:51:09 2022 -0400 reformat and remove 3.10 from testing commit 3e7fcf8 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:46:52 2022 -0400 Add markupsafe req in setup.py commit 85b2e6e Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:42:03 2022 -0400 update jinja2 setup req commit 0cd5ef9 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:38:30 2022 -0400 update dev requirements file commit 254a0f1 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:35:56 2022 -0400 Modify github workflow matrix to reflect sphinx version requirements commit 259f590 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:20:57 2022 -0400 sphinx versioning in setup.py commit 79fc201 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 19:18:00 2022 -0400 lock jinja2 to 2.0 for py<3.8 commit f5d64cc Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:15:45 2022 -0400 Update minimum sphinx ver to 3 commit a6ce9d1 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:12:25 2022 -0400 Update jinja2 version to be dependent on your python version commit 54b5e6f Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:09:30 2022 -0400 Update jinja2 version to be dependent on your python version commit 5e0345a Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:05:13 2022 -0400 Readd sphinx building tests commit 715ea8b Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:02:57 2022 -0400 Revert "Delete no longere needed files from test dir" This reverts commit 9566cc3. commit 5a636d1 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:02:47 2022 -0400 Revert "Remove unneeded sphinx things to check if it is causing fails" This reverts commit 6d43529. commit 6d43529 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 18:01:05 2022 -0400 Remove unneeded sphinx things to check if it is causing fails commit 37acbf5 Author: Madeline Scyphers <madelinescyphers@gmail.com> Date: Mon Jul 18 12:35:03 2022 -0400 Ci testing
1 parent d055699 commit fd02899

5 files changed

Lines changed: 61 additions & 8 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,21 @@ jobs:
2525
runs-on: ubuntu-latest
2626
strategy:
2727
matrix:
28-
python-version: ['3.6', '3.7', '3.8', '3.9', 'pypy3']
29-
sphinx-version: ['2', '3']
28+
python-version: ['3.8', '3.9', 'pypy3']
29+
sphinx-version: ['4', '5']
30+
include:
31+
- python-version: '3.10'
32+
sphinx-version: '4.3'
33+
- python-version: '3.10'
34+
sphinx-version: '5'
35+
- python-version: '3.6'
36+
sphinx-version: '3'
37+
- python-version: '3.7'
38+
sphinx-version: '3'
39+
- python-version: '3.6'
40+
sphinx-version: '2'
41+
- python-version: '3.7'
42+
sphinx-version: '2'
3043
name: "Test Extension - Python(${{ matrix.python-version }}), Sphinx(${{ matrix.sphinx-version }})"
3144
steps:
3245
- uses: actions/checkout@v2

dev-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sphinx
2-
six
3-
pytest==5.4.3
1+
-e .
2+
black
3+
pytest==6.2.5
44
wheel==0.34.2

setup.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
long_description=long_description,
2727
long_description_content_type="text/markdown",
2828
url="https://github.com/wpilibsuite/sphinxext-remoteliteralinclude",
29-
install_requires=["sphinx>=2.0", "six"],
29+
install_requires=[
30+
"sphinx>=4.3;python_version>='3.10'",
31+
"jinja2<3;python_version<'3.8'",
32+
"MarkupSafe<=2.0.1;python_version<'3.8'",
33+
"six",
34+
],
3035
packages=["sphinxext"],
3136
classifiers=[
3237
"Development Status :: 5 - Production/Stable",
@@ -40,12 +45,14 @@
4045
"Programming Language :: Python :: 3.6",
4146
"Programming Language :: Python :: 3.7",
4247
"Programming Language :: Python :: 3.8",
48+
"Programming Language :: Python :: 3.9",
49+
"Programming Language :: Python :: 3.10",
4350
"Programming Language :: Python",
4451
"Topic :: Documentation :: Sphinx",
4552
"Topic :: Documentation",
4653
"Topic :: Software Development :: Documentation",
4754
"Topic :: Text Processing",
4855
"Topic :: Utilities",
4956
],
50-
python_requires=">=3.4",
57+
python_requires=">=3.6",
5158
)

sphinxext/remoteliteralinclude.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,14 @@ def pyobject_filter(self, lines, location=None):
118118
if pyobject:
119119
from sphinx.pycode import ModuleAnalyzer
120120

121-
analyzer = ModuleAnalyzer.for_file(self.url, "")
121+
# read the url in as a string
122+
response = requests.get(self.url)
123+
text = response.text
124+
# initialize the module analyzer with the file in string form
125+
analyzer = ModuleAnalyzer.for_string(text, "")
126+
122127
tags = analyzer.find_tags()
128+
# Check the pyobject passed is in the tags
123129
if pyobject not in tags:
124130
raise ValueError(
125131
__("Object named %r not found in include file %r")

tests/test_options.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import os
12
import pytest
23
from sphinx.application import Sphinx
34
from sphinx import version_info
5+
from sphinx.config import Config
6+
from sphinxext.remoteliteralinclude import RemoteLiteralIncludeReader
7+
8+
9+
DUMMY_CONFIG = Config({}, {})
410

511

612
@pytest.mark.sphinx("html", testroot="simple-short")
@@ -25,6 +31,27 @@ def test_simple_full(app: Sphinx):
2531
assert html in content
2632

2733

34+
def test_pyobject():
35+
url = "https://raw.githubusercontent.com/wpilibsuite/sphinxext-remoteliteralinclude/main/sphinxext/remoteliteralinclude.py"
36+
# Grab the entire RemoteLiteralIncludeReader.__init__
37+
options = {"pyobject": "RemoteLiteralIncludeReader.__init__"}
38+
reader = RemoteLiteralIncludeReader(url, options, DUMMY_CONFIG)
39+
content, lines = reader.read()
40+
41+
# only check the first line to be less susceptible to breaking with code changes
42+
first_line = " def __init__(self, url, options, config):"
43+
assert content.splitlines()[0] == first_line
44+
45+
# we grab just the second line from `RemoteLiteralIncludeReader`
46+
options = {"pyobject": "RemoteLiteralIncludeReader", "lines": "2-2"}
47+
reader = RemoteLiteralIncludeReader(url, options, DUMMY_CONFIG)
48+
content, lines = reader.read()
49+
50+
# we use os.linesep to replace with \n on posix and \r\n on windows
51+
second_line = f" INVALID_OPTIONS_PAIR = [{os.linesep}" # this keeps \n because no splitlines
52+
assert content == second_line
53+
54+
2855
def read_text(app: Sphinx):
2956
if version_info[:2] < (3, 0):
3057
return (app.outdir / "index.html").text().replace("\n", "")

0 commit comments

Comments
 (0)