2023-05-20 00:37:27 +00:00
|
|
|
import argparse
|
2022-04-29 10:42:37 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
2023-05-20 00:37:27 +00:00
|
|
|
def parse_config_settings_args(config_settings):
|
|
|
|
"""
|
|
|
|
Given a list of config `KEY=VALUE` formatted config settings,
|
|
|
|
return a dictionary that can be passed to PEP 517 hook functions.
|
|
|
|
"""
|
|
|
|
if not config_settings:
|
|
|
|
return config_settings
|
|
|
|
new_config_settings = {}
|
|
|
|
for arg in config_settings:
|
|
|
|
key, _, value = arg.partition('=')
|
|
|
|
new_config_settings[key] = value
|
|
|
|
return new_config_settings
|
|
|
|
|
|
|
|
|
|
|
|
def get_config_settings_args(config_settings):
|
|
|
|
"""
|
|
|
|
Given a dictionary of PEP 517 backend config_settings,
|
|
|
|
yield --config-settings args that can be passed to pip's CLI
|
|
|
|
"""
|
|
|
|
if not config_settings:
|
|
|
|
return
|
|
|
|
for key, value in config_settings.items():
|
|
|
|
if value == '':
|
|
|
|
yield f'--config-settings={key}'
|
|
|
|
else:
|
|
|
|
yield f'--config-settings={key}={value}'
|
|
|
|
|
|
|
|
|
|
|
|
def build_wheel(*, wheeldir, stdout=None, config_settings=None):
|
2022-04-29 10:42:37 +00:00
|
|
|
command = (
|
|
|
|
sys.executable,
|
|
|
|
'-m', 'pip',
|
|
|
|
'wheel',
|
|
|
|
'--wheel-dir', wheeldir,
|
|
|
|
'--no-deps',
|
|
|
|
'--use-pep517',
|
|
|
|
'--no-build-isolation',
|
|
|
|
'--disable-pip-version-check',
|
|
|
|
'--no-clean',
|
|
|
|
'--progress-bar', 'off',
|
|
|
|
'--verbose',
|
2023-05-20 00:37:27 +00:00
|
|
|
*get_config_settings_args(config_settings),
|
2022-04-29 10:42:37 +00:00
|
|
|
'.',
|
|
|
|
)
|
|
|
|
cp = subprocess.run(command, stdout=stdout)
|
|
|
|
return cp.returncode
|
|
|
|
|
|
|
|
|
2023-05-20 00:37:27 +00:00
|
|
|
def parse_args(argv=None):
|
|
|
|
parser = argparse.ArgumentParser(prog='%pyproject_wheel')
|
|
|
|
parser.add_argument('wheeldir', help=argparse.SUPPRESS)
|
|
|
|
parser.add_argument(
|
|
|
|
'-C',
|
|
|
|
dest='config_settings',
|
|
|
|
action='append',
|
|
|
|
help='Configuration settings to pass to the PEP 517 backend',
|
|
|
|
)
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
args.config_settings = parse_config_settings_args(args.config_settings)
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
2022-04-29 10:42:37 +00:00
|
|
|
if __name__ == '__main__':
|
2023-05-20 00:37:27 +00:00
|
|
|
sys.exit(build_wheel(**vars(parse_args())))
|