Skip to content

Commit 3b5f0d4

Browse files
committed
Updated docs and linting.
1 parent 169885c commit 3b5f0d4

32 files changed

+508
-309
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ install:
2121
- pip install coveralls coverage_pyver_pragma
2222

2323
script:
24-
- tox
24+
- tox -vv
2525
after_success:
2626
- coveralls
2727

doc-source/api/pagesizes/classes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
.. automodule:: domdf_python_tools.pagesizes.classes
66
:undoc-members:
7+
:exclude-members: __slots__

doc-source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# User-configurable lines
1616
import domdf_python_tools
1717
domdf_python_tools.__docs = True
18+
overloads_location = "bottom"
1819
# End of user-configurable lines
1920

2021
github_username = "domdfcoding"

domdf_python_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# __init__.py
44
"""
5-
Helpful functions for Python 🐍 🛠️
5+
Helpful functions for Python 🐍 🛠️ .
66
"""
77
#
88
# Copyright © 2018-2020 by Dominic Davis-Foster <[email protected]>

domdf_python_tools/dates.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ def get_utc_offset(
5656
) -> Optional[datetime.timedelta]:
5757
"""
5858
Returns the offset between UTC and the requested timezone on the given date.
59-
If ``date`` is ``None`` then the current date is used.
59+
If ``date`` is :py:obj:`None` then the current date is used.
6060
6161
:param tz: ``pytz.timezone`` or a string representing the timezone
6262
:param date: The date to obtain the UTC offset for
63-
64-
:return:
6563
"""
6664

