Skip to content

Commit 3ec765a

Browse files
committed
try rewriting gi-docgen refs
1 parent bf11459 commit 3ec765a

File tree

3 files changed

+86
-35
lines changed

3 files changed

+86
-35
lines changed

README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ Local user install:
195195
.. code-block:: shell
196196
197197
$ pip install -e .[binary]
198-
$ pypy -m pip --user -e .
199198
200199
Run all tests:
201200

examples/gen-enums.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,58 @@ def remove_prefix(enum_str):
3737
return enum_str
3838

3939

40+
def rewrite_references(string):
41+
"""Rewrite a gi-docgen references to RST style.
42+
43+
gi-docgen references look like this:
44+
45+
[func@version]
46+
[class@Image]
47+
[func@Image.bandjoin]
48+
[meth@Image.add]
49+
[ctor@Image.new_from_file]
50+
[enum@SdfShape]
51+
[enum@Vips.SdfShape.CIRCLE]
52+
53+
we look for the approximate patterns and rewrite in RST style, so:
54+
55+
:meth:`.version`
56+
:class:`.Image`
57+
:meth:`.Image.bandjoin`
58+
:meth:`.Image.new_from_file`
59+
:class:`.enums.SdfShape`
60+
:class:`.enums.SdfShape.CIRCLE`
61+
"""
62+
63+
import re
64+
while True:
65+
match = re.search(r"\[(.*?)@(.*?)\]", string)
66+
if not match:
67+
break
68+
69+
before = string[0:match.span(0)[0]]
70+
type = match[1]
71+
target = match[2]
72+
after = string[match.span(0)[1]:]
73+
74+
if type in ["ctor", "meth", "method", "func"]:
75+
python_type = "meth"
76+
elif type in ["class", "enum", "flags"]:
77+
python_type = "class"
78+
else:
79+
raise Exception(f'type "{type}" is unknown')
80+
81+
match = re.match("Vips.(.*)", target)
82+
if match:
83+
target = match[1]
84+
85+
if type == "enum":
86+
target = f"enums.{target}"
87+
88+
string = f"{before}:{python_type}:`.{target}`{after}"
89+
90+
return string
91+
4092
def generate_enums():
4193
all_nicknames = []
4294

@@ -70,7 +122,7 @@ def add_nickname(gtype, a, b):
70122
print(f' """{python_name}.')
71123
if enum_doc is not None:
72124
print('')
73-
print(f'{enum_doc.text}')
125+
print(f'{rewrite_references(enum_doc.text)}')
74126
print('')
75127
print('Attributes:')
76128
print('')
@@ -79,7 +131,7 @@ def add_nickname(gtype, a, b):
79131
member = node.find(f"goi:member[@name='{python_name}']", namespace)
80132
member_doc = member.find("goi:doc", namespace)
81133
if member_doc is not None:
82-
text = member_doc.text
134+
text = rewrite_references(member_doc.text)
83135
print(f' {python_name.upper()} (str): {text}')
84136
print('')
85137
print(' """')
@@ -123,7 +175,7 @@ def add_nickname(gtype, a, b):
123175
print(f' """{python_name}.')
124176
if enum_doc is not None:
125177
print('')
126-
print(f'{enum_doc.text}')
178+
print(f'{rewrite_references(enum_doc.text)}')
127179
print('')
128180
print('Attributes:')
129181
print('')
@@ -133,7 +185,7 @@ def add_nickname(gtype, a, b):
133185
member_doc = member.find("goi:doc", namespace)
134186
if member_doc is not None:
135187
text = member_doc.text
136-
print(f' {python_name.upper()} (int): {text}')
188+
print(f' {python_name.upper()} (int): {rewrite_references(text)}')
137189
print('')
138190
print(' """')
139191
print('')

