Skip to content

Commit

Permalink
Merge pull request #122 from graingert/enable-pytest-strict-mode
Browse files Browse the repository at this point in the history
avoid tomli Text file object support is deprecated and enable pytest strict mode
  • Loading branch information
takluyver committed Jul 31, 2021
2 parents 161b86a + 02568d8 commit 9359590
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-flake8
pytest-forward-compatibility; python_version<'3'
mock ; python_version<'3.6'
testpath
toml ; python_version<'3.6'
Expand Down
2 changes: 1 addition & 1 deletion pep517/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load_system(source_dir):
Load the build system from a source dir (pyproject.toml).
"""
pyproject = os.path.join(source_dir, 'pyproject.toml')
with io.open(pyproject, encoding="utf-8") as f:
with io.open(pyproject, 'rb') as f:
pyproject_data = toml_load(f)
return pyproject_data['build-system']

Expand Down
2 changes: 1 addition & 1 deletion pep517/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def check(source_dir):
return False

try:
with io.open(pyproject, encoding="utf-8") as f:
with io.open(pyproject, 'rb') as f:
pyproject_data = toml_load(f)
# Ensure the mandatory data can be loaded
buildsys = pyproject_data['build-system']
Expand Down
11 changes: 10 additions & 1 deletion pep517/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python 2/3 compatibility"""
import io
import json
import sys

Expand Down Expand Up @@ -35,7 +36,15 @@ def read_json(path):


if sys.version_info < (3, 6):
from toml import load as toml_load # noqa: F401
from toml import load as _toml_load # noqa: F401

def toml_load(f):
w = io.TextIOWrapper(f, encoding="utf8", newline="")
try:
return _toml_load(w)
finally:
w.detach()

from toml import TomlDecodeError as TOMLDecodeError # noqa: F401
else:
from tomli import load as toml_load # noqa: F401
Expand Down
2 changes: 1 addition & 1 deletion pep517/envbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def _load_pyproject(source_dir):
with io.open(
os.path.join(source_dir, 'pyproject.toml'),
encoding="utf-8",
'rb',
) as f:
pyproject_data = toml_load(f)
buildsys = pyproject_data['build-system']
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ home-page = "https://github.com/pypa/pep517"
description-file = "README.rst"
requires = [
"toml;python_version<'3.6'",
"tomli;python_version>='3.6'",
"tomli >=1.1.0;python_version>='3.6'",
"importlib_metadata;python_version<'3.8'",
"zipp;python_version<'3.8'",
]
Expand All @@ -19,4 +19,3 @@ classifiers = [
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
]

11 changes: 10 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[pytest]
addopts=--flake8
addopts =
--strict-config
--strict-markers
--flake8
xfail_strict = True
junit_family = xunit2
filterwarnings =
error
# Suppress deprecation warning in flake8
ignore:SelectableGroups dict interface is deprecated::flake8
2 changes: 1 addition & 1 deletion tests/test_call_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def get_hooks(pkg, **kwargs):
source_dir = pjoin(SAMPLES_DIR, pkg)
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
data = toml_load(f)
return Pep517HookCaller(
source_dir, data['build-system']['build-backend'], **kwargs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hook_fallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def get_hooks(pkg):
source_dir = pjoin(SAMPLES_DIR, pkg)
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
data = toml_load(f)
return Pep517HookCaller(source_dir, data['build-system']['build-backend'])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_inplace_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def get_hooks(pkg, backend=None, path=None):
source_dir = pjoin(SAMPLES_DIR, pkg)
with io.open(pjoin(source_dir, 'pyproject.toml'), encoding="utf-8") as f:
with io.open(pjoin(source_dir, 'pyproject.toml'), 'rb') as f:
data = toml_load(f)
if backend is None:
backend = data['build-system']['build-backend']
Expand Down
2 changes: 0 additions & 2 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)


@pep517_needs_python_3
def test_meta_for_this_package():
dist = meta.load('.')
assert re.match(r'[\d.]+', dist.version)
Expand All @@ -30,7 +29,6 @@ def test_classic_package(tmpdir):
assert dist.metadata['Name'] == 'foo'


@pep517_needs_python_3
def test_meta_output(capfd):
"""load shouldn't emit any output"""
meta.load('.')
Expand Down

0 comments on commit 9359590

Please sign in to comment.