6765
if date is None:
@@ -79,12 +77,10 @@ def get_utc_offset(
7977
def get_timezone(tz: str, date: Optional[datetime.datetime] = None) -> Optional[datetime.tzinfo]:
8078
"""
8179
Returns a localized :class:`pytz.timezone` object for the given date.
82-
If ``date`` is ``None`` then the current date is used.
80+
If ``date`` is :py:obj:`None` then the current date is used.
8381
8482
:param tz: A string representing a pytz timezone
8583
:param date: The date to obtain the timezone for
86-
87-
:return:
8884
"""
8985

9086
if date is None:
@@ -113,7 +109,7 @@ def get_timezone(tz: str, date: Optional[datetime.datetime] = None) -> Optional[
113109

114110
def current_tzinfo() -> Optional[datetime.tzinfo]:
115111
"""
116-
Returns a tzinfo object for the current timezone
112+
Returns a tzinfo object for the current timezone.
117113
118114
:rtype: :class:`python:datetime.tzinfo`
119115
"""

domdf_python_tools/doctools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def make_sphinx_links(input_string: str, builtins_list: Optional[Sequence[str]]
134134
:param builtins_list: A list of builtins to make links for.
135135
:default builtins_list: dir(:py:obj:`builtins`)
136136
137-
:return: processed string with links
138-
"""
137+
:return: Processed string with links.
138+
""" # noqa SXL001
139139

140140
if builtins_list is None:
141141
builtins_list = dir(builtins)
@@ -199,7 +199,7 @@ def sphinxify_docstring() -> Callable:
199199
200200
Make sure to have ``'python': ('https://docs.python.org/3/', None),`` in the
201201
``intersphinx_mapping`` dict of your ``conf.py`` file for Sphinx.
202-
"""
202+
""" # noqa SXL001
203203

204204
def wrapper(target: F) -> F:
205205
target_doc = target.__doc__

domdf_python_tools/import_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def discover(
6060
match_func: Optional[Callable[[Any], bool]] = None,
6161
) -> List[Type[Any]]:
6262
"""
63-
Returns a list of objects in the directory matched by match_func
63+
Returns a list of objects in the directory matched by ``match_func``.
6464
6565
:param package: A Python package
6666
:param match_func: Function taking an object and returning true if the object is to be included in the output.

domdf_python_tools/pagesizes/classes.py

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,26 @@
5959

6060
class BaseSize(namedtuple("__BaseSize", "width, height")):
6161
"""
62-
Base class namedtuple representing a page size, in point
63-
64-
:param width: The page width
65-
:type width: |AnyNumber|
66-
:param height: The page height
67-
:type height: |AnyNumber|
62+
Base class namedtuple representing a page size, in point.
6863
"""
6964

7065
__slots__: List[str] = []
7166
_unit: Unit = pt
67+
68+
#: The page width.
7269
width: Unit
70+
71+
#: The page height.
7372
height: Unit
7473

7574
def __new__(cls, width: AnyNumber, height: AnyNumber):
75+
"""
76+
Create a new :class:`~.BaseSize` object.
77+
78+
:param width: The page width.
79+
:param height: The page height.
80+
"""
81+
7682
return super().__new__(
7783
cls,
7884
cls._unit(width),
@@ -88,10 +94,10 @@ def from_pt(cls, size: Tuple[float, float]):
8894
Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a
8995
page size in point.
9096
91-
:param size: The size, in point, to convert from
97+
:param size: The size, in point, to convert from.
9298
9399
:rtype: A subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
94-
"""
100+
""" # noqa D400
95101

96102
assert isinstance(size, PageSize)
97103

@@ -100,35 +106,35 @@ def from_pt(cls, size: Tuple[float, float]):
100106
@classmethod
101107
def from_size(cls, size: Tuple[AnyNumber, AnyNumber]) -> "BaseSize":
102108
"""
103-
Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a tuple
109+
Create a :class:`~domdf_python_tools.pagesizes.classes.BaseSize` object from a tuple.
104110
"""
105111

106112
return cls(*size)
107113

108114
def is_landscape(self) -> bool:
109115
"""
110-
Returns whether the page is in the landscape orientation
116+
Returns whether the page is in the landscape orientation.
111117
"""
112118

113119
return self.width >= self.height
114120

115121
def is_portrait(self) -> bool:
116122
"""
117-
Returns whether the page is in the portrait orientation
123+
Returns whether the page is in the portrait orientation.
118124
"""
119125

120126
return self.width < self.height
121127

122128
def is_square(self) -> bool:
123129
"""
124-
Returns whether the given pagesize is square
130+
Returns whether the given pagesize is square.
125131
"""
126132

127133
return self.width == self.height
128134

129135
def landscape(self) -> "BaseSize":
130136
"""
131-
Returns the pagesize in landscape orientation
137+
Returns the pagesize in landscape orientation.
132138
"""
133139

134140
if self.is_portrait():
@@ -138,7 +144,7 @@ def landscape(self) -> "BaseSize":
138144

139145
def portrait(self) -> "BaseSize":
140146
"""
141-
Returns the pagesize in portrait orientation
147+
Returns the pagesize in portrait orientation.
142148
"""
143149

144150
if self.is_landscape():
@@ -148,7 +154,7 @@ def portrait(self) -> "BaseSize":
148154

149155
def to_pt(self) -> "PageSize":
150156
"""
151-
Returns the page size in point
157+
Returns the page size in point.
152158
"""
153159

154160
return PageSize(self.width.as_pt(), self.height.as_pt())
@@ -159,83 +165,50 @@ def to_pt(self) -> "PageSize":
159165

160166
class Size_mm(BaseSize):
161167
"""
162-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
163-
representing a pagesize in millimeters.
164-
165-
:param width: The page width
166-
:type width: |AnyNumber|
167-
:param height: The page height
168-
:type height: |AnyNumber|
168+
Represents a pagesize in millimeters.
169169
"""
170170

171171
_unit = mm
172172

173173

174174
class Size_inch(BaseSize):
175175
"""
176-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
177-
representing a pagesize in inches.
178-
179-
:param width: The page width
180-
:type width: |AnyNumber|
181-
:param height: The page height
182-
:type height: |AnyNumber|
176+
Represents a pagesize in inches.
183177
"""
184178

185179
_unit = inch
186180

187181

188182
class Size_cm(BaseSize):
189183
"""
190-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
191-
representing a pagesize in centimeters.
192-
193-
:param width: The page width
194-
:type width: |AnyNumber|
195-
:param height: The page height
196-
:type height: |AnyNumber|
184+
Represents a pagesize in centimeters.
197185
"""
198186

199187
_unit = cm
200188

201189

202190
class Size_um(BaseSize):
203191
"""
204-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
205-
representing a pagesize in micrometers.
206-
207-
:param width: The page width
208-
:type width: |AnyNumber|
209-
:param height: The page height
210-
:type height: |AnyNumber|
192+
Represents a pagesize in micrometers.
211193
"""
212194

213195
_unit = um
214196

215197

216198
class Size_pica(BaseSize):
217199
"""
218-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
219-
representing a pagesize in pica.
220-
221-
:param width: The page width
222-
:type width: |AnyNumber|
223-
:param height: The page height
224-
:type height: |AnyNumber|
200+
Represents a pagesize in pica.
225201
"""
226202

227203
_unit = pica
228204

229205

230206
class PageSize(BaseSize):
231207
"""
232-
Subclass of :class:`~domdf_python_tools.pagesizes.classes.BaseSize`
233-
representing a pagesize in point.
208+
Represents a pagesize in point.
234209
235210
:param width: The page width
236-
:type width: |AnyNumber|
237211
:param height: The page height
238-
:type height: |AnyNumber|
239212
240213
The pagesize can be converted to other units using the properties below.
241214
"""
@@ -246,8 +219,8 @@ def __new__(cls, width: AnyNumber, height: AnyNumber, unit: AnyNumber = pt):
246219
"""
247220
Create a new :class:`~domdf_python_tools.pagesizes.classes.PageSize` object.
248221
249-
:param width:
250-
:param height:
222+
:param width: The page width.
223+
:param height: The page height.
251224
:param unit:
252225
"""
253226

domdf_python_tools/pagesizes/sizes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# sizes.py
44
"""
5-
Common pagesizes in point/pt
5+
Common pagesizes in point/pt.
66
77
.. TODO:: finish the list of the page sizes
88

domdf_python_tools/pagesizes/utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ def convert_from(
6262
value: Union[Sequence[AnyNumber], AnyNumber],
6363
from_: AnyNumber,
6464
) -> Union[float, Tuple[float, ...]]:
65-
"""
65+
r"""
6666
Convert ``value`` to point from the unit specified in ``from_``.
6767
6868
:param value:
69-
:param from_: The unit to convert from, specified as a number of points
70-
71-
:return:
69+
:param from\_: The unit to convert from, specified as a number of points.
7270
"""
7371

7472
if isinstance(value, Sequence):
@@ -94,9 +92,6 @@ def parse_measurement(measurement: str) -> Union[float, Tuple[float, ...]]:
9492
Parse the given measurement.
9593
9694
:param measurement:
97-
:type measurement: str
98-
99-
:return:
10095
"""
10196

10297
# TODO: docstring
@@ -109,7 +104,7 @@ def parse_measurement(measurement: str) -> Union[float, Tuple[float, ...]]:
109104

110105
val, unit = all_matches[0]
111106

112-
if "" in {val, unit}:
107+
if '' in {val, unit}:
113108
raise ValueError("Unable to parse measurement")
114109

115110
val = float(val)

0 commit comments

Comments
 (0)