Skip to content

Commit c5d9c21

Browse files
authored
Merge pull request #39 from sphinx-notes/v3
Any domain 3.0
2 parents 9f048e1 + 1862856 commit c5d9c21

File tree

18 files changed

+694
-253
lines changed

18 files changed

+694
-253
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ on:
55
schedule:
66
- cron: '0 7 * * 6'
77
jobs:
8-
test-ubuntu:
8+
test:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version-file: 'pyproject.toml'
1215
- name: Install the dependencies
13-
run: python3 -m pip install sphinx -r ./requirements.txt
16+
run: python3 -m pip install .[dev]
1417
- name: Build
1518
run: make test

docs/_schemas/cat.py

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

44
cat = Schema(
55
'cat',
6-
name=Field(referenceable=True, form=Field.Form.LINES),
6+
name=Field(ref=True, form=Field.Forms.LINES),
77
attrs={
8-
'id': Field(unique=True, referenceable=True, required=True),
9-
'color': Field(referenceable=True),
8+
'id': Field(uniq=True, ref=True, required=True),
9+
'color': Field(ref=True),
1010
'picture': Field(),
1111
},
1212
description_template=dedent("""

docs/_schemas/dog1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
dog = Schema(
55
'dog',
66
attrs={
7-
'breed': Field(referenceable=True),
8-
'color': Field(referenceable=True, form=Field.Form.WORDS),
7+
'breed': Field(ref=True),
8+
'color': Field(ref=True, form=Field.Forms.WORDS),
99
},
1010
description_template=dedent("""
1111
:Breed: {{ breed }}

docs/_schemas/dog2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from textwrap import dedent
2-
from any import Schema, Field
2+
from any.api import Schema, Field
33

44
dog = Schema(
55
'dog',
66
attrs={
7-
'breed': Field(referenceable=True),
8-
'color': Field(referenceable=True, form=Field.Form.WORDS),
7+
'breed': Field(ref=True),
8+
'color': Field(ref=True, form=Field.Forms.WORDS),
99
},
1010
description_template=dedent("""
1111
:Breed: :any:dog.breed:`{{ breed }}`

docs/_schemas/tmplvar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from textwrap import dedent
2-
from any import Schema, Field
2+
from any.api import Schema, Field
33

44
tmplvar = Schema(
55
'tmplvar',
6-
name=Field(unique=True, referenceable=True),
6+
name=Field(uniq=True, ref=True),
77
attrs={
88
'type': Field(),
99
'conf': Field(),

docs/_templates/version.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
:Date: :ref:`📅{{ date }} <any-version.date>`
2+
:Date: :version.date+by-year:`📅{{ date }} <{{ date }}>`
33
:Download: :tag:`{{ title }}`
44

55
{% for line in content %}

docs/conf.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,36 @@
114114

115115
#
116116
# DOG FOOD CONFIGURATION START
117-
from any import Schema, Field as F
118-
sys.path.insert(0, os.path.abspath('.'))
117+
from any.api import Schema, Field as F, by_year, by_month
119118

120119
version_schema = Schema('version',
121-
name=F(unique=True, referenceable=True, required=True, form=F.Form.LINES),
122-
attrs={'date': F(referenceable=True)},
123-
content=F(form=F.Form.LINES),
120+
name=F(uniq=True, ref=True, required=True, form=F.Forms.LINES),
121+
attrs={
122+
'date': F(ref=True, indexers=[by_year, by_month]),
123+
},
124+
content=F(form=F.Forms.LINES),
124125
description_template=open('_templates/version.rst', 'r').read(),
125126
reference_template='🏷️{{ title }}',
126127
missing_reference_template='🏷️{{ title }}',
127128
ambiguous_reference_template='🏷️{{ title }}')
128129
confval_schema = Schema('confval',
129-
name=F(unique=True, referenceable=True, required=True, form=F.Form.LINES),
130+
name=F(uniq=True, ref=True, required=True, form=F.Forms.LINES),
130131
attrs={
131132
'type': F(),
132133
'default': F(),
133-
'choice': F(form=F.Form.WORDS),
134+
'choice': F(form=F.Forms.WORDS),
134135
'versionadded': F(),
135-
'versionchanged': F(form=F.Form.LINES),
136+
'versionchanged': F(form=F.Forms.LINES),
136137
},
137138
content=F(),
138139
description_template=open('_templates/confval.rst', 'r').read(),
139140
reference_template='⚙️{{ title }}',
140141
missing_reference_template='⚙️{{ title }}',
141142
ambiguous_reference_template='⚙️{{ title }}')
142143
example_schema = Schema('example',
143-
name=F(referenceable=True),
144+
name=F(ref=True),
144145
attrs={'style': F()},
145-
content=F(form=F.Form.LINES),
146+
content=F(form=F.Forms.LINES),
146147
description_template=open('_templates/example.rst', 'r').read(),
147148
reference_template='📝{{ title }}',
148149
missing_reference_template='📝{{ title }}',

docs/usage.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Defining Schema
1515

1616
The necessary python classes for writing schema are listed here:
1717

18-
.. autoclass:: any.Schema
18+
.. autoclass:: any.api.Schema
1919

2020
Class-wide shared special keys used in template rendering context:
2121

@@ -26,15 +26,15 @@ The necessary python classes for writing schema are listed here:
2626

2727
|
2828

29-
.. autoclass:: any.Field
29+
.. autoclass:: any.api.Field
3030

3131
|
3232

33-
.. autoclass:: any.Field.Form
33+
.. autoclass:: any.api.Field.Forms
3434

35-
.. autoattribute:: any.Field.Form.PLAIN
36-
.. autoattribute:: any.Field.Form.WORDS
37-
.. autoattribute:: any.Field.Form.LINES
35+
.. autoattribute:: any.api.Field.Forms.PLAIN
36+
.. autoattribute:: any.api.Field.Forms.WORDS
37+
.. autoattribute:: any.api.Field.Forms.LINES
3838

3939
Documenting Object
4040
==================

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727
"Topic :: Documentation :: Sphinx",
2828
]
2929

30-
requires-python = ">=3.8"
30+
requires-python = ">=3.12"
3131
dependencies = [
3232
"Sphinx >= 4",
3333
"Jinja2",

src/sphinxnotes/any/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@
1010

1111
from __future__ import annotations
1212
from typing import TYPE_CHECKING
13+
from importlib.metadata import version
14+
1315
from sphinx.util import logging
1416

1517
from .template import Environment as TemplateEnvironment
1618
from .domain import AnyDomain, warn_missing_reference
17-
from .schema import Schema, Field
19+
from .objects import Schema
1820

1921
if TYPE_CHECKING:
2022
from sphinx.application import Sphinx
2123
from sphinx.config import Config
2224

23-
__version__ = '2.3.1'
2425

2526
logger = logging.getLogger(__name__)
2627

27-
# Export
28-
Field = Field
29-
Schema = Schema
30-
3128

3229
def _config_inited(app: Sphinx, config: Config) -> None:
3330
AnyDomain.name = config.any_domain_name
@@ -51,4 +48,4 @@ def setup(app: Sphinx):
5148
app.connect('config-inited', _config_inited)
5249
app.connect('warn-missing-reference', warn_missing_reference)
5350

54-
return {'version': __version__}
51+
return {'version': version('sphinxnotes.any')}

src/sphinxnotes/any/api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
sphinxnotes.any.api
3+
~~~~~~~~~~~~~~~~~~~
4+
5+
Public API for building configuration of extension.
6+
(such as object schema, and so on).
7+
8+
:copyright: Copyright 2024 Shengyu Zhang
9+
:license: BSD, see LICENSE for details.
10+
"""
11+
12+
from .objects import Schema, Field
13+
from .indexers import LiteralIndexer, PathIndexer, YearIndexer, MonthIndexer
14+
15+
# Object schema.
16+
Schema = Schema
17+
Field = Field
18+
19+
# Indexers.
20+
LiteralIndexer = LiteralIndexer
21+
PathIndexer = PathIndexer
22+
YearIndexer = YearIndexer
23+
MonthIndexer = MonthIndexer
24+
25+
# Indexer wrappers.
26+
by_year = YearIndexer()
27+
by_month = MonthIndexer()

src/sphinxnotes/any/directives.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from docutils.nodes import Node, Element, fully_normalize_name
1616
from docutils.statemachine import StringList
1717
from docutils.parsers.rst import directives
18-
1918
from sphinx import addnodes
2019
from sphinx.util.docutils import SphinxDirective
2120
from sphinx.util.nodes import make_id, nested_parse_with_titles
2221
from sphinx.util import logging
2322

24-
from .schema import Schema, Object
23+
from .objects import Schema, Object
2524

2625
logger = logging.getLogger(__name__)
2726

0 commit comments

Comments
 (0)