Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building via PyPA/build #17

Merged
merged 4 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Authors
* Antonio Botelho - https://github.com/botant
* Thomas Grainger - https://github.com/graingert
* Michael Rans - https://github.com/mcarans
* Ben Rowland - https://github.com/bennyrowland
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Unreleased changes
------------------

* Added option to build wheels (and sdists) in an isolated environment using `build <https://github.com/pypa/build>`_.
Contributed by Ben Rowland in `#17 <https://github.com/ionelmc/tox-wheel/pull/17>`_.

0.7.0 (2021-12-29)
------------------

Expand Down
41 changes: 36 additions & 5 deletions src/tox_wheel/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from contextlib import contextmanager
from functools import partial
import os.path

import pluggy
import py
Expand Down Expand Up @@ -32,9 +33,12 @@ def tox_addoption(parser):
)
parser.add_testenv_attribute(
name="wheel_pep517",
type="bool",
default=False,
help="Build wheel using PEP 517/518"
type="string",
default="",
help=(
"Build wheel using PEP 517/518 (pass true to build with pip or "
"build to build with build)"
),
)
parser.add_testenv_attribute(
name="wheel_dirty",
Expand All @@ -60,6 +64,13 @@ def patch(obj, attr, value):
setattr(obj, attr, original)


@hookimpl
def tox_testenv_install_deps(venv, action):
if venv.envconfig.wheel_pep517 == "build":
venv.run_install_command(["build[virtualenv]>=0.7.0"], action)
return None


@hookimpl
def tox_package(session, venv):
if session.config.option.wheel or venv.envconfig.wheel:
Expand Down Expand Up @@ -153,16 +164,36 @@ def wheel_build_pep517(config, session, venv):
action.setactivity("wheel-make", "cleaning up build directory ...")
ensure_empty_dir(config.setupdir.join("build"))
ensure_empty_dir(config.distdir)
if venv.envconfig.wheel_pep517 == "build":
commands = [
"python",
"-Im",
"build",
"--outdir",
config.distdir,
config.setupdir,
]
else:
commands = [
"pip",
"wheel",
config.setupdir,
"--no-deps",
"--use-pep517",
"--wheel-dir",
config.distdir,
]
venv.test(
name="wheel-make",
commands=[["pip", "wheel", config.setupdir, "--no-deps", "--use-pep517", "--wheel-dir", config.distdir]],
commands=[commands],
redirect=False,
ignore_outcome=False,
ignore_errors=False,
display_hash_seed=False,
)
try:
dists = config.distdir.listdir()
# we need to filter our list of dists to include only wheels
dists = [dist for dist in config.distdir.listdir() if os.path.splitext(dist)[1] == ".whl"]
except py.error.ENOENT:
reporter.error(
"No dist directory found. Please check pyproject.toml, e.g with:\n"
Expand Down
55 changes: 55 additions & 0 deletions tests/test_tox_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ def testdir_pep517(testdir):
return testdir


@pytest.fixture
def testdir_pep517_build(testdir):
testdir.tmpdir.join('tox.ini').write("""
[tox]
envlist = py-{a,b}

[testenv]
wheel = true
wheel_pep517 = build
""")
testdir.tmpdir.join('setup.py').write("""
from setuptools import setup

setup(name='foobar', packages=[])
""")
testdir.tmpdir.join('pyproject.toml').write("""
[build-system]
requires = [
"setuptools >= 35.0.2"
]
build-backend = "setuptools.build_meta"
""")
testdir.tmpdir.join('build').ensure(dir=1)
return testdir


@pytest.fixture(params=['', '--parallel 1 --parallel-live'], ids=['sequential', 'parallel'])
def options(request):
return ['-e', 'py-a,py-b'] + request.param.split()
Expand Down Expand Up @@ -99,6 +125,16 @@ def test_enabled_pep517(testdir_pep517, options):
assert result.ret == 0


def test_enabled_pep517_build(testdir_pep517_build, options):
result = testdir_pep517_build.run('tox', *options)
result.stdout.fnmatch_lines([
'py* wheel-make: *',
])
build_string = 'Successfully built foobar-0.0.0.tar.gz and foobar-0.0.0-py3-none-any.whl'
assert result.stdout.str().count(build_string) == 2
assert result.ret == 0


def test_build_env_legacy(testdir_legacy, options):
testdir_legacy.tmpdir.join('setup.cfg').write("""
[bdist_wheel]
Expand Down Expand Up @@ -141,6 +177,25 @@ def test_build_env_pep517(testdir_pep517, options):
assert result.ret == 0


def test_build_env_pep517_build(testdir_pep517_build, options):
testdir_pep517_build.tmpdir.join('setup.cfg').write("""
[bdist_wheel]
universal = 1
""")
testdir_pep517_build.tmpdir.join('tox.ini').write("""
wheel_build_env = build

[testenv:build]
""", mode='a')
result = testdir_pep517_build.run('tox', *options)
result.stdout.fnmatch_lines([
'build wheel-make: *',
])
build_string = 'Successfully built foobar-0.0.0.tar.gz and foobar-0.0.0-py2.py3-none-any.whl'
assert result.stdout.str().count(build_string) == 1
assert result.ret == 0


@pytest.mark.parametrize('wheel_build_env', ['', 'wheel_build_env'])
def test_skip_usedevelop(testdir_legacy, options, wheel_build_env):
testdir_legacy.tmpdir.join('tox.ini').write("""
Expand Down