Skip to content

Commit

Permalink
Apply black and ruff to code, and fix some ruff lint issues. Also close
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Mar 17, 2024
1 parent c98ada9 commit ff3fdd8
Show file tree
Hide file tree
Showing 14 changed files with 955 additions and 1,078 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
args: [--fix, --exit-non-zero-on-fix, --show-fixes, --unsafe-fixes]
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
virtualenv>=16.6.0
pip>=19.1.1
setuptools>=18.0.1
six>=1.14.0
tox
twine
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'sphinx.ext.extlinks',
]
if os.getenv('SPELLCHECK'):
extensions += 'sphinxcontrib.spelling',
extensions += ('sphinxcontrib.spelling',)
spelling_show_suggestions = True
spelling_lang = 'en_US'

Expand Down
4 changes: 3 additions & 1 deletion examples/adhoc-layout/example/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

# test merging multiple tox runs with a platform
# based branch
if platform.python_implementation() == "PyPy":
if platform.python_implementation() == 'PyPy':

def add(a, b):
return a + b

else:

def add(a, b):
return a + b
2 changes: 1 addition & 1 deletion examples/adhoc-layout/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

setup(
name='example',
packages=find_packages(include=['example'])
packages=find_packages(include=['example']),
)
4 changes: 3 additions & 1 deletion examples/src-layout/src/example/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

# test merging multiple tox runs with a platform
# based branch
if platform.python_implementation() == "PyPy":
if platform.python_implementation() == 'PyPy':

def add(a, b):
return a + b

else:

def add(a, b):
return a + b
43 changes: 20 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/env python

import re
from pathlib import Path
from glob import glob
from itertools import chain
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import splitext
from pathlib import Path

from setuptools import Command
from setuptools import find_packages
Expand All @@ -32,24 +27,24 @@ def read(*names, **kwargs):
class BuildWithPTH(build):
def run(self, *args, **kwargs):
super().run(*args, **kwargs)
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
dest = join(self.build_lib, basename(path))
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
dest = str(Path(self.build_lib) / Path(path).name)
self.copy_file(path, dest)


class EasyInstallWithPTH(easy_install):
def run(self, *args, **kwargs):
super().run(*args, **kwargs)
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
dest = join(self.install_dir, basename(path))
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
dest = str(Path(self.install_dir) / Path(path).name)
self.copy_file(path, dest)


class InstallLibWithPTH(install_lib):
def run(self, *args, **kwargs):
super().run(*args, **kwargs)
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
dest = join(self.install_dir, basename(path))
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
dest = str(Path(self.install_dir) / Path(path).name)
self.copy_file(path, dest)
self.outputs = [dest]

Expand All @@ -60,13 +55,13 @@ def get_outputs(self):
class DevelopWithPTH(develop):
def run(self, *args, **kwargs):
super().run(*args, **kwargs)
path = join(dirname(__file__), 'src', 'pytest-cov.pth')
dest = join(self.install_dir, basename(path))
path = str(Path(__file__).parent / 'src' / 'pytest-cov.pth')
dest = str(Path(self.install_dir) / Path(path).name)
self.copy_file(path, dest)


class GeneratePTH(Command):
user_options = []
user_options = ()

def initialize_options(self):
pass
Expand All @@ -75,11 +70,9 @@ def finalize_options(self):
pass

def run(self):
with open(join(dirname(__file__), 'src', 'pytest-cov.pth'), 'w') as fh:
with open(join(dirname(__file__), 'src', 'pytest-cov.embed')) as sh:
fh.write(
f"import os, sys;exec({sh.read().replace(' ', ' ')!r})"
)
with Path(__file__).parent.joinpath('src', 'pytest-cov.pth').open('w') as fh:
with Path(__file__).parent.joinpath('src', 'pytest-cov.embed').open() as sh:
fh.write(f"import os, sys;exec({sh.read().replace(' ', ' ')!r})")


setup(
Expand Down Expand Up @@ -124,19 +117,23 @@ def run(self):
'Issue Tracker': 'https://github.com/pytest-dev/pytest-cov/issues',
},
keywords=[
'cover', 'coverage', 'pytest', 'py.test', 'distributed', 'parallel',
'cover',
'coverage',
'pytest',
'py.test',
'distributed',
'parallel',
],
python_requires='>=3.8',
install_requires=[
'pytest>=4.6',
'coverage[toml]>=5.2.1'
'coverage[toml]>=5.2.1',
],
extras_require={
'testing': [
'fields',
'hunter',
'process-tests',
'six',
'pytest-xdist',
'virtualenv',
]
Expand Down
1 change: 1 addition & 0 deletions src/pytest_cov/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""pytest-cov: avoid already-imported warning: PYTEST_DONT_REWRITE."""

__version__ = '4.1.0'
9 changes: 0 additions & 9 deletions src/pytest_cov/compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
try:
from StringIO import StringIO
except ImportError:
from io import StringIO


StringIO # pyflakes, this is for re-export


class SessionWrapper:
def __init__(self, session):
self._session = session
Expand Down
7 changes: 4 additions & 3 deletions src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
that code coverage is being collected we activate coverage based on
info passed via env vars.
"""

import atexit
import os
import signal
Expand Down Expand Up @@ -52,7 +53,7 @@ def init():
data_suffix=True,
config_file=cov_config,
auto_data=True,
data_file=cov_datafile
data_file=cov_datafile,
)
cov.load()
cov.start()
Expand All @@ -70,7 +71,7 @@ def _cleanup(cov):
cov._auto_save = False # prevent autosaving from cov._atexit in case the interpreter lacks atexit.unregister
try:
atexit.unregister(cov._atexit)
except Exception:
except Exception: # noqa: S110
pass


Expand Down Expand Up @@ -108,7 +109,7 @@ def _signal_cleanup_handler(signum, frame):
elif signum == signal.SIGTERM:
os._exit(128 + signum)
elif signum == signal.SIGINT:
raise KeyboardInterrupt()
raise KeyboardInterrupt


def cleanup_on_signal(signum):
Expand Down
Loading

0 comments on commit ff3fdd8

Please sign in to comment.