6
6
7
7
from sphinx .ext import autodoc
8
8
9
- import vdirsyncer
9
+ import setuptools_scm
10
10
11
11
extensions = ['sphinx.ext.autodoc' ]
12
12
19
19
copyright = (u'2014-{}, Markus Unterwaditzer & contributors'
20
20
.format (datetime .date .today ().strftime ('%Y' )))
21
21
22
- release = vdirsyncer . __version__
22
+ release = setuptools_scm . get_version ( root = '..' , relative_to = __file__ )
23
23
version = '.' .join (release .split ('.' )[:2 ]) # The short X.Y version.
24
24
25
25
rst_epilog = '.. |vdirsyncer_version| replace:: %s' % release
@@ -75,9 +75,10 @@ def github_issue_role(name, rawtext, text, lineno, inliner,
75
75
prb = inliner .problematic (rawtext , rawtext , msg )
76
76
return [prb ], [msg ]
77
77
78
- import vdirsyncer
79
78
from docutils import nodes
80
- link = '{}/{}/{}' .format (vdirsyncer .PROJECT_HOME ,
79
+
80
+ PROJECT_HOME = 'https://github.com/pimutils/vdirsyncer'
81
+ link = '{}/{}/{}' .format (PROJECT_HOME ,
81
82
'issues' if name == 'gh' else 'pull' ,
82
83
issue_num )
83
84
linktext = ('issue #{}' if name == 'gh'
@@ -87,64 +88,9 @@ def github_issue_role(name, rawtext, text, lineno, inliner,
87
88
return [node ], []
88
89
89
90
90
- def format_storage_config (cls , header = True ):
91
- if header is True :
92
- yield '[storage example_for_{}]' .format (cls .storage_name )
93
- yield 'type = "{}"' .format (cls .storage_name )
94
-
95
- from vdirsyncer .storage .base import Storage
96
- from vdirsyncer .utils import get_storage_init_specs
97
- handled = set ()
98
- for spec in get_storage_init_specs (cls , stop_at = Storage ):
99
- defaults = spec .defaults or ()
100
- defaults = dict (zip (spec .args [- len (defaults ):], defaults ))
101
- for key in spec .args [1 :]:
102
- if key in handled :
103
- continue
104
- handled .add (key )
105
-
106
- comment = '' if key not in defaults else '#'
107
- value = defaults .get (key , '...' )
108
- yield '{}{} = {}' .format (comment , key , json .dumps (value ))
109
-
110
-
111
- class StorageDocumenter (autodoc .ClassDocumenter ):
112
- '''Custom formatter for auto-documenting storage classes. It assumes that
113
- the first line of the class' docstring is its own paragraph.
114
-
115
- After that first paragraph, an example configuration will be inserted and
116
- Sphinx' __init__ signature removed.'''
117
-
118
- objtype = 'storage'
119
- domain = None
120
- directivetype = 'storage'
121
- option_spec = {}
122
-
123
- @classmethod
124
- def can_document_member (cls , member , membername , isattr , parent ):
125
- from vdirsyncer .storage .base import Storage
126
- return isinstance (member , Storage )
127
-
128
- def format_signature (self ):
129
- return ''
130
-
131
- def add_directive_header (self , sig ):
132
- directive = getattr (self , 'directivetype' , self .objtype )
133
- name = self .object .storage_name
134
- self .add_line (u'.. %s:: %s%s' % (directive , name , sig ),
135
- '<autodoc>' )
136
-
137
- def get_doc (self , encoding = None , ignore = 1 ):
138
- rv = autodoc .ClassDocumenter .get_doc (self , encoding , ignore )
139
- config = [u' ' + x for x in format_storage_config (self .object )]
140
- rv [0 ] = rv [0 ][:1 ] + [u'::' , u'' ] + config + [u'' ] + rv [0 ][1 :]
141
- return rv
142
-
143
-
144
91
def setup (app ):
145
92
from sphinx .domains .python import PyObject
146
93
app .add_object_type ('storage' , 'storage' , 'pair: %s; storage' ,
147
94
doc_field_types = PyObject .doc_field_types )
148
95
app .add_role ('gh' , github_issue_role )
149
96
app .add_role ('ghpr' , github_issue_role )
150
- app .add_autodocumenter (StorageDocumenter )
0 commit comments