Commit 823780e4 authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #1175 from xoviat/build_meta

Build meta: fixes and cleanups
parents 5b6c8d3f ca5a8186
...@@ -65,10 +65,11 @@ def _run_setup(setup_script='setup.py'): ...@@ -65,10 +65,11 @@ def _run_setup(setup_script='setup.py'):
# Note that we can reuse our build directory between calls # Note that we can reuse our build directory between calls
# Correctness comes first, then optimization later # Correctness comes first, then optimization later
__file__ = setup_script __file__ = setup_script
__name__ = '__main__'
f = getattr(tokenize, 'open', open)(__file__) f = getattr(tokenize, 'open', open)(__file__)
code = f.read().replace('\\r\\n', '\\n') code = f.read().replace('\\r\\n', '\\n')
f.close() f.close()
exec(compile(code, __file__, 'exec')) exec(compile(code, __file__, 'exec'), locals())
def _fix_config(config_settings): def _fix_config(config_settings):
...@@ -92,6 +93,11 @@ def _get_build_requires(config_settings): ...@@ -92,6 +93,11 @@ def _get_build_requires(config_settings):
return requirements return requirements
def _get_immediate_subdirectories(a_dir):
return [name for name in os.listdir(a_dir)
if os.path.isdir(os.path.join(a_dir, name))]
def get_requires_for_build_wheel(config_settings=None): def get_requires_for_build_wheel(config_settings=None):
config_settings = _fix_config(config_settings) config_settings = _fix_config(config_settings)
return _get_build_requires(config_settings) return _get_build_requires(config_settings)
...@@ -106,10 +112,28 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None): ...@@ -106,10 +112,28 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', metadata_directory] sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', metadata_directory]
_run_setup() _run_setup()
dist_infos = [f for f in os.listdir(metadata_directory) dist_info_directory = metadata_directory
while True:
dist_infos = [f for f in os.listdir(dist_info_directory)
if f.endswith('.dist-info')] if f.endswith('.dist-info')]
if len(dist_infos) == 0 and \
len(_get_immediate_subdirectories(dist_info_directory)) == 1:
dist_info_directory = os.path.join(
dist_info_directory, os.listdir(dist_info_directory)[0])
continue
assert len(dist_infos) == 1 assert len(dist_infos) == 1
break
# PEP 517 requires that the .dist-info directory be placed in the
# metadata_directory. To comply, we MUST copy the directory to the root
if dist_info_directory != metadata_directory:
shutil.move(
os.path.join(dist_info_directory, dist_infos[0]),
metadata_directory)
shutil.rmtree(dist_info_directory, ignore_errors=True)
return dist_infos[0] return dist_infos[0]
......
...@@ -4,7 +4,6 @@ As defined in the wheel specification ...@@ -4,7 +4,6 @@ As defined in the wheel specification
""" """
import os import os
import shutil
from distutils.core import Command from distutils.core import Command
from distutils import log from distutils import log
...@@ -27,14 +26,11 @@ class dist_info(Command): ...@@ -27,14 +26,11 @@ class dist_info(Command):
def run(self): def run(self):
egg_info = self.get_finalized_command('egg_info') egg_info = self.get_finalized_command('egg_info')
egg_info.egg_base = self.egg_base
egg_info.finalize_options()
egg_info.run() egg_info.run()
dist_info_dir = egg_info.egg_info[:-len('.egg-info')] + '.dist-info' dist_info_dir = egg_info.egg_info[:-len('.egg-info')] + '.dist-info'
log.info("creating '{}'".format(os.path.abspath(dist_info_dir))) log.info("creating '{}'".format(os.path.abspath(dist_info_dir)))
bdist_wheel = self.get_finalized_command('bdist_wheel') bdist_wheel = self.get_finalized_command('bdist_wheel')
bdist_wheel.egg2dist(egg_info.egg_info, dist_info_dir) bdist_wheel.egg2dist(egg_info.egg_info, dist_info_dir)
if self.egg_base:
destination = os.path.join(self.egg_base, dist_info_dir)
log.info("creating '{}'".format(os.path.abspath(destination)))
shutil.move(dist_info_dir, destination)
...@@ -42,9 +42,7 @@ class BuildBackendCaller(BuildBackendBase): ...@@ -42,9 +42,7 @@ class BuildBackendCaller(BuildBackendBase):
return getattr(mod, name)(*args, **kw) return getattr(mod, name)(*args, **kw)
@pytest.fixture defns = [{
def build_backend(tmpdir):
defn = {
'setup.py': DALS(""" 'setup.py': DALS("""
__import__('setuptools').setup( __import__('setuptools').setup(
name='foo', name='foo',
...@@ -56,8 +54,43 @@ def build_backend(tmpdir): ...@@ -56,8 +54,43 @@ def build_backend(tmpdir):
def run(): def run():
print('hello') print('hello')
"""), """),
} },
build_files(defn, prefix=str(tmpdir)) {
'setup.py': DALS("""
assert __name__ == '__main__'
__import__('setuptools').setup(
name='foo',
py_modules=['hello'],
setup_requires=['six'],
)
"""),
'hello.py': DALS("""
def run():
print('hello')
"""),
},
{
'setup.py': DALS("""
variable = True
def function():
return variable
assert variable
__import__('setuptools').setup(
name='foo',
py_modules=['hello'],
setup_requires=['six'],
)
"""),
'hello.py': DALS("""
def run():
print('hello')
"""),
}]
@pytest.fixture(params=defns)
def build_backend(tmpdir, request):
build_files(request.param, prefix=str(tmpdir))
with tmpdir.as_cwd(): with tmpdir.as_cwd():
yield BuildBackend(cwd='.') yield BuildBackend(cwd='.')
......
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