Skip to content

Commit f726f63

Browse files
committed
Cleanup
1 parent 3a18ca0 commit f726f63

File tree

11 files changed

+106
-111
lines changed

11 files changed

+106
-111
lines changed

domdf_python_tools/pagesizes/units.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ class Unit(float):
164164
_in_pt: float = 1
165165

166166
def __repr__(self):
167-
value = _rounders(float(self), '0.000')
168-
as_pt = _rounders(self.as_pt(), '0.000')
167+
value = _rounders(float(self), "0.000")
168+
as_pt = _rounders(self.as_pt(), "0.000")
169169
return f"<Unit '{value}\u205F{self.name}': {as_pt}pt>"
170170

171171
def __mul__(self, other: Union[float, "Unit"]) -> "Unit":

domdf_python_tools/pagesizes/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ def to_length(s):
126126
"""
127127

128128
try:
129-
if s[-2:] == 'cm':
129+
if s[-2:] == "cm":
130130
return float(s[:-2]) * cm
131-
if s[-2:] == 'in':
131+
if s[-2:] == "in":
132132
return float(s[:-2]) * inch
133-
if s[-2:] == 'pt':
133+
if s[-2:] == "pt":
134134
return float(s[:-2])
135135
if s[-1:] == 'i':
136136
return float(s[:-1]) * inch
137-
if s[-2:] == 'mm':
137+
if s[-2:] == "mm":
138138
return float(s[:-2]) * mm
139-
if s[-4:] == 'pica':
139+
if s[-4:] == "pica":
140140
return float(s[:-4]) * pica
141141
return float(s)
142142
except:

domdf_python_tools/paths.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,7 @@ def delete(filename: PathLike):
127127
os.remove(os.path.join(os.getcwd(), filename))
128128

129129

130-
def maybe_make(
131-
directory: PathLike,
132-
mode=0o777,
133-
parents: bool = False,
134-
exist_ok: bool = False
135-
):
130+
def maybe_make(directory: PathLike, mode=0o777, parents: bool = False, exist_ok: bool = False):
136131
"""
137132
Create a directory at this given path, but only if the directory does not already exist.
138133
@@ -194,10 +189,7 @@ def read(filename: PathLike) -> str:
194189
return f.read()
195190

196191

197-
def relpath(
198-
path: PathLike,
199-
relative_to: Optional[PathLike] = None
200-
) -> pathlib.Path:
192+
def relpath(path: PathLike, relative_to: Optional[PathLike] = None) -> pathlib.Path:
201193
"""
202194
Returns the path for the given file or directory relative to the given
203195
directory or, if that would require path traversal, returns the absolute path.
@@ -256,10 +248,10 @@ def clean_writer(string: str, fp: IO) -> None:
256248

257249
buffer = []
258250

259-
for line in string.split("\n"):
251+
for line in string.split('\n'):
260252
buffer.append(line.rstrip())
261253

262-
while buffer[-1:] == [""]:
254+
while buffer[-1:] == ['']:
263255
buffer = buffer[:-1]
264256

265257
for line in buffer:

domdf_python_tools/terminal.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#
6161

6262
# stdlib
63+
import fcntl
6364
import inspect
6465
import os
6566
import platform
@@ -68,6 +69,7 @@
6869
import struct
6970
import subprocess
7071
import sys
72+
import termios
7173
import textwrap
7274
from typing import Optional, Tuple
7375

@@ -80,7 +82,7 @@ def clear() -> None:
8082
"""
8183

8284
if os.name == "nt":
83-
os.system('cls')
85+
os.system("cls")
8486
else:
8587
print("\033c", end='')
8688