pyvips/enums.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BandFormat(object):
88
The format used for each band element.
99
1010
Each corresponds to a native C type for the current machine. For example,
11-
[enum@Vips.BandFormat.USHORT] is `unsigned short`.
11+
:class:`.enums.BandFormat.USHORT` is `unsigned short`.
1212
1313
Attributes:
1414
@@ -52,7 +52,7 @@ class BandFormat(object):
5252
class BlendMode(object):
5353
"""BlendMode.
5454
55-
The various Porter-Duff and PDF blend modes. See [func@Image.composite],
55+
The various Porter-Duff and PDF blend modes. See :meth:`.Image.composite`,
5656
for example.
5757
5858
The Cairo docs have a nice explanation of all the blend modes:
@@ -250,13 +250,13 @@ class Interpretation(object):
250250
class DemandStyle(object):
251251
"""DemandStyle.
252252
253-
See [method@Image.pipelinev]. Operations can hint
253+
See :meth:`.Image.pipelinev`. Operations can hint
254254
the kind of demand geometry they prefer
255255
to the VIPS image IO system.
256256
257257
These demand styles are given below in order of increasing
258258
specialisation. When demanding output from a pipeline,
259-
[method@Image.generate]
259+
:meth:`.Image.generate`
260260
will use the most general style requested by the operations
261261
in the pipeline.
262262
@@ -267,18 +267,18 @@ class DemandStyle(object):
267267
@VIPS_DEMAND_STYLE_FATSTRIP -- This operation would like to output strips
268268
the width of the image and as high as possible. This option is suitable
269269
for area operations which do not violently transform coordinates, such
270-
as [method@Image.conv].
270+
as :meth:`.Image.conv`.
271271
272272
@VIPS_DEMAND_STYLE_THINSTRIP -- This operation would like to output strips
273273
the width of the image and a few pels high. This option is suitable for
274274
point-to-point operations, such as those in the arithmetic package.
275275
276276
@VIPS_DEMAND_STYLE_ANY -- This image is not being demand-read from a disc
277277
file (even indirectly) so any demand style is OK. It's used for things like
278-
[ctor@Image.black] where the pixels are calculated.
278+
:meth:`.Image.black` where the pixels are calculated.
279279
280280
::: seealso
281-
[method@Image.pipelinev].
281+
:meth:`.Image.pipelinev`.
282282
283283
Attributes:
284284
@@ -504,7 +504,7 @@ class OperationComplexget(object):
504504
class Combine(object):
505505
"""Combine.
506506
507-
How to combine values. See [method@Image.compass], for example.
507+
How to combine values. See :meth:`.Image.compass`, for example.
508508
509509
Attributes:
510510
@@ -524,8 +524,8 @@ class Combine(object):
524524
class Access(object):
525525
"""Access.
526526
527-
The type of access an operation has to supply. See [method@Image.tilecache]
528-
and [class@Foreign].
527+
The type of access an operation has to supply. See :meth:`.Image.tilecache`
528+
and :class:`.Foreign`.
529529
530530
@VIPS_ACCESS_RANDOM means requests can come in any order.
531531
@@ -548,7 +548,7 @@ class Access(object):
548548
class Extend(object):
549549
"""Extend.
550550
551-
See [method@Image.embed], [method@Image.conv], [method@Image.affine] and so on.
551+
See :meth:`.Image.embed`, :meth:`.Image.conv`, :meth:`.Image.affine` and so on.
552552
553553
When the edges of an image are extended, you can specify
554554
how you want the extension done.
@@ -571,7 +571,7 @@ class Extend(object):
571571
keep these frozen for back compat with vips7.
572572
573573
::: seealso
574-
[method@Image.embed].
574+
:meth:`.Image.embed`.
575575
576576
Attributes:
577577
@@ -600,7 +600,7 @@ class Extend(object):
600600
class CompassDirection(object):
601601
"""CompassDirection.
602602
603-
A direction on a compass. Used for [method@Image.gravity], for example.
603+
A direction on a compass. Used for :meth:`.Image.gravity`, for example.
604604
605605
Attributes:
606606
@@ -638,13 +638,13 @@ class CompassDirection(object):
638638
class Direction(object):
639639
"""Direction.
640640
641-
See [method@Image.flip], [method@Image.join] and so on.
641+
See :meth:`.Image.flip`, :meth:`.Image.join` and so on.
642642
643-
Operations like [method@Image.flip] need to be told whether to flip left-right or
643+
Operations like :meth:`.Image.flip` need to be told whether to flip left-right or
644644
top-bottom.
645645
646646
::: seealso
647-
[method@Image.flip], [method@Image.join].
647+
:meth:`.Image.flip`, :meth:`.Image.join`.
648648
649649
Attributes:
650650
@@ -661,13 +661,13 @@ class Direction(object):
661661
class Align(object):
662662
"""Align.
663663
664-
See [method@Image.join] and so on.
664+
See :meth:`.Image.join` and so on.
665665
666-
Operations like [method@Image.join] need to be told whether to align images on the
666+
Operations like :meth:`.Image.join` need to be told whether to align images on the
667667
low or high coordinate edge, or centre.
668668
669669
::: seealso
670-
[method@Image.join].
670+
:meth:`.Image.join`.
671671
672672
Attributes:
673673
@@ -688,15 +688,15 @@ class Interesting(object):
688688
"""Interesting.
689689
690690
Pick the algorithm vips uses to decide image "interestingness". This is used
691-
by [method@Image.smartcrop], for example, to decide what parts of the image to
691+
by :meth:`.Image.smartcrop`, for example, to decide what parts of the image to
692692
keep.
693693
694694
#VIPS_INTERESTING_NONE and #VIPS_INTERESTING_LOW mean the same -- the
695695
crop is positioned at the top or left. #VIPS_INTERESTING_HIGH positions at
696696
the bottom or right.
697697
698698
::: seealso
699-
[method@Image.smartcrop].
699+
:meth:`.Image.smartcrop`.
700700
701701
Attributes:
702702
@@ -728,12 +728,12 @@ class Interesting(object):
728728
class Angle(object):
729729
"""Angle.
730730
731-
See [method@Image.rot] and so on.
731+
See :meth:`.Image.rot` and so on.
732732
733733
Fixed rotate angles.
734734
735735
::: seealso
736-
[method@Image.rot].
736+
:meth:`.Image.rot`.
737737
738738
Attributes:
739739
@@ -756,12 +756,12 @@ class Angle(object):
756756
class Angle45(object):
757757
"""Angle45.
758758
759-
See [method@Image.rot45] and so on.
759+
See :meth:`.Image.rot45` and so on.
760760
761761
Fixed rotate angles.
762762
763763
::: seealso
764-
[method@Image.rot45].
764+
:meth:`.Image.rot45`.
765765
766766
Attributes:
767767
@@ -816,11 +816,11 @@ class Precision(object):
816816
class TextWrap(object):
817817
"""TextWrap.
818818
819-
Sets the word wrapping style for [ctor@Image.text] when used with a maximum
819+
Sets the word wrapping style for :meth:`.Image.text` when used with a maximum
820820
width.
821821
822822
::: seealso
823-
[ctor@Image.text].
823+
:meth:`.Image.text`.
824824
825825
Attributes:
826826
@@ -846,7 +846,7 @@ class SdfShape(object):
846846
The SDF to generate,
847847
848848
::: seealso
849-
[ctor@Image.sdf].
849+
:meth:`.Image.sdf`.
850850
851851
Attributes:
852852
@@ -1257,8 +1257,8 @@ class Kernel(object):
12571257
class PCS(object):
12581258
"""PCS.
12591259
1260-
Pick a Profile Connection Space for [method@Image.icc_import] and
1261-
[method@Image.icc_export]. LAB is usually best, XYZ can be more convenient in some
1260+
Pick a Profile Connection Space for :meth:`.Image.icc_import` and
1261+
:meth:`.Image.icc_export`. LAB is usually best, XYZ can be more convenient in some
12621262
cases.
12631263
12641264
Attributes:

0 commit comments

Comments
 (0)