Skip to content

Commit 4c7f61b

Browse files
committed
Linting.
1 parent b2e8b6a commit 4c7f61b

File tree

8 files changed

+54
-38
lines changed

8 files changed

+54
-38
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ repos:
7373
- id: forbid-crlf
7474

7575
- repo: https://github.com/repo-helper/formate
76-
rev: v0.4.5
76+
rev: v0.4.8
7777
hooks:
7878
- id: formate
7979
exclude: ^(doc-source/conf|__pkginfo__|setup)\.(_)?py$

domdf_python_tools/compat/importlib_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# noqa: D100
2+
13
# stdlib
24
import sys
35

domdf_python_tools/compat/importlib_metadata.pyi

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PackagePath(pathlib.PurePosixPath):
3737
def locate(self) -> PathLike[str]: ...
3838

3939
# The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
40-
hash: Optional[FileHash]
40+
hash: Optional[FileHash] # noqa: A003 # pylint: disable=redefined-builtin
4141
size: Optional[int]
4242
dist: Distribution
4343

@@ -64,12 +64,14 @@ class Distribution:
6464

6565
@overload
6666
@classmethod
67-
def discover(cls,
68-
*,
69-
context: None = ...,
70-
name: Optional[str] = ...,
71-
path: List[str] = ...,
72-
**kwargs: Any) -> Iterable[Distribution]: ...
67+
def discover(
68+
cls,
69+
*,
70+
context: None = ...,
71+
name: Optional[str] = ...,
72+
path: List[str] = ...,
73+
**kwargs: Any,
74+
) -> Iterable[Distribution]: ...
7375

7476
@staticmethod
7577
def at(path: StrPath) -> PathDistribution: ...
@@ -118,11 +120,13 @@ def distribution(distribution_name: str) -> Distribution: ...
118120
def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
119121

120122
@overload
121-
def distributions(*,
122-
context: None = ...,
123-
name: Optional[str] = ...,
124-
path: List[str] = ...,
125-
**kwargs: Any) -> Iterable[Distribution]: ...
123+
def distributions(
124+
*,
125+
context: None = ...,
126+
name: Optional[str] = ...,
127+
path: List[str] = ...,
128+
**kwargs: Any,
129+
) -> Iterable[Distribution]: ...
126130

127131
def metadata(distribution_name: str) -> Message: ...
128132
def version(distribution_name: str) -> str: ...

domdf_python_tools/compat/importlib_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# noqa: D100
2+
13
# stdlib
24
import sys
35

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# From https://github.com/python/typeshed
22
# Apache-2.0 Licensed
33

4-
import sys
5-
from typing import Any
6-
4+
# stdlib
75
import os
6+
import sys
87
from pathlib import Path
98
from types import ModuleType
10-
from typing import BinaryIO, ContextManager, Iterator, TextIO, Union
9+
from typing import Any, BinaryIO, ContextManager, Iterator, TextIO, Union
1110

1211
Package = Union[str, ModuleType]
1312
Resource = Union[str, os.PathLike[Any]]
13+
1414
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
1515
def open_text(package: Package, resource: Resource, encoding: str = ..., errors: str = ...) -> TextIO: ...
1616
def read_binary(package: Package, resource: Resource) -> bytes: ...
@@ -20,7 +20,9 @@ def is_resource(package: Package, name: str) -> bool: ...
2020
def contents(package: Package) -> Iterator[str]: ...
2121

2222
if sys.version_info >= (3, 9):
23-
from contextlib import AbstractContextManager
24-
from importlib.abc import Traversable
25-
def files(package: Package) -> Traversable: ...
26-
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
23+
# stdlib
24+
from contextlib import AbstractContextManager
25+
from importlib.abc import Traversable
26+
27+
def files(package: Package) -> Traversable: ...
28+
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...

domdf_python_tools/paths.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def append(var: str, filename: PathLike, **kwargs) -> int:
149149
:param filename: The file to append to
150150
"""
151151

152-
with open(os.path.join(os.getcwd(), filename), 'a', **kwargs) as f:
152+
kwargs.setdefault("encoding", "UTF-8")
153+
154+
with open(os.path.join(os.getcwd(), filename), 'a', **kwargs) as f: # noqa: ENC001
153155
return f.write(var)
154156

155157

@@ -268,7 +270,9 @@ def read(filename: PathLike, **kwargs) -> str:
268270
:return: The contents of the file.
269271
"""
270272

271-
with open(os.path.join(os.getcwd(), filename), **kwargs) as f:
273+
kwargs.setdefault("encoding", "UTF-8")
274+
275+
with open(os.path.join(os.getcwd(), filename), **kwargs) as f: # noqa: ENC001
272276
return f.read()
273277

274278

