Skip to content

Commit 643003b

Browse files
committed
Linting.
1 parent 4952f92 commit 643003b

File tree

9 files changed

+110
-78
lines changed

9 files changed

+110
-78
lines changed

doc-source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'python': ('https://docs.python.org/3/', None),
7171
'sphinx': ('https://www.sphinx-doc.org/en/stable/', None),
7272
'pandas': ('https://pandas.pydata.org/docs/', None),
73+
'consolekit': ('https://consolekit.readthedocs.io/en/latest/', None),
7374
}
7475

7576
html_theme = 'domdf_sphinx_theme'

domdf_python_tools/iterative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def double_chain(iterable: Iterable[Iterable]):
151151
yield from itertools.chain.from_iterable(itertools.chain.from_iterable(iterable))
152152

153153

154-
def flatten(iterable: Iterable, primitives: Tuple[Type] = (str, int, float)):
154+
def flatten(iterable: Iterable, primitives: Tuple[Type, ...] = (str, int, float)):
155155
"""
156156
Flattens a mixed list of primitive types and iterables of those types into a single list,
157157
regardless of nesting.
@@ -171,7 +171,7 @@ def flatten(iterable: Iterable, primitives: Tuple[Type] = (str, int, float)):
171171
raise NotImplementedError
172172

173173

174-
Branch = Union[List[str], List["Branch"]]
174+
Branch = Union[Sequence[str], Sequence[Union[Sequence[str], Sequence]]]
175175

176176

177177
def make_tree(tree: Branch) -> Iterator[str]:

domdf_python_tools/terminal_colours.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
This module generates ANSI character codes to printing colors to terminals.
88
See: http://en.wikipedia.org/wiki/ANSI_escape_code
9+
10+
.. deprecated:: Use :mod:`consolekit.terminal_colours` instead.
911
"""
1012
#
1113
# Copyright © 2020 Dominic Davis-Foster <[email protected]>

domdf_python_tools/utils.py

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
:func:`~domdf_python_tools.iterative.double_chain`
2424
moved to :func:`domdf_python_tools.iterative`.
2525
26-
They can still be importrd from here until version 2.0.0, but that use is deprecated.
26+
They can still be imported from here until version 2.0.0, but that use is deprecated.
2727
"""
2828
#
2929
# Copyright © 2018-2020 Dominic Davis-Foster <[email protected]>
@@ -132,38 +132,6 @@
132132
SPACE_PLACEHOLDER = '␣'
133133

134134

135-
def check_dependencies(dependencies: Iterable[str], prt: bool = True) -> List[str]:
136-
"""
137-
Check whether one or more dependencies are available to be imported.
138-
139-
:param dependencies: The list of dependencies to check the availability of.
140-
:param prt: Whether the status should be printed to the terminal.
141-
142-
:return: A list of any missing modules.
143-
"""
144-
145-
# stdlib
146-
from pkgutil import iter_modules
147-
148-
modules = {x[1] for x in iter_modules()}
149-
missing_modules = []
150-
151-
for requirement in dependencies:
152-
if requirement not in modules:
153-
missing_modules.append(requirement)
154-
155-
if prt:
156-
if len(missing_modules) == 0:
157-
print("All modules installed")
158-
else:
159-
print("The following modules are missing.")
160-
print(missing_modules)
161-
print("Please check the documentation.")
162-
print('')
163-
164-
return missing_modules
165-
166-
167135
def cmp(x, y) -> int:
168136
"""
169137
Implementation of ``cmp`` for Python 3.
@@ -641,42 +609,80 @@ def _inner(*args, **kwargs):
641609

642610

643611
chunks = deprecated(
644-
"1.4.0",
645-
"2.0.0",
646-
__version__,
647-
"Import from :mod:`domdf_python_tools.iterative` instead.",
612+
deprecated_in="1.4.0",
613+
removed_in="2.0.0",
614+
current_version=__version__,
615+
details="Import from 'domdf_python_tools.iterative' instead.",
648616
)(
649617
iterative.chunks
650618
)
651619
permutations = deprecated(
652-
"1.4.0",
653-
"2.0.0",
654-
__version__,
655-
"Import from :mod:`domdf_python_tools.iterative` instead.",
620+
deprecated_in="1.4.0",
621+
removed_in="2.0.0",
622+
current_version=__version__,
623+
details="Import from 'domdf_python_tools.iterative' instead.",
656624
)(
657625
iterative.permutations
658626
)
659627
split_len = deprecated(
660-
"1.4.0",
661-
"2.0.0",
662-
__version__,
663-
"Import from :mod:`domdf_python_tools.iterative` instead.",
628+
deprecated_in="1.4.0",
629+
removed_in="2.0.0",
630+
current_version=__version__,
631+
details="Import from 'domdf_python_tools.iterative' instead.",
664632
)(
665633
iterative.split_len
666634
)
667635
Len = deprecated(
668-
"1.4.0",
669-
"2.0.0",
670-
__version__,
671-
"Import from :mod:`domdf_python_tools.iterative` instead.",
636+
deprecated_in="1.4.0",
637+
removed_in="2.0.0",
638+
current_version=__version__,
639+
details="Import from 'domdf_python_tools.iterative' instead.",
672640
)(
673641
iterative.Len
674642
)
675643
double_chain = deprecated(
676-
"1.4.0",
677-
"2.0.0",
678-
__version__,
679-
"Import from :mod:`domdf_python_tools.iterative` instead.",
644+
deprecated_in="1.4.0",
645+
removed_in="2.0.0",
646+
current_version=__version__,
647+
details="Import from 'domdf_python_tools.iterative' instead.",
680648
)(
681649
iterative.double_chain
682650
)
651+
652+
653+
@deprecated(
654+
deprecated_in="1.4.0",
655+
removed_in="2.0.0",
656+
current_version=__version__,
657+
details="Import from :mod:`packing_tape.requirements` instead.",
658+
)
659+
def check_dependencies(dependencies: Iterable[str], prt: bool = True) -> List[str]:
660+
"""
661+
Check whether one or more dependencies are available to be imported.
662+
663+
:param dependencies: The list of dependencies to check the availability of.
664+
:param prt: Whether the status should be printed to the terminal.
665+
666+
:return: A list of any missing modules.
667+
"""
668+
669+
# stdlib
670+
from pkgutil import iter_modules
671+
672+
modules = {x[1] for x in iter_modules()}
673+
missing_modules = []
674+
675+
for requirement in dependencies:
676+
if requirement not in modules:
677+
missing_modules.append(requirement)
678+
679+
if prt:
680+
if len(missing_modules) == 0:
681+
print("All modules installed")
682+
else:
683+
print("The following modules are missing:")
684+
print(missing_modules)
685+
print("Please check the documentation.")
686+
print('')
687+
688+
return missing_modules

