Skip to content

Commit

Permalink
🔧 remove unnecessary checks for sphinx versions <5 (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Aug 28, 2024
1 parent 58fee42 commit 0ddb5e7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 105 deletions.
10 changes: 2 additions & 8 deletions sphinx_needs/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Iterable, Sequence

from docutils import nodes
from sphinx import version_info
from sphinx.application import Sphinx
from sphinx.builders import Builder

Expand Down Expand Up @@ -286,12 +285,7 @@ def build_needumls_pumls(app: Sphinx, _exception: Exception) -> None:
return

# if other builder like html used together with config: needs_build_needumls
if version_info[0] >= 5:
needs_builder = NeedumlsBuilder(app, env)
needs_builder.outdir = os.path.join(needs_builder.outdir, config.build_needumls)
else:
needs_builder = NeedumlsBuilder(app)
needs_builder.outdir = os.path.join(needs_builder.outdir, config.build_needumls)
needs_builder.set_environment(env)
needs_builder = NeedumlsBuilder(app, env)
needs_builder.outdir = os.path.join(needs_builder.outdir, config.build_needumls)

needs_builder.finish()
133 changes: 62 additions & 71 deletions tests/test_needs_external_needs_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
import responses
import sphinx
from docutils import __version__ as doc_ver


Expand Down Expand Up @@ -114,32 +113,29 @@ def test_external_needs_base_url_relative_path(test_app):
assert root_table_hrefs[4].text == "EXT_TEST_01"

# check needflow usage for base_url in root level
if not sphinx.__version__.startswith("3.5"):
if int(doc_ver.split(".")[1]) >= 18:
root_flow_hrefs = root_tree.xpath("//figure/p/object/a/img")
assert (
root_tree.xpath("//figure/figcaption/p/span/a")[0].text == "My needflow"
)
else:
root_flow_hrefs = root_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
assert (
root_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)
# check base_url url in root level
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in root_flow_hrefs[0].attrib["alt"]
if int(doc_ver.split(".")[1]) >= 18:
root_flow_hrefs = root_tree.xpath("//figure/p/object/a/img")
assert root_tree.xpath("//figure/figcaption/p/span/a")[0].text == "My needflow"
else:
root_flow_hrefs = root_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
# check base_url relative path in root level
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in root_flow_hrefs[0].attrib["alt"]
root_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)
# check base_url url in root level
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in root_flow_hrefs[0].attrib["alt"]
)
# check base_url relative path in root level
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in root_flow_hrefs[0].attrib["alt"]
)

# check role need_outgoing and need_incoming for base_url in root level
for element in root_tree.xpath("//p/span/a"):
Expand Down Expand Up @@ -190,32 +186,29 @@ def test_external_needs_base_url_relative_path(test_app):
assert sub_table_hrefs[4].text == "EXT_TEST_01"

# check needflow usage for base_url in subfolder level
if not sphinx.__version__.startswith("3.5"):
if int(doc_ver.split(".")[1]) >= 18:
sub_flow_hrefs = sub_tree.xpath("//figure/p/object/a/img")
assert (
sub_tree.xpath("//figure/figcaption/p/span/a")[0].text == "My needflow"
)
else:
sub_flow_hrefs = sub_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
assert (
sub_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)
# check base_url url in root level
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in sub_flow_hrefs[0].attrib["alt"]
if int(doc_ver.split(".")[1]) >= 18:
sub_flow_hrefs = sub_tree.xpath("//figure/p/object/a/img")
assert sub_tree.xpath("//figure/figcaption/p/span/a")[0].text == "My needflow"
else:
sub_flow_hrefs = sub_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
# check base_url relative path in subfolder level, one level deeper than base_url
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in sub_flow_hrefs[0].attrib["alt"]
sub_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)
# check base_url url in root level
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in sub_flow_hrefs[0].attrib["alt"]
)
# check base_url relative path in subfolder level, one level deeper than base_url
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in sub_flow_hrefs[0].attrib["alt"]
)

# check role need_outgoing and need_incoming for base_url in subfolder level
for element in sub_tree.xpath("//p/span/a"):
Expand Down Expand Up @@ -272,35 +265,33 @@ def test_external_needs_base_url_relative_path(test_app):
assert sub_sub_table_hrefs[4].text == "EXT_TEST_01"

