Skip to content

Commit ff3fdd8

Browse files
committed
Apply black and ruff to code, and fix some ruff lint issues. Also close #613.
1 parent c98ada9 commit ff3fdd8

File tree

14 files changed

+955
-1078
lines changed

14 files changed

+955
-1078
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
rev: v0.3.3
1010
hooks:
1111
- id: ruff
12-
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
12+
args: [--fix, --exit-non-zero-on-fix, --show-fixes, --unsafe-fixes]
1313
- repo: https://github.com/psf/black
1414
rev: 24.3.0
1515
hooks:

ci/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
virtualenv>=16.6.0
22
pip>=19.1.1
33
setuptools>=18.0.1
4-
six>=1.14.0
54
tox
65
twine

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'sphinx.ext.extlinks',
1414
]
1515
if os.getenv('SPELLCHECK'):
16-
extensions += 'sphinxcontrib.spelling',
16+
extensions += ('sphinxcontrib.spelling',)
1717
spelling_show_suggestions = True
1818
spelling_lang = 'en_US'
1919

examples/adhoc-layout/example/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
# test merging multiple tox runs with a platform
44
# based branch
5-
if platform.python_implementation() == "PyPy":
5+
if platform.python_implementation() == 'PyPy':
6+
67
def add(a, b):
78
return a + b
89

910
else:
11+
1012
def add(a, b):
1113
return a + b

examples/adhoc-layout/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
setup(
55
name='example',
6-
packages=find_packages(include=['example'])
6+
packages=find_packages(include=['example']),
77
)

examples/src-layout/src/example/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
# test merging multiple tox runs with a platform
44
# based branch
5-
if platform.python_implementation() == "PyPy":
5+
if platform.python_implementation() == 'PyPy':
6+
67
def add(a, b):
78
return a + b
89

910
else:
11+
1012
def add(a, b):
1113
return a + b

setup.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#!/usr/bin/env python
22

33
import re
4-
from pathlib import Path
5-
from glob import glob
64
from itertools import chain
7-
from os.path import basename
8-
from os.path import dirname
9-
from os.path import join
10-
from os.path import splitext
5+
from pathlib import Path
116

127
from setuptools import Command
138
from setuptools import find_packages
@@ -32,24 +27,24 @@ def read(*names, **kwargs):
3227
class BuildWithPTH(build):
3328
def run(self, *args, **kwargs):
3429
super().run(*args, **kwargs)
35-
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
36-
dest = join(self.build_lib, basename(path))
30+
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
31+
dest = str(Path(self.build_lib) / Path(path).name)
3732
self.copy_file(path, dest)
3833

3934

4035
class EasyInstallWithPTH(easy_install):
4136
def run(self, *args, **kwargs):
4237
super().run(*args, **kwargs)
43-
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
44-
dest = join(self.install_dir, basename(path))
38+
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
39+
dest = str(Path(self.install_dir) / Path(path).name)
4540
self.copy_file(path, dest)
4641

4742

4843
class InstallLibWithPTH(install_lib):
4944
def run(self, *args, **kwargs):
5045
super().run(*args, **kwargs)
51-
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
52-
dest = join(self.install_dir, basename(path))
46+
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
47+
dest = str(Path(self.install_dir) / Path(path).name)
5348
self.copy_file(path, dest)
5449
self.outputs = [dest]
5550

@@ -60,13 +55,13 @@ def get_outputs(self):
6055
class DevelopWithPTH(develop):
6156
def run(self, *args, **kwargs):
6257
super().run(*args, **kwargs)
63-
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
64-
dest = join(self.install_dir, basename(path))
58+
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
59+
dest = str(Path(self.install_dir) / Path(path).name)
6560
self.copy_file(path, dest)
6661

6762

6863
class GeneratePTH(Command):
69-
user_options = []
64+
user_options = ()
7065

7166
def initialize_options(self):
7267
pass
@@ -75,11 +70,9 @@ def finalize_options(self):
7570
pass
7671

7772
def run(self):
78-
with open(join(dirname(__file__), 'src', 'pytest-cov.pth'), 'w') as fh:
79-
with open(join(dirname(__file__), 'src', 'pytest-cov.embed')) as sh:
80-
fh.write(
81-
f"import os, sys;exec({sh.read().replace(' ', ' ')!r})"
82-
)
73+
with Path(__file__).parent.joinpath('src', 'pytest-cov.pth').open('w') as fh:
74+
with Path(__file__).parent.joinpath('src', 'pytest-cov.embed').open() as sh:
75+
fh.write(f"import os, sys;exec({sh.read().replace(' ', ' ')!r})")
8376

8477

8578
setup(
@@ -124,19 +117,23 @@ def run(self):
124117
'Issue Tracker': 'https://github.com/pytest-dev/pytest-cov/issues',
125118
},
126119
keywords=[
127-
'cover', 'coverage', 'pytest', 'py.test', 'distributed', 'parallel',
120+
'cover',
121+
'coverage',
122+
'pytest',
123+
'py.test',
124+
'distributed',
125+
'parallel',
128126
],
129127
python_requires='>=3.8',
130128
install_requires=[
131129
'pytest>=4.6',
132-
'coverage[toml]>=5.2.1'
130+
'coverage[toml]>=5.2.1',
133131
],
134132
extras_require={
135133
'testing': [
136134
'fields',
137135
'hunter',
138136
'process-tests',
139-
'six',
140137
'pytest-xdist',
141138
'virtualenv',
142139
]

src/pytest_cov/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"""pytest-cov: avoid already-imported warning: PYTEST_DONT_REWRITE."""
2+
23
__version__ = '4.1.0'

src/pytest_cov/compat.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
try:
2-
from StringIO import StringIO
3-
except ImportError:
4-
from io import StringIO
5-
6-
7-
StringIO # pyflakes, this is for re-export
8-
9-
101
class SessionWrapper:
112
def __init__(self, session):
123
self._session = session

src/pytest_cov/embed.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
that code coverage is being collected we activate coverage based on
1414
info passed via env vars.
1515
"""
16+
1617
import atexit
1718
import os
1819
import signal
@@ -52,7 +53,7 @@ def init():
5253
data_suffix=True,
5354
config_file=cov_config,
5455
auto_data=True,
55-
data_file=cov_datafile
56+
data_file=cov_datafile,
5657
)
5758
cov.load()
5859
cov.start()
@@ -70,7 +71,7 @@ def _cleanup(cov):
7071
cov._auto_save = False # prevent autosaving from cov._atexit in case the interpreter lacks atexit.unregister
7172
try:
7273
atexit.unregister(cov._atexit)
73-
except Exception:
74+
except Exception: # noqa: S110
7475
pass
7576

7677

@@ -108,7 +109,7 @@ def _signal_cleanup_handler(signum, frame):
108109
elif signum == signal.SIGTERM:
109110
os._exit(128 + signum)
110111
elif signum == signal.SIGINT:
111-
raise KeyboardInterrupt()
112+
raise KeyboardInterrupt
112113

113114

114115
def cleanup_on_signal(signum):

0 commit comments

Comments
 (0)