Commit 33546858 authored by xoviat's avatar xoviat

tests: add get_requires_for_build_wheel

parent bfe0ee27
......@@ -21,7 +21,13 @@ def _run_setup(setup_script='setup.py'): #
exec(compile(code, __file__, 'exec'))
def fix_config(config_settings):
config_settings = config_settings or {}
config_settings.setdefault('--global-option', [])
return config_settings
def get_build_requires(config_settings):
config_settings = fix_config(config_settings)
requirements = ['setuptools', 'wheel']
dist.skip_install_eggs = True
......@@ -38,10 +44,12 @@ def get_build_requires(config_settings):
def get_requires_for_build_wheel(config_settings=None):
config_settings = fix_config(config_settings)
return get_build_requires(config_settings)
def get_requires_for_build_sdist(config_settings=None):
config_settings = fix_config(config_settings)
return get_build_requires(config_settings)
......@@ -51,6 +59,7 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
def build_wheel(wheel_directory, config_settings=None,
metadata_directory=None):
config_settings = fix_config(config_settings)
wheel_directory = os.path.abspath(wheel_directory)
sys.argv = sys.argv[:1] + ['bdist_wheel'] + \
config_settings["--global-option"]
......@@ -61,6 +70,7 @@ def build_wheel(wheel_directory, config_settings=None,
def build_sdist(sdist_directory, config_settings=None):
config_settings = fix_config(config_settings)
sdist_directory = os.path.abspath(sdist_directory)
sys.argv = sys.argv[:1] + ['sdist'] + \
config_settings["--global-option"]
......
......@@ -6,7 +6,9 @@ import os
# a concurrent.futures backport for testing
pytest.importorskip('concurrent.futures')
from contextlib import contextmanager
from importlib import import_module
from tempfile import mkdtemp
from concurrent.futures import ProcessPoolExecutor
from .files import build_files
from .textwrap import DALS
......@@ -24,10 +26,10 @@ class BuildBackend(object):
def __getattr__(self, name):
"""Handles aribrary function invokations on the build backend."""
def method(**kw):
def method(*args, **kw):
return self.pool.submit(
BuildBackendCaller(self.cwd, self.env, self.backend_name),
(name, kw)).result()
(name, args, kw)).result()
return method
......@@ -38,21 +40,33 @@ class BuildBackendCaller(object):
self.env = env
self.backend_name = backend_name
def __getattr__(self, name):
def __call__(self, info):
"""Handles aribrary function invokations on the build backend."""
os.chdir(self.cwd)
os.environ.update(self.env)
return getattr(import_module(self.backend_name), name)
name, args, kw = info
return getattr(import_module(self.backend_name), name)(*args, **kw)
@contextmanager
def enter_directory(dir, val=None):
original_dir = os.getcwd()
os.chdir(dir)
yield val
os.chdir(original_dir)
@pytest.fixture
def build_backend():
tmpdir = mkdtemp()
with enter_directory(tmpdir):
setup_script = DALS("""
from setuptools import setup
setup(
name='foo',
py_modules=['hello'],
setup_requires=['test-package'],
entry_points={'console_scripts': ['hi = hello.run']},
zip_safe=False,
)
......@@ -66,4 +80,10 @@ def build_backend():
""")
})
return BuildBackend(cwd='.')
return enter_directory(tmpdir, BuildBackend(cwd='.'))
def test_get_requires_for_build_wheel(build_backend):
with build_backend as b:
assert list(sorted(b.get_requires_for_build_wheel())) == \
list(sorted(['test-package', 'setuptools', 'wheel']))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment