Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Remove unwrap function #1017

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sphinx_needs/api/need.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from sphinx_needs.logging import get_logger
from sphinx_needs.nodes import Need
from sphinx_needs.roles.need_part import find_parts, update_need_with_parts
from sphinx_needs.utils import jinja_parse, unwrap
from sphinx_needs.utils import jinja_parse

logger = get_logger(__name__)

Expand Down Expand Up @@ -512,7 +512,7 @@ def del_need(app: Sphinx, need_id: str) -> None:
:param app: Sphinx application object.
:param need_id: Sphinx need id.
"""
env = unwrap(app.env)
env = app.env
needs = SphinxNeedsData(env).get_or_create_needs()
if need_id in needs:
del needs[need_id]
Expand Down
13 changes: 6 additions & 7 deletions sphinx_needs/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from sphinx_needs.data import NeedsInfoType, SphinxNeedsData
from sphinx_needs.logging import get_logger
from sphinx_needs.needsfile import NeedsList
from sphinx_needs.utils import unwrap

log = get_logger(__name__)

Expand All @@ -25,7 +24,7 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:
pass

def finish(self) -> None:
env = unwrap(self.env)
env = self.env
data = SphinxNeedsData(env)
filters = data.get_or_create_filters()
version = getattr(env.config, "version", "unset")
Expand Down Expand Up @@ -82,7 +81,7 @@ def get_target_uri(self, _docname: str, _typ: Optional[str] = None) -> str:


def build_needs_json(app: Sphinx, _exception: Exception) -> None:
env = unwrap(app.env)
env = app.env

if not NeedsSphinxConfig(env.config).build_json:
return
Expand All @@ -107,7 +106,7 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:
pass

def finish(self) -> None:
env = unwrap(self.env)
env = self.env
needumls = SphinxNeedsData(env).get_or_create_umls().values()

for needuml in needumls:
Expand Down Expand Up @@ -140,7 +139,7 @@ def get_target_uri(self, _docname: str, _typ: Optional[str] = None) -> str:


def build_needumls_pumls(app: Sphinx, _exception: Exception) -> None:
env = unwrap(app.env)
env = app.env
config = NeedsSphinxConfig(env.config)

if not config.build_needumls:
Expand Down Expand Up @@ -174,7 +173,7 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:
pass

def finish(self) -> None:
env = unwrap(self.env)
env = self.env
data = SphinxNeedsData(env)
needs = data.get_or_create_needs().values() # We need a list of needs for later filter checks
version = getattr(env.config, "version", "unset")
Expand Down Expand Up @@ -216,7 +215,7 @@ def get_target_uri(self, _docname: str, _typ: Optional[str] = None) -> str:


def build_needs_id_json(app: Sphinx, _exception: Exception) -> None:
env = unwrap(app.env)
env = app.env

if not NeedsSphinxConfig(env.config).build_json_per_id:
return
Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/diagrams_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sphinx_needs.data import NeedsFilteredBaseType, NeedsPartsInfoType
from sphinx_needs.errors import NoUri
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import get_scale, split_link_types, unwrap
from sphinx_needs.utils import get_scale, split_link_types

try:
from typing import TypedDict
Expand Down Expand Up @@ -169,7 +169,7 @@ def calculate_link(app: Sphinx, need_info: NeedsPartsInfoType, _fromdocname: str
:param fromdocname:
:return:
"""
builder = unwrap(app.builder)
builder = app.builder
try:
if need_info["is_external"]:
assert need_info["external_url"] is not None, "external_url must be set for external needs"
Expand Down
11 changes: 4 additions & 7 deletions sphinx_needs/directives/need.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from sphinx_needs.logging import get_logger
from sphinx_needs.need_constraints import process_constraints
from sphinx_needs.nodes import Need
from sphinx_needs.utils import add_doc, profile, unwrap
from sphinx_needs.utils import add_doc, profile

logger = get_logger(__name__)

Expand Down Expand Up @@ -296,8 +296,7 @@ def analyse_need_locations(app: Sphinx, doctree: nodes.document) -> None:
(i.e. ones that should not be rendered in the output)
are removed from the doctree.
"""
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env

needs = SphinxNeedsData(env).get_or_create_needs()

Expand Down Expand Up @@ -376,8 +375,7 @@ def process_need_nodes(app: Sphinx, doctree: nodes.document, fromdocname: str) -
node.parent.remove(node) # type: ignore
return

builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env

# If no needs were defined, we do not need to do anything
if not hasattr(env, "needs_all_needs"):
Expand Down Expand Up @@ -430,8 +428,7 @@ def print_need_nodes(app: Sphinx, doctree: nodes.document, fromdocname: str, fou
:param fromdocname:
:return:
"""
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs = SphinxNeedsData(env).get_or_create_needs()

# We try to avoid findall as much as possibles. so we reuse the already found need nodes in the current document.
Expand Down
5 changes: 2 additions & 3 deletions sphinx_needs/directives/needbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sphinx_needs.config import NeedsSphinxConfig
from sphinx_needs.data import SphinxNeedsData
from sphinx_needs.filter_common import FilterBase, filter_needs, prepare_need_list
from sphinx_needs.utils import add_doc, save_matplotlib_figure, unwrap
from sphinx_needs.utils import add_doc, save_matplotlib_figure

if not os.environ.get("DISPLAY"):
matplotlib.use("Agg")
Expand Down Expand Up @@ -168,8 +168,7 @@ def run(self) -> Sequence[nodes.Node]:
# 9. final storage
# 10. cleanup matplotlib
def process_needbar(app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]) -> None:
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs_config = NeedsSphinxConfig(env.config)

# NEEDFLOW
Expand Down
5 changes: 2 additions & 3 deletions sphinx_needs/directives/needextend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sphinx_needs.data import SphinxNeedsData
from sphinx_needs.filter_common import filter_needs
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import add_doc, unwrap
from sphinx_needs.utils import add_doc

logger = get_logger(__name__)

Expand Down Expand Up @@ -75,8 +75,7 @@ def process_needextend(app: Sphinx, doctree: nodes.document, fromdocname: str) -
"""
Perform all modifications on needs
"""
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs_config = NeedsSphinxConfig(env.config)
data = SphinxNeedsData(env)
workflow = data.get_or_create_workflow()
Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/directives/needextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from sphinx_needs.filter_common import FilterBase, process_filters
from sphinx_needs.layout import create_need
from sphinx_needs.utils import add_doc, unwrap
from sphinx_needs.utils import add_doc


class Needextract(nodes.General, nodes.Element):
Expand Down Expand Up @@ -75,7 +75,7 @@ def process_needextract(
"""
Replace all needextract nodes with a list of the collected needs.
"""
env = unwrap(app.env)
env = app.env
needs_config = NeedsSphinxConfig(app.config)

for node in found_nodes:
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/directives/needfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sphinx_needs.data import SphinxNeedsData
from sphinx_needs.diagrams_common import create_legend
from sphinx_needs.filter_common import FilterBase, process_filters
from sphinx_needs.utils import add_doc, row_col_maker, unwrap
from sphinx_needs.utils import add_doc, row_col_maker


class Needfilter(nodes.General, nodes.Element):
Expand Down Expand Up @@ -74,8 +74,8 @@ def process_needfilters(
) -> None:
# Replace all needlist nodes with a list of the collected needs.
# Augment each need with a backlink to the original location.
builder = unwrap(app.builder)
env = unwrap(builder.env)
builder = app.builder
env = app.env
needs_config = NeedsSphinxConfig(env.config)
all_needs = SphinxNeedsData(env).get_or_create_needs()

Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/directives/needflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sphinx_needs.diagrams_common import calculate_link, create_legend
from sphinx_needs.filter_common import FilterBase, filter_single_need, process_filters
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import add_doc, get_scale, split_link_types, unwrap
from sphinx_needs.utils import add_doc, get_scale, split_link_types

logger = get_logger(__name__)

Expand Down Expand Up @@ -271,7 +271,7 @@ def cal_needs_node(
def process_needflow(app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]) -> None:
# Replace all needflow nodes with a list of the collected needs.
# Augment each need with a backlink to the original location.
env = unwrap(app.env)
env = app.env
needs_config = NeedsSphinxConfig(app.config)
env_data = SphinxNeedsData(env)
all_needs = env_data.get_or_create_needs()
Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/directives/needgantt.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_link_type_option(self, name: str, default: str = "") -> List[str]:

def process_needgantt(app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]) -> None:
# Replace all needgantt nodes with a list of the collected needs.
env = app.builder.env
env = app.env
needs_config = NeedsSphinxConfig(app.config)