@@ -90,7 +92,7 @@ def br() -> None:
9092
Prints a line break
9193
"""
9294

93-
print("")
95+
print('')
9496

9597

9698
def interrupt() -> None:
@@ -148,13 +150,13 @@ def get_terminal_size() -> Tuple[int, int]:
148150
current_os = platform.system()
149151
tuple_xy = None
150152

151-
if current_os == 'Windows':
153+
if current_os == "Windows":
152154
tuple_xy = _get_terminal_size_windows()
153155
if tuple_xy is None:
154156
tuple_xy = _get_terminal_size_tput()
155157
# needed for window's python in cygwin's xterm!
156158

157-
if current_os in ['Linux', 'Darwin'] or current_os.startswith('CYGWIN'):
159+
if current_os in {"Linux", "Darwin"} or current_os.startswith("CYGWIN"):
158160
tuple_xy = _get_terminal_size_linux()
159161

160162
if tuple_xy is None:
@@ -194,8 +196,8 @@ def _get_terminal_size_tput() -> Optional[Tuple[int, int]]:
194196
# get terminal width
195197
# src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window
196198
try:
197-
cols = int(subprocess.check_call(shlex.split('tput cols')))
198-
rows = int(subprocess.check_call(shlex.split('tput lines')))
199+
cols = int(subprocess.check_call(shlex.split("tput cols")))
200+
rows = int(subprocess.check_call(shlex.split("tput lines")))
199201
return cols, rows
200202
except:
201203
return None
@@ -205,11 +207,7 @@ def _get_terminal_size_linux() -> Optional[Tuple[int, int]]:
205207

206208
def ioctl_GWINSZ(fd):
207209
try:
208-
209-
# stdlib
210-
import fcntl
211-
import termios
212-
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
210+
cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
213211
return cr
214212
except:
215213
pass
@@ -218,15 +216,15 @@ def ioctl_GWINSZ(fd):
218216

219217
if not cr:
220218
try:
221-
fd = os.open(os.ctermid(), os.O_RDONLY) # type: ignore
219+
fd = os.open(os.ctermid(), os.O_RDONLY) # type: ignore
222220
cr = ioctl_GWINSZ(fd)
223221
os.close(fd)
224222
except:
225223
pass
226224

227225
if not cr:
228226
try:
229-
cr = (os.environ['LINES'], os.environ['COLUMNS'])
227+
cr = (os.environ["LINES"], os.environ["COLUMNS"])
230228
except:
231229
return None
232230

@@ -238,7 +236,7 @@ class Echo:
238236
Context manager for echoing variable assignments (in CPython)
239237
"""
240238

241-
def __init__(self, msg: str, indent: str = ' '):
239+
def __init__(self, msg: str, indent: str = " "):
242240
self.msg = msg
243241
self.indent = indent
244242

@@ -259,4 +257,4 @@ def __exit__(self, exc_t, exc_v, tb):
259257

260258
if __name__ == "__main__":
261259
size_x, size_y = get_terminal_size()
262-
print('width =', size_x, 'height =', size_y)
260+
print("width =", size_x, "height =", size_y)

domdf_python_tools/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def as_text(value: Any) -> str:
4343
"""
4444

4545
if value is None:
46-
return ""
46+
return ''
4747

4848
return str(value)
4949

@@ -77,7 +77,7 @@ def check_dependencies(dependencies: Iterable[str], prt: bool = True) -> List[st
7777
print("The following modules are missing.")
7878
print(missing_modules)
7979
print("Please check the documentation.")
80-
print("")
80+
print('')
8181

8282
return missing_modules
8383

@@ -110,7 +110,7 @@ def cmp(x, y) -> int:
110110
return int((x > y) - (x < y))
111111

112112

113-
def list2str(the_list: Iterable[Any], sep: str = ",") -> str:
113+
def list2str(the_list: Iterable[Any], sep: str = ',') -> str:
114114
"""
115115
Convert an iterable, such as a list, to a comma separated string.
116116
@@ -203,7 +203,7 @@ def split_len(string: str, n: int) -> List[str]:
203203
splitLen = split_len
204204

205205