@@ -312,7 +316,9 @@ def write(var: str, filename: PathLike, **kwargs) -> None:
312316
:param filename: The file to write to.
313317
"""
314318

315-
with open(os.path.join(os.getcwd(), filename), 'w', **kwargs) as f:
319+
kwargs.setdefault("encoding", "UTF-8")
320+
321+
with open(os.path.join(os.getcwd(), filename), 'w', **kwargs) as f: # noqa: ENC001
316322
f.write(var)
317323

318324

tests/test_dir_comparator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def comparator_tmpdir(tmp_pathplus):
4343
fn = "FiLe" # Verify case-insensitive comparison
4444
else:
4545
fn = "file"
46-
with open(os.path.join(dir, fn), 'w') as output:
46+
with open(os.path.join(dir, fn), 'w', encoding="UTF-8") as output:
4747
output.write('Contents of file go here.\n')
4848

49-
with open(os.path.join(data.dir_diff, "file2"), 'w') as output:
49+
with open(os.path.join(data.dir_diff, "file2"), 'w', encoding="UTF-8") as output:
5050
output.write('An extra file.\n')
5151

5252
return data
@@ -85,7 +85,7 @@ def test_cmpfiles(self, comparator_tmpdir):
8585
), "Comparing directory to same fails"
8686

8787
# Add different file2
88-
with open(os.path.join(comparator_tmpdir.dir, "file2"), 'w') as output:
88+
with open(os.path.join(comparator_tmpdir.dir, "file2"), 'w', encoding="UTF-8") as output:
8989
output.write('Different contents.\n')
9090

9191
assert filecmp.cmpfiles(
@@ -174,7 +174,7 @@ def test_dircmp(self, comparator_tmpdir):
174174
self._assert_report(d.report, expected_report)
175175

176176
# Add different file2
177-
with open(os.path.join(comparator_tmpdir.dir_diff, "file2"), 'w') as output:
177+
with open(os.path.join(comparator_tmpdir.dir_diff, "file2"), 'w', encoding="UTF-8") as output:
178178
output.write('Different contents.\n')
179179
d = DirComparator(comparator_tmpdir.dir, comparator_tmpdir.dir_diff)
180180
assert d.same_files == ["file"]

tox.ini

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,19 @@ timeout = 300
139139

140140
[flake8]
141141
max-line-length = 120
142-
select = E111 E112 E113 E121 E122 E125 E127 E128 E129 E131 E133 E201 E202 E203 E211 E222 E223 E224 E225 E225 E226 E227 E228 E231 E241 E242 E251 E261 E262 E265 E271 E272 E301 E302 E303 E304 E305 E306 E402 E502 E703 E711 E712 E713 E714 E721 W291 W292 W293 W391 W504 YTT101 YTT102 YTT103 YTT201 YTT202 YTT203 YTT204 YTT301 YTT302 YTT303 STRFTIME001 STRFTIME002 SXL001 PT001 PT002 PT003 PT005 PT006 PT007 PT008 PT009 PT010 PT011 PT012 PT013 PT014 PT015 PT016 PT017 PT018 PT019 PT020 PT021 RST201 RST202 RST203 RST204 RST205 RST206 RST207 RST208 RST210 RST211 RST212 RST213 RST214 RST215 RST216 RST217 RST218 RST219 RST299 RST301 RST302 RST303 RST304 RST305 RST306 RST399 RST401 RST499 RST900 RST901 RST902 RST903 Q001 Q002 Q003 A001 A002 A003 TYP001 TYP002 TYP003 TYP004 TYP005 TYP006 Y001,Y002 Y003 Y004 Y005 Y006 Y007 Y008 Y009 Y010 Y011 Y012 Y013 Y014 Y015 Y090 Y091 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
143-
exclude = doc-source,.git,__pycache__,old,build,dist,__pkginfo__.py,setup.py,.tox,venv
142+
select = E111 E112 E113 E121 E122 E125 E127 E128 E129 E131 E133 E201 E202 E203 E211 E222 E223 E224 E225 E225 E226 E227 E228 E231 E241 E242 E251 E261 E262 E265 E271 E272 E303 E304 E306 E402 E502 E703 E711 E712 E713 E714 E721 W291 W292 W293 W391 W504 YTT101 YTT102 YTT103 YTT201 YTT202 YTT203 YTT204 YTT301 YTT302 YTT303 STRFTIME001 STRFTIME002 SXL001 PT001 PT002 PT003 PT006 PT007 PT008 PT009 PT010 PT011 PT012 PT013 PT014 PT015 PT016 PT017 PT018 PT019 PT020 PT021 RST201 RST202 RST203 RST204 RST205 RST206 RST207 RST208 RST210 RST211 RST212 RST213 RST214 RST215 RST216 RST217 RST218 RST219 RST299 RST301 RST302 RST303 RST304 RST305 RST306 RST399 RST401 RST499 RST900 RST901 RST902 RST903 Q001 Q002 Q003 A001 A002 A003 TYP001 TYP002 TYP003 TYP004 TYP005 TYP006 ENC001 ENC002 ENC003 ENC004 ENC011 ENC012 ENC021 ENC022 ENC023 ENC024 ENC025 ENC026 Y001,Y002 Y003 Y004 Y005 Y006 Y007 Y008 Y009 Y010 Y011 Y012 Y013 Y014 Y015 Y090 Y091 E301 E302 E305 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002
143+
extend-exclude = doc-source,old,build,dist,__pkginfo__.py,setup.py,venv
144144
rst-directives =
145145
TODO
146-
envvar
147-
extras-require
148146
autosummary-widths
149147
autosummary2
150148
autovariable
151149
bold-title
152-
rst-roles =
153-
manpage
154-
bold-title
155-
inline-code
150+
envvar
151+
extras-require
156152
per-file-ignores =
157-
tests/*: D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
158-
*/*.pyi: D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
153+
tests/*: D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002
154+
*/*.pyi: E301 E302 E305 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002
159155
tests/list_tests.py: PT011 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
160156
tests/test_paths_stdlib.py: PT011 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
161157
tests/test_pretty_print.py: PT011 D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000
@@ -165,6 +161,10 @@ inline-quotes = "
165161
multiline-quotes = """
166162
docstring-quotes = """
167163
count = True
164+
min_python_version = 3.6
165+
rst-roles = manpage
166+
bold-title
167+
inline-code
168168
169169
[testenv]
170170
setenv =

0 commit comments

Comments
 (0)