Skip to content

Commit

Permalink
Bugfix/pyobject fix (#17)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Date:   Mon Jul 18 20:25:17 2022 -0400

    Return workflow.yml on section

commit abb513c
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:18:51 2022 -0400

    Messing with install requirements for testing

commit 8073cde
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:17:28 2022 -0400

    Messing with install requirements for testing

commit b52b648
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:15:54 2022 -0400

    Messing with install requirements for testing

commit 73d9392
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:11:31 2022 -0400

    Fix python versions in matrix for workflow

commit 99317f6
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:10:22 2022 -0400

    Fix matrix for workflow

commit e1d7519
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 20:08:18 2022 -0400

    Update sphinx req for py3.10

commit 5c4e8d0
Author: Madeline Scyphers <[email protected]>
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 <[email protected]>
Date:   Mon Jul 18 19:51:09 2022 -0400

    reformat and remove 3.10 from testing

commit 3e7fcf8
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:46:52 2022 -0400

    Add markupsafe req in setup.py

commit 85b2e6e
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:42:03 2022 -0400

    update jinja2 setup req

commit 0cd5ef9
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:38:30 2022 -0400

    update dev requirements file

commit 254a0f1
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:35:56 2022 -0400

    Modify github workflow matrix to reflect sphinx version requirements

commit 259f590
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:20:57 2022 -0400

    sphinx versioning in setup.py

commit 79fc201
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 19:18:00 2022 -0400

    lock jinja2 to 2.0 for py<3.8

commit f5d64cc
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 18:15:45 2022 -0400

    Update minimum sphinx ver to 3

commit a6ce9d1
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 18:12:25 2022 -0400

    Update jinja2 version to be dependent on your python version

commit 54b5e6f
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 18:09:30 2022 -0400

    Update jinja2 version to be dependent on your python version

commit 5e0345a
Author: Madeline Scyphers <[email protected]>
Date:   Mon Jul 18 18:05:13 2022 -0400

    Readd sphinx building tests

commit 715ea8b
Author: Madeline Scyphers <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date:   Mon Jul 18 12:35:03 2022 -0400

    Ci testing
  • Loading branch information
madeline-scyphers authored Jul 22, 2022
1 parent d055699 commit fd02899
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,21 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', 'pypy3']
sphinx-version: ['2', '3']
python-version: ['3.8', '3.9', 'pypy3']
sphinx-version: ['4', '5']
include:
- python-version: '3.10'
sphinx-version: '4.3'
- python-version: '3.10'
sphinx-version: '5'
- python-version: '3.6'
sphinx-version: '3'
- python-version: '3.7'
sphinx-version: '3'
- python-version: '3.6'
sphinx-version: '2'
- python-version: '3.7'
sphinx-version: '2'
name: "Test Extension - Python(${{ matrix.python-version }}), Sphinx(${{ matrix.sphinx-version }})"
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sphinx
six
pytest==5.4.3
-e .
black
pytest==6.2.5
wheel==0.34.2
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/wpilibsuite/sphinxext-remoteliteralinclude",
install_requires=["sphinx>=2.0", "six"],
install_requires=[
"sphinx>=4.3;python_version>='3.10'",
"jinja2<3;python_version<'3.8'",
"MarkupSafe<=2.0.1;python_version<'3.8'",
"six",
],
packages=["sphinxext"],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand All @@ -40,12 +45,14 @@
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python",
"Topic :: Documentation :: Sphinx",
"Topic :: Documentation",
"Topic :: Software Development :: Documentation",
"Topic :: Text Processing",
"Topic :: Utilities",
],
python_requires=">=3.4",
python_requires=">=3.6",
)
8 changes: 7 additions & 1 deletion sphinxext/remoteliteralinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ def pyobject_filter(self, lines, location=None):
if pyobject:
from sphinx.pycode import ModuleAnalyzer

analyzer = ModuleAnalyzer.for_file(self.url, "")
# read the url in as a string
response = requests.get(self.url)
text = response.text
# initialize the module analyzer with the file in string form
analyzer = ModuleAnalyzer.for_string(text, "")

tags = analyzer.find_tags()
# Check the pyobject passed is in the tags
if pyobject not in tags:
raise ValueError(
__("Object named %r not found in include file %r")
Expand Down
27 changes: 27 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
import pytest
from sphinx.application import Sphinx
from sphinx import version_info
from sphinx.config import Config
from sphinxext.remoteliteralinclude import RemoteLiteralIncludeReader


DUMMY_CONFIG = Config({}, {})


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


def test_pyobject():
url = "https://raw.githubusercontent.com/wpilibsuite/sphinxext-remoteliteralinclude/main/sphinxext/remoteliteralinclude.py"
# Grab the entire RemoteLiteralIncludeReader.__init__
options = {"pyobject": "RemoteLiteralIncludeReader.__init__"}
reader = RemoteLiteralIncludeReader(url, options, DUMMY_CONFIG)
content, lines = reader.read()

# only check the first line to be less susceptible to breaking with code changes
first_line = " def __init__(self, url, options, config):"
assert content.splitlines()[0] == first_line

# we grab just the second line from `RemoteLiteralIncludeReader`
options = {"pyobject": "RemoteLiteralIncludeReader", "lines": "2-2"}
reader = RemoteLiteralIncludeReader(url, options, DUMMY_CONFIG)
content, lines = reader.read()

# we use os.linesep to replace with \n on posix and \r\n on windows
second_line = f" INVALID_OPTIONS_PAIR = [{os.linesep}" # this keeps \n because no splitlines
assert content == second_line


def read_text(app: Sphinx):
if version_info[:2] < (3, 0):
return (app.outdir / "index.html").text().replace("\n", "")
Expand Down

0 comments on commit fd02899

Please sign in to comment.