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'): # ...@@ -21,7 +21,13 @@ def _run_setup(setup_script='setup.py'): #
exec(compile(code, __file__, 'exec')) 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): def get_build_requires(config_settings):
config_settings = fix_config(config_settings)
requirements = ['setuptools', 'wheel'] requirements = ['setuptools', 'wheel']
dist.skip_install_eggs = True dist.skip_install_eggs = True
...@@ -38,10 +44,12 @@ def get_build_requires(config_settings): ...@@ -38,10 +44,12 @@ def get_build_requires(config_settings):
def get_requires_for_build_wheel(config_settings=None): def get_requires_for_build_wheel(config_settings=None):
config_settings = fix_config(config_settings)
return get_build_requires(config_settings) return get_build_requires(config_settings)
def get_requires_for_build_sdist(config_settings=None): def get_requires_for_build_sdist(config_settings=None):
config_settings = fix_config(config_settings)
return get_build_requires(config_settings) return get_build_requires(config_settings)
...@@ -51,6 +59,7 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None): ...@@ -51,6 +59,7 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
def build_wheel(wheel_directory, config_settings=None, def build_wheel(wheel_directory, config_settings=None,
metadata_directory=None): metadata_directory=None):
config_settings = fix_config(config_settings)
wheel_directory = os.path.abspath(wheel_directory) wheel_directory = os.path.abspath(wheel_directory)
sys.argv = sys.argv[:1] + ['bdist_wheel'] + \ sys.argv = sys.argv[:1] + ['bdist_wheel'] + \
config_settings["--global-option"] config_settings["--global-option"]
...@@ -61,6 +70,7 @@ def build_wheel(wheel_directory, config_settings=None, ...@@ -61,6 +70,7 @@ def build_wheel(wheel_directory, config_settings=None,
def build_sdist(sdist_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) sdist_directory = os.path.abspath(sdist_directory)
sys.argv = sys.argv[:1] + ['sdist'] + \ sys.argv = sys.argv[:1] + ['sdist'] + \
config_settings["--global-option"] config_settings["--global-option"]
......
...@@ -6,7 +6,9 @@ import os ...@@ -6,7 +6,9 @@ import os
# a concurrent.futures backport for testing # a concurrent.futures backport for testing
pytest.importorskip('concurrent.futures') pytest.importorskip('concurrent.futures')
from contextlib import contextmanager
from importlib import import_module from importlib import import_module
from tempfile import mkdtemp
from concurrent.futures import ProcessPoolExecutor from concurrent.futures import ProcessPoolExecutor
from .files import build_files from .files import build_files
from .textwrap import DALS from .textwrap import DALS
...@@ -24,10 +26,10 @@ class BuildBackend(object): ...@@ -24,10 +26,10 @@ class BuildBackend(object):
def __getattr__(self, name): def __getattr__(self, name):
"""Handles aribrary function invokations on the build backend.""" """Handles aribrary function invokations on the build backend."""
def method(**kw): def method(*args, **kw):
return self.pool.submit( return self.pool.submit(
BuildBackendCaller(self.cwd, self.env, self.backend_name), BuildBackendCaller(self.cwd, self.env, self.backend_name),
(name, kw)).result() (name, args, kw)).result()
return method return method
...@@ -38,21 +40,33 @@ class BuildBackendCaller(object): ...@@ -38,21 +40,33 @@ class BuildBackendCaller(object):
self.env = env self.env = env
self.backend_name = backend_name self.backend_name = backend_name
def __getattr__(self, name): def __call__(self, info):
"""Handles aribrary function invokations on the build backend.""" """Handles aribrary function invokations on the build backend."""
os.chdir(self.cwd) os.chdir(self.cwd)
os.environ.update(self.env) 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 @pytest.fixture
def build_backend(): def build_backend():
tmpdir = mkdtemp()
with enter_directory(tmpdir):
setup_script = DALS(""" setup_script = DALS("""
from setuptools import setup from setuptools import setup
setup( setup(
name='foo', name='foo',
py_modules=['hello'], py_modules=['hello'],
setup_requires=['test-package'],
entry_points={'console_scripts': ['hi = hello.run']}, entry_points={'console_scripts': ['hi = hello.run']},
zip_safe=False, zip_safe=False,
) )
...@@ -66,4 +80,10 @@ def build_backend(): ...@@ -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