# link_types = needs_config.extra_links
Expand Down
6 changes: 3 additions & 3 deletions sphinx_needs/directives/needlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
used_filter_paragraph,
)
from sphinx_needs.filter_common import FilterBase, process_filters
from sphinx_needs.utils import add_doc, check_and_calc_base_url_rel_path, unwrap
from sphinx_needs.utils import add_doc, check_and_calc_base_url_rel_path


class Needlist(nodes.General, nodes.Element):
Expand Down Expand Up @@ -64,8 +64,8 @@ def process_needlist(app: Sphinx, doctree: nodes.document, fromdocname: str, fou
Replace all needlist nodes with a list of the collected needs.
Augment each need with a backlink to the original location.
"""
builder = unwrap(app.builder)
env = unwrap(builder.env)
builder = app.builder
env = app.env

include_needs = NeedsSphinxConfig(env.config).include_needs
# for node in doctree.findall(Needlist):
Expand Down
4 changes: 1 addition & 3 deletions sphinx_needs/directives/needpie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
add_doc,
check_and_get_external_filter_func,
save_matplotlib_figure,
unwrap,
)

logger = get_logger(__name__)
Expand Down Expand Up @@ -111,8 +110,7 @@ def run(self) -> Sequence[nodes.Node]:

@measure_time("needpie")
def process_needpie(app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]) -> None:
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs_data = SphinxNeedsData(env)

# NEEDFLOW
Expand Down
5 changes: 2 additions & 3 deletions sphinx_needs/directives/needsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from sphinx_needs.filter_common import FilterBase
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import add_doc, unwrap
from sphinx_needs.utils import add_doc

logger = get_logger(__name__)

Expand Down Expand Up @@ -76,8 +76,7 @@ def process_needsequence(
app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]
) -> None:
# Replace all needsequence nodes with a list of the collected needs.
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs_data = SphinxNeedsData(env)
all_needs_dict = needs_data.get_or_create_needs()

Expand Down
5 changes: 3 additions & 2 deletions sphinx_needs/directives/needservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sphinx_needs.directives.need import NeedDirective
from sphinx_needs.logging import get_logger
from sphinx_needs.services.base import BaseService
from sphinx_needs.utils import add_doc, unwrap
from sphinx_needs.utils import add_doc


class Needservice(nodes.General, nodes.Element):
Expand Down Expand Up @@ -58,7 +58,8 @@ def run(self) -> Sequence[nodes.Node]:
needs_services: Dict[str, BaseService] = getattr(app, "needs_services", {})

service_name = self.arguments[0]
service = unwrap(needs_services.get(service_name))
service = needs_services.get(service_name)
assert service is not None
section = []

if "debug" not in self.options:
Expand Down
10 changes: 2 additions & 8 deletions sphinx_needs/directives/needtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from sphinx_needs.filter_common import FilterBase, process_filters
from sphinx_needs.functions.functions import check_and_get_content
from sphinx_needs.utils import add_doc, profile, row_col_maker, unwrap
from sphinx_needs.utils import add_doc, profile, row_col_maker


class Needtable(nodes.General, nodes.Element):
Expand Down Expand Up @@ -117,14 +117,8 @@ def process_needtables(
) -> None:
"""
Replace all needtables nodes with a table of filtered nodes.

:param app:
:param doctree:
:param fromdocname:
:return:
"""
builder = unwrap(app.builder)
env = unwrap(builder.env)
env = app.env
needs_config = NeedsSphinxConfig(app.config)
needs_data = SphinxNeedsData(env)

Expand Down
2 changes: 1 addition & 1 deletion sphinx_needs/directives/needuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def is_element_of_need(node: nodes.Element) -> str:

@measure_time("needuml")
def process_needuml(app: Sphinx, doctree: nodes.document, fromdocname: str, found_nodes: List[nodes.Element]) -> None:
env = app.builder.env
env = app.env

# for node in doctree.findall(Needuml):
for node in found_nodes:
Expand Down
Loading