repo_helper.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ tox_testenv_extras: all
5959

6060
intersphinx_mapping:
6161
- "'pandas': ('https://pandas.pydata.org/docs/', None)"
62+
- "'consolekit': ('https://consolekit.readthedocs.io/en/latest/', None)"
6263

6364
mypy_deps:
6465
- pprint36

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# * options
55
# * options.packages.find
66
# * mypy
7+
# * options.entry_points
78

89
[metadata]
910
name = domdf_python_tools

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# stdlib
12
import os
23
from pathlib import Path
34

5+
# 3rd party
46
import pytest
57

68
pytest_plugins = ("domdf_python_tools.testing", )

tests/test_iterative_/test_make_tree.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
│ ├── idna<3,>=2.5
77
│ ├── urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
88
│ └── certifi>=2017.4.17
9-
└── msgpack>=0.5.2
9+
└── msgpack>=0.5.2

tests/test_utils.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_check_dependencies(capsys):
4242
missing_deps = utils.check_dependencies(deps)
4343
captured = capsys.readouterr()
4444
stdout = captured.out.split("\n")
45-
assert stdout[0] == "The following modules are missing."
45+
assert stdout[0] == "The following modules are missing:"
4646
assert stdout[1] == "['madeup_module']"
4747
assert stdout[2] == "Please check the documentation."
4848
assert stdout[3] == ''
@@ -333,28 +333,47 @@ def test_protocol_pandas(self):
333333
assert isinstance(pandas.DataFrame, HasHead)
334334
assert isinstance(pandas.Series, HasHead)
335335

336-
def test_namedtuple(self):
337-
foo = namedtuple("foo", "a, b, c, d, e, f, g, h, i, j, k, l, m")
338-
assert head(
339-
foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
340-
) == "foo(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, ...)"
341-
assert head(
342-
foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), 13
343-
) == "foo(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, k=11, l=12, m=13)"
336+
foo = namedtuple("foo", "a, b, c, d, e, f, g, h, i, j, k, l, m")
344337

345-
def test_tuple(self):
346-
assert head((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)) == "(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...)"
347-
assert head(
348-
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
349-
13,
350-
) == "(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)"
338+
@pytest.mark.parametrize(
339+
"args, expects",
340+
[
341+
((foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), ),
342+
"foo(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, ...)"),
343+
((foo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), 13),
344+
"foo(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, k=11, l=12, m=13)"),
345+
]
346+
)
347+
def test_namedtuple(self, args, expects):
348+
assert head(*args) == expects
351349

352-
def test_list(self):
353-
assert head([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]"
354-
assert head(
355-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
356-
13,
357-
) == "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]"
350+
@pytest.mark.parametrize(
351+
"args, expects",
352+
[
353+
(((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), ), "(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...)"),
354+
((
355+
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
356+
13,
357+
),
358+
"(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)"),
359+
]
360+
)
361+
def test_tuple(self, args, expects):
362+
assert head(*args) == expects
363+
364+
@pytest.mark.parametrize(
365+
"args, expects",
366+
[
367+
(([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], ), "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]"),
368+
((
369+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
370+
13,
371+
),
372+
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]"),
373+
]
374+
)
375+
def test_list(self, args, expects):
376+
assert head(*args) == expects
358377

359378
def test_data_frame(self):
360379
pandas = pytest.importorskip("pandas")
@@ -436,7 +455,7 @@ def deprecated_func(*args, **kwargs):
436455

437456

438457
def test_diff(file_regression: FileRegressionFixture):
439-
data_dir = PathPlus(__file__).parent / "test_diff"
458+
data_dir = PathPlus(__file__).parent / "test_diff_"
440459
original = data_dir / "original"
441460
modified = data_dir / "modified"
442461

0 commit comments

Comments
 (0)