Skip to content

Commit 9f048e1

Browse files
committed
chore: Format all code
1 parent 1dbc48d commit 9f048e1

File tree

13 files changed

+332
-285
lines changed

13 files changed

+332
-285
lines changed

docs/_schemas/cat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from textwrap import dedent
22
from any import Schema, Field
33

4-
cat = Schema('cat',
4+
cat = Schema(
5+
'cat',
56
name=Field(referenceable=True, form=Field.Form.LINES),
67
attrs={
78
'id': Field(unique=True, referenceable=True, required=True),
@@ -18,4 +19,5 @@
1819
{{ content }}"""),
1920
reference_template='🐈{{ title }}',
2021
missing_reference_template='😿{{ title }}',
21-
ambiguous_reference_template='😼{{ title }}')
22+
ambiguous_reference_template='😼{{ title }}',
23+
)

docs/_schemas/dog1.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from textwrap import dedent
22
from any import Schema, Field
33

4-
dog = Schema('dog',
4+
dog = Schema(
5+
'dog',
56
attrs={
67
'breed': Field(referenceable=True),
78
'color': Field(referenceable=True, form=Field.Form.WORDS),
@@ -10,4 +11,5 @@
1011
:Breed: {{ breed }}
1112
:Colors: {{ colors }}"""),
1213
reference_template='🐕{{ title }}',
13-
ambiguous_reference_template='{{ title }}')
14+
ambiguous_reference_template='{{ title }}',
15+
)

docs/_schemas/dog2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from textwrap import dedent
22
from any import Schema, Field
33

4-
dog = Schema('dog',
4+
dog = Schema(
5+
'dog',
56
attrs={
67
'breed': Field(referenceable=True),
78
'color': Field(referenceable=True, form=Field.Form.WORDS),
@@ -10,4 +11,5 @@
1011
:Breed: :any:dog.breed:`{{ breed }}`
1112
:Colors: {% for c in color %}:any:dog.color:`{{ c }}` {% endfor %}"""),
1213
reference_template='🐕{{ title }}',
13-
ambiguous_reference_template='{{ title }}')
14+
ambiguous_reference_template='{{ title }}',
15+
)

docs/_schemas/tmplvar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
Name of variables("{{ name }}") can be changed by setting
2020
:py:attr:`~any.Schema.{{ conf }}`
2121
{% endif %}"""),
22-
2322
reference_template="{{ '{{' }}{{ title }}{{ '}}' }}",
24-
missing_reference_template="{{ '{{' }}{{ title }}{{ '}}' }}")
23+
missing_reference_template="{{ '{{' }}{{ title }}{{ '}}' }}",
24+
)

src/sphinxnotes/any/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
2-
sphinxnotes.any
3-
~~~~~~~~~~~~~~~
2+
sphinxnotes.any
3+
~~~~~~~~~~~~~~~
44
5-
Sphinx extension entrypoint.
5+
Sphinx extension entrypoint.
66
7-
:copyright: Copyright 2020 Shengyu Zhang
8-
:license: BSD, see LICENSE for details.
7+
:copyright: Copyright 2020 Shengyu Zhang
8+
:license: BSD, see LICENSE for details.
99
"""
1010

1111
from __future__ import annotations
@@ -28,7 +28,8 @@
2828
Field = Field
2929
Schema = Schema
3030

31-
def _config_inited(app:Sphinx, config:Config) -> None:
31+
32+
def _config_inited(app: Sphinx, config: Config) -> None:
3233
AnyDomain.name = config.any_domain_name
3334
AnyDomain.label = config.any_domain_name
3435

@@ -39,7 +40,7 @@ def _config_inited(app:Sphinx, config:Config) -> None:
3940
app.add_domain(AnyDomain)
4041

4142

42-
def setup(app:Sphinx):
43+
def setup(app: Sphinx):
4344
"""Sphinx extension entrypoint."""
4445

4546
# Init template environment

src/sphinxnotes/any/directives.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
sphinxnotes.any.directives
3-
~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
sphinxnotes.any.directives
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~
44
5-
Directive implementations.
5+
Directive implementations.
66
7-
:copyright: Copyright 2021 Shengyu Zhang
8-
:license: BSD, see LICENSE for details.
7+
:copyright: Copyright 2021 Shengyu Zhang
8+
:license: BSD, see LICENSE for details.
99
"""
10+
1011
from __future__ import annotations
1112
from typing import Type
1213

@@ -24,6 +25,7 @@
2425

2526
logger = logging.getLogger(__name__)
2627

28+
2729
class AnyDirective(SphinxDirective):
2830
"""
2931
Directive to describe anything. Not used directly,
@@ -32,17 +34,17 @@ class AnyDirective(SphinxDirective):
3234
The class is modified from sphinx.directives.ObjectDescription
3335
"""
3436

35-
schema:Schema
37+
schema: Schema
3638

