Commit a52acadb authored by Xavier Thompson's avatar Xavier Thompson

[feat] Enable build of pyproject.toml projects

Enable zc.buildout.easy_install.build, which builds a project manually
from an unpacked sdist archive and is used by zc.recipe.egg:custom, to
build a project which only has a pyproject.toml but no setup.py.
parent 25141b9b
...@@ -945,28 +945,31 @@ class Installer(object): ...@@ -945,28 +945,31 @@ class Installer(object):
try: try:
setuptools.archive_util.unpack_archive(dist.location, setuptools.archive_util.unpack_archive(dist.location,
build_tmp) build_tmp)
if os.path.exists(os.path.join(build_tmp, 'setup.py')):
# Find pyproject.toml or setup.py
for filename in ('pyproject.toml', 'setup.py'):
if os.path.exists(os.path.join(build_tmp, filename)):
base = build_tmp base = build_tmp
break
else: else:
for filename in ('pyproject.toml', 'setup.py'):
setups = glob.glob( setups = glob.glob(
os.path.join(build_tmp, '*', 'setup.py')) os.path.join(build_tmp, '*', filename))
if not setups: if setups:
raise distutils.errors.DistutilsError(
"Couldn't find a setup script in %s"
% os.path.basename(dist.location)
)
if len(setups) > 1: if len(setups) > 1:
raise distutils.errors.DistutilsError( raise distutils.errors.DistutilsError(
"Multiple setup scripts in %s" "Multiple %s in %s" % (
filename, os.path.basename(dist.location)))
base = os.path.dirname(setups[0])
break
else:
raise distutils.errors.DistutilsError(
"Couldn't find a pyproject.toml nor setup.py in %s"
% os.path.basename(dist.location) % os.path.basename(dist.location)
) )
base = os.path.dirname(setups[0])
setup_cfg_dict = {'build_ext':build_ext} # Apply patches.
if patch_dict: if patch_dict:
setup_cfg_dict.update(
{'egg_info':{'tag_build':'+%s%03d' % (PATCH_MARKER,
patch_dict['patch_revision'])}})
download = zc.buildout.download.Download( download = zc.buildout.download.Download(
cache=tmp, hash_name=True) cache=tmp, hash_name=True)
patch_dict = patch_dict[requirement.key] patch_dict = patch_dict[requirement.key]
...@@ -981,12 +984,44 @@ class Installer(object): ...@@ -981,12 +984,44 @@ class Installer(object):
if popen.returncode: if popen.returncode:
raise subprocess.CalledProcessError( raise subprocess.CalledProcessError(
popen.returncode, ' '.join(args)) popen.returncode, ' '.join(args))
# Attempt to determine whether setuptools is used.
def uses_setuptools():
if filename == 'setup.py':
return True
for setup in ('setup.py', 'setup.cfg'):
if os.path.exists(os.path.join(base, setup)):
return True
with open(os.path.join(base, 'pyproject.toml')) as f:
config = f.read()
pattern = "^build-backend\s*=\s*['\"]+setuptools"
if re.search(pattern, config, re.MULTILINE):
return True
return False
# Edit setup.cfg if required; warn if setuptools is not used.
if uses_setuptools():
setup_cfg_dict = {'build_ext': build_ext}
if patch_dict:
# TODO: find alternative for without setuptools.
setup_cfg_dict.update(
{'egg_info':{'tag_build':'+%s%03d' % (
PATCH_MARKER,
patch_dict['patch_revision'])}})
setup_cfg = os.path.join(base, 'setup.cfg') setup_cfg = os.path.join(base, 'setup.cfg')
if not os.path.exists(setup_cfg): if not os.path.exists(setup_cfg):
f = open(setup_cfg, 'w') with open(setup_cfg, 'w'):
f.close() pass
setuptools.command.setopt.edit_config( setuptools.command.setopt.edit_config(
setup_cfg, setup_cfg_dict) setup_cfg, setup_cfg_dict)
else:
if build_ext or patch_dict:
logger.warning(
"Build options call for editing setup.cfg "
"but project %s does not use setuptools. "
"Proceeding without."
% dist
)
dists = self._call_pip_wheel(base, self._dest, dist) dists = self._call_pip_wheel(base, self._dest, dist)
......
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