# check needflow usage for base_url in subsubfolder level
if not sphinx.__version__.startswith("3.5"):
if int(doc_ver.split(".")[1]) >= 18:
sub_sub_flow_hrefs = sub_sub_tree.xpath("//figure/p/object/a/img")
assert (
sub_sub_tree.xpath("//figure/figcaption/p/span/a")[0].text
== "My needflow"
)
else:
sub_sub_flow_hrefs = sub_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
assert (
sub_sub_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)

# check base_url url in subsubfolder level
if int(doc_ver.split(".")[1]) >= 18:
sub_sub_flow_hrefs = sub_sub_tree.xpath("//figure/p/object/a/img")
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in sub_sub_flow_hrefs[0].attrib["alt"]
sub_sub_tree.xpath("//figure/figcaption/p/span/a")[0].text == "My needflow"
)
else:
sub_sub_flow_hrefs = sub_tree.xpath(
"//div[@class='figure align-center']/p/object/a/img"
)
# check base_url relative path in subsubfolder level, two level deeper than base_url
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in sub_sub_flow_hrefs[0].attrib["alt"]
sub_sub_tree.xpath(
"//div[@class='figure align-center']/p[@class='caption']/span/a"
)[0].text
== "My needflow"
)

# check base_url url in subsubfolder level
assert (
"as EXT_TEST_01 [[http://my_company.com/docs/v1/index.html#TEST_01]]"
in sub_sub_flow_hrefs[0].attrib["alt"]
)
# check base_url relative path in subsubfolder level, two level deeper than base_url
assert (
"as EXT_REL_PATH_TEST_01 [[../../../_build/html/index.html#TEST_01]]"
in sub_sub_flow_hrefs[0].attrib["alt"]
)

# check role need_outgoing and need_incoming for base_url in subsubfolder level
for element in sub_sub_tree.xpath("//p/span/a"):
# check link for need_outgoing
Expand Down
5 changes: 0 additions & 5 deletions tests/test_needs_filter_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ def test_doc_needs_filter_data_html(test_app):
app.build()
index_html = Path(app.outdir, "index.html").read_text()

import sphinx

if sphinx.__version__.startswith("3.5"):
return

# Check need_count works
assert "The amount of needs that belong to current variants: 6" in index_html

Expand Down
23 changes: 2 additions & 21 deletions tests/test_needtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,14 @@ def test_doc_build_html(test_app):
indirect=True,
)
def test_doc_needtable_options(test_app):
import sphinx

app = test_app
app.build()
html = Path(app.outdir, "test_options.html").read_text()
assert "SP_TOO_003" in html
assert 'id="needtable-test_options-0"' in html
assert 'id="needtable-test_options-1"' in html

if sphinx.version_info[0] < 2:
column_order = """
<tr class="row-odd"><th class="head">Incoming</th>
<th class="head">ID</th>
<th class="head">Tags</th>
<th class="head">Status</th>
<th class="head">Title</th>
"""
else:
column_order = """
column_order = """
<tr class="row-odd"><th class="head"><p>Incoming</p></th>
<th class="head"><p>ID</p></th>
<th class="head"><p>Tags</p></th>
Expand All @@ -110,15 +99,7 @@ def test_doc_needtable_options(test_app):
)
assert "Sphinx-Needs docs for needs-string-links" in html

if sphinx.version_info[0] < 2:
string_column_order = """
<tr class="row-odd"><th class="head">ID</th>
<th class="head">Title</th>
<th class="head">Config</th>
<th class="head">Github</th>
"""
else:
string_column_order = """
string_column_order = """
<tr class="row-odd"><th class="head"><p>ID</p></th>
<th class="head"><p>Title</p></th>
<th class="head"><p>Config</p></th>
Expand Down

1 comment on commit 0ddb5e7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 0ddb5e7 Previous: 58fee42 Ratio
Small, basic Sphinx-Needs project 0.3012528970000119 s 0.1808682230000045 s 1.67

This comment was automatically generated by workflow using github-action-benchmark.

CC: @danwos

Please sign in to comment.