3739
# Member of parent
38-
has_content:bool = True
39-
required_arguments:int = 0
40-
optional_arguments:int = 0
41-
final_argument_whitespace:bool = True
42-
option_spec:dict[str,callable] = {}
40+
has_content: bool = True
41+
required_arguments: int = 0
42+
optional_arguments: int = 0
43+
final_argument_whitespace: bool = True
44+
option_spec: dict[str, callable] = {}
4345

4446
@classmethod
45-
def derive(cls, schema:Schema) -> Type["AnyDirective"]:
47+
def derive(cls, schema: Schema) -> Type['AnyDirective']:
4648
"""Generate an AnyDirective child class for describing object."""
4749
has_content = schema.content is not None
4850

@@ -64,24 +66,30 @@ def derive(cls, schema:Schema) -> Type["AnyDirective"]:
6466
option_spec[name] = directives.unchanged
6567

6668
# Generate directive class
67-
return type('Any%sDirective' % schema.objtype.title(),
68-
(AnyDirective,),
69-
{'schema': schema,
70-
'has_content': has_content,
71-
'required_arguments': required_arguments,
72-
'optional_arguments': optional_arguments,
73-
'option_spec': option_spec, })
74-
69+
return type(
70+
'Any%sDirective' % schema.objtype.title(),
71+
(AnyDirective,),
72+
{
73+
'schema': schema,
74+
'has_content': has_content,
75+
'required_arguments': required_arguments,
76+
'optional_arguments': optional_arguments,
77+
'option_spec': option_spec,
78+
},
79+
)
7580

7681
def _build_object(self) -> Object:
7782
"""Build object information for template rendering."""
78-
return self.schema.object(name=self.arguments[0] if self.arguments else None,
79-
attrs=self.options,
80-
# Convert docutils.statemachine.ViewList.data -> str
81-
content='\n'.join(list(self.content.data)))
82-
83-
84-
def _setup_nodes(self, obj:Object, sectnode:Element, ahrnode:Element|None, contnode:Element) -> None:
83+
return self.schema.object(
84+
name=self.arguments[0] if self.arguments else None,
85+
attrs=self.options,
86+
# Convert docutils.statemachine.ViewList.data -> str
87+
content='\n'.join(list(self.content.data)),
88+
)
89+
90+
def _setup_nodes(
91+
self, obj: Object, sectnode: Element, ahrnode: Element | None, contnode: Element
92+
) -> None:
8593
"""
8694
Attach necessary informations to nodes and note them.
8795
@@ -116,23 +124,26 @@ def _setup_nodes(self, obj:Object, sectnode:Element, ahrnode:Element|None, contn
116124
ahrnode['names'].extend([fully_normalize_name(x) for x in name])
117125
self.state.document.note_explicit_target(ahrnode)
118126
# Note object by docu fields
119-
domain.note_object(self.env.docname, ahrid, self.schema, obj) # FIXME: Cast to AnyDomain
127+
domain.note_object(
128+
self.env.docname, ahrid, self.schema, obj
129+
) # FIXME: Cast to AnyDomain
120130

121131
# Parse description
122-
nested_parse_with_titles(self.state,
123-
StringList(self.schema.render_description(obj)),
124-
contnode)
125-
132+
nested_parse_with_titles(
133+
self.state, StringList(self.schema.render_description(obj)), contnode
134+
)
126135

127-
def _run_section(self, obj:Object) -> list[Node]:
136+
def _run_section(self, obj: Object) -> list[Node]:
128137
# Get the title of the "section" where the directive is located
129138
sectnode = self.state.parent
130139
titlenode = sectnode.next_node(nodes.title)
131140
if not titlenode or titlenode.parent != sectnode:
132141
# Title should be direct child of section
133142
msg = 'Failed to get title of current section'
134143
logger.warning(msg, location=sectnode)
135-
sm = nodes.system_message(msg, type='WARNING', level=2, backrefs=[], source='')
144+
sm = nodes.system_message(
145+
msg, type='WARNING', level=2, backrefs=[], source=''
146+
)
136147
sectnode += sm
137148
title = ''
138149
else:
@@ -152,8 +163,7 @@ def _run_section(self, obj:Object) -> list[Node]:
152163
# Add all content to existed section, so return nothing
153164
return []
154165

155-
156-
def _run_objdesc(self, obj:Object) -> list[Node]:
166+
def _run_objdesc(self, obj: Object) -> list[Node]:
157167
descnode = addnodes.desc()
158168

159169
# Generate signature node
@@ -175,7 +185,6 @@ def _run_objdesc(self, obj:Object) -> list[Node]:
175185
self._setup_nodes(obj, descnode, signode, contnode)
176186
return [descnode]
177187

178-
179188
def run(self) -> list[Node]:
180189
obj = self._build_object()
181190
if self.schema.title_of(obj) == '_':

0 commit comments

Comments
 (0)