206-
def str2tuple(input_string: str, sep: str = ",") -> Tuple[int, ...]:
206+
def str2tuple(input_string: str, sep: str = ',') -> Tuple[int, ...]:
207207
"""
208208
Convert a comma-separated string of integers into a tuple.
209209
@@ -239,9 +239,9 @@ def strtobool(val: Union[str, bool]) -> bool:
239239
return bool(val)
240240

241241
val = val.lower()
242-
if val in ('y', 'yes', 't', 'true', 'on', '1'):
242+
if val in ('y', "yes", 't', "true", "on", '1'):
243243
return True
244-
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
244+
elif val in ('n', "no", 'f', "false", "off", '0'):
245245
return False
246246
else:
247247
raise ValueError(f"invalid truth value {val!r}")
@@ -251,7 +251,7 @@ def enquote_value(value: Any) -> Union[str, bool, float]:
251251
"""
252252
Adds quotes to the given value, suitable for use in a templating system such as Jinja2.
253253
254-
floats, integerss, booleans, None, and the strings "True", "False" and "None" are returned as-is.
254+
floats, integers, booleans, None, and the strings "True", "False" and "None" are returned as-is.
255255
256256
:param value: The value to enquote
257257
"""

tests/test_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __dict__(self):
5151
return class_dict
5252

5353

54-
@pytest.fixture(scope="function")
54+
@pytest.fixture()
5555
def alice():
5656
return Person("Alice", 20, "IRC Lurker")
5757

tests/test_dates.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def test_set_timezone():
8989
if tz in {
9090
"America/Punta_Arenas",
9191
"America/Santiago",
92-
'Antarctica/Palmer',
93-
'Chile/Continental',
94-
'Chile/EasterIsland',
95-
'Pacific/Easter',
92+
"Antarctica/Palmer",
93+
"Chile/Continental",
94+
"Chile/EasterIsland",
95+
"Pacific/Easter",
9696
}:
9797
continue
9898

@@ -144,7 +144,7 @@ def test_parse_month():
144144

145145
assert dates.parse_month(month_idx) == month
146146

147-
for value in ["abc", 0, "0", -1, "-1", 13, "13"]:
147+
for value in ["abc", 0, '0', -1, "-1", 13, "13"]:
148148
with pytest.raises(ValueError):
149149
dates.parse_month(value)
150150

@@ -164,7 +164,7 @@ def test_get_month_number():
164164
for month_idx in range(1, 13):
165165
assert dates.get_month_number(month_idx) == month_idx
166166

167-
for value in ["abc", 0, "0", -1, "-1", 13, "13"]:
167+
for value in ["abc", 0, '0', -1, "-1", 13, "13"]:
168168
with pytest.raises(ValueError):
169169
dates.get_month_number(value)
170170

tests/test_doctools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def function_in_class_with_same_args(self, a, b, c, d):
166166

167167
def test_deindent_string():
168168
assert doctools.deindent_string("\t\t\t ") == ''
169-
assert doctools.deindent_string("\t\t\t Spam") == 'Spam'
170-
assert doctools.deindent_string("\t\t\t Spam \t\t\t") == 'Spam \t\t\t'
171-
assert doctools.deindent_string("\t\t\t Spam\n \t\t\t") == 'Spam\n'
169+
assert doctools.deindent_string("\t\t\t Spam") == "Spam"
170+
assert doctools.deindent_string("\t\t\t Spam \t\t\t") == "Spam \t\t\t"
171+
assert doctools.deindent_string("\t\t\t Spam\n \t\t\t") == "Spam\n"
172172
assert doctools.deindent_string(" \t\t\t") == ''
173-
assert doctools.deindent_string(" \t\t\tSpam") == 'Spam'
174-
assert doctools.deindent_string(" \t\t\tSpam\t\t\t ") == 'Spam\t\t\t '
175-
assert doctools.deindent_string(" \t\t\tSpam\n\t\t\t ") == 'Spam\n'
173+
assert doctools.deindent_string(" \t\t\tSpam") == "Spam"
174+
assert doctools.deindent_string(" \t\t\tSpam\t\t\t ") == "Spam\t\t\t "
175+
assert doctools.deindent_string(" \t\t\tSpam\n\t\t\t ") == "Spam\n"
176176

177177

178178
def test_decorators():

tests/test_paths.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def test_maybe_make():
4545
# Delete the directory and replace with a file
4646
test_dir.rmdir()
4747
assert test_dir.exists() is False
48-
test_dir.write_text("")
48+
test_dir.write_text('')
4949
assert test_dir.exists()
5050
assert test_dir.is_file()
5151

5252
paths.maybe_make(test_dir)
53-
assert test_dir.exists() and test_dir.is_file()
53+
assert test_dir.exists()
54+
assert test_dir.is_file()
5455

5556

5657
def test_parent_path():
@@ -67,7 +68,7 @@ def test_parent_path():
6768
assert str(paths.parent_path("spam/spam/spam")) == os.path.join("spam", "spam")
6869

6970

70-
@pytest.mark.skipif(sys.platform == 'win32', reason="Needs special-casing for Windows")
71+
@pytest.mark.skipif(sys.platform == "win32", reason="Needs special-casing for Windows")
7172
@pytest.mark.parametrize(
7273
"relto, relpath",
7374
[

0 commit comments

Comments
 (0)