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

Fix pip wheel #345

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ cache:
- $HOME/.cache/pip
- $HOME/.cache/pre-commit

install: pip install tox
install: pip install tox tox-venv
script:
- python testing/runtests_travis.py
12 changes: 7 additions & 5 deletions src/setuptools_scm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ def _popen_pipes(cmd, cwd):


def do_ex(cmd, cwd="."):
trace("cmd", repr(cmd))
trace("cmd:", cmd)
if os.name == "posix" and not isinstance(cmd, (list, tuple)):
cmd = shlex.split(cmd)

p = _popen_pipes(cmd, cwd)
out, err = p.communicate()
out = ensure_stripped_str(out)
err = ensure_stripped_str(err)
if out:
trace("out", repr(out))
trace("out:", " ".join(out.splitlines(True)))
if err:
trace("err", repr(err))
trace("err:", " ".join(err.splitlines(True)))
if p.returncode:
trace("ret", p.returncode)
return ensure_stripped_str(out), ensure_stripped_str(err), p.returncode
trace("ret:", p.returncode)
return out, err, p.returncode


def do(cmd, cwd="."):
Expand Down
8 changes: 2 additions & 6 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ def version(self):


@pytest.yield_fixture(autouse=True)
def debug_mode():
from setuptools_scm import utils

utils.DEBUG = True
yield
utils.DEBUG = False
def debug_mode(monkeypatch):
monkeypatch.setattr("setuptools_scm.utils.DEBUG", True)


@pytest.fixture
Expand Down
139 changes: 139 additions & 0 deletions testing/test_pip_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

import pytest
import attr
from setuptools_scm.utils import do
import zipfile
import os

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

pytestmark = pytest.mark.skipif(
"sys.version_info[0] < 3", reason="the pip integration tests require python3"
)

FILE = "example_package.py", "import sys;print sys.version\n"
SETUP_PY_CLASSICAL = "setup.py", """\
from setuptools import setup

setup(
name="example",
setup_requires=["setuptools_scm"],
use_scm_version=True)
"""

SETUP_CFG = "setup.cfg", """\
[metadata]
name = example
[options]
setup_requires=setuptools_scm
"""


SETUP_PY_MINIMAL = "setup.py", """\
from setuptools import setup
setup(use_scm_version=True)
"""

PYPROJECT_SETUPTOOLS = "pyproject.toml", """\
[build-system]
requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]

"""
PYPROJECT_SETUPTOOLS_SCM = "pyproject.toml", """\
[build-system]
requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]

"""

PYPROJECT_FLIT = "pyproject.toml", ""


@attr.s
class PipVenv(object):
path = attr.ib()

@classmethod
def create(cls, path):

venv = pytest.importorskip("venv")
builder = venv.EnvBuilder(with_pip=True)
builder.create(str(path))

self = cls(path)
self.do("bin/pip install wheel -e {setuptools_scm}".format(setuptools_scm=ROOT))
self.do("bin/pip install -U pip")
return self

def do(self, cmd):
return do(cmd, str(self.path))


@pytest.fixture
def pip_venv(tmp_path):
return PipVenv.create(tmp_path / "pip_venv")


@pytest.fixture
def wd(wd):
wd("git init")
wd("git config user.email [email protected]")
wd('git config user.name "a test"')
wd.add_command = "git add ."
wd.commit_command = "git commit -m test-{reason}"
return wd


def with_filespecs(**kw):
params = []
for id, wanted_files in kw.items():
actual_files = [x for x in wanted_files if isinstance(x, tuple)]
marks = [x for x in wanted_files if not isinstance(x, tuple)]
params.append(pytest.param(actual_files, id=id, marks=marks))

return pytest.mark.parametrize("wanted_files", params)


def setup_package(wanted_files, wd):
for name, content in wanted_files:
wd.write(name, content)
wd.add_and_commit("basic-file-setup-done")
wd("git tag v0.1")


spec = with_filespecs(
classical=[FILE, SETUP_PY_CLASSICAL],
static_config=[FILE, SETUP_PY_MINIMAL, SETUP_CFG],
basic_pep717=[FILE, SETUP_PY_MINIMAL, SETUP_CFG, PYPROJECT_SETUPTOOLS],
integrated_pep517=[
FILE,
SETUP_CFG,
PYPROJECT_SETUPTOOLS_SCM,
pytest.mark.xfail(reason="integration not yet implemented"),
],
)


@spec
def test_package_installs(wanted_files, wd, pip_venv): # NOQA
setup_package(wanted_files, wd)
pip_venv.do("./bin/pip install --no-build-isolation {wd.cwd}".format(wd=wd))
metadata = pip_venv.do("./bin/pip show example")
assert "Version: 0.1\n" in metadata


@spec
def test_package_builds_wheel(wanted_files, wd, pip_venv, tmp_path): # NOQA
setup_package(wanted_files, wd)

wheel_dir = tmp_path.joinpath("wheels")
wheel_dir.mkdir()
pip_venv.do(
"bin/pip wheel {wd.cwd} --no-build-isolation --wheel-dir {wheel_dir}".format(
wd=wd, wheel_dir=wheel_dir
)
)
wheel = next(wheel_dir.glob("*.whl"))
print(wheel)
with zipfile.ZipFile(wheel, "r") as zfp:
metadata = zfp.read("example-0.1.dist-info/METADATA")
assert b"Version: 0.1\n" in metadata