Skip to content

Commit ad0bfff

Browse files
committed
feat: support pypa build
1 parent 635b226 commit ad0bfff

17 files changed

+229
-56
lines changed

cibuildwheel/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def main() -> None:
131131
repair_command_default = ''
132132

133133
build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '')
134+
pypa_build = os.environ.get('CIBW_PYPA_BUILD', '0')
134135
environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='')
135136
before_all = get_option_from_environment('CIBW_BEFORE_ALL', platform=platform, default='')
136137
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
@@ -231,6 +232,7 @@ def main() -> None:
231232
environment=environment,
232233
dependency_constraints=dependency_constraints,
233234
manylinux_images=manylinux_images,
235+
pypa_build=bool(pypa_build),
234236
)
235237

236238
# Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print'

cibuildwheel/linux.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,15 @@ def build(options: BuildOptions) -> None:
161161

162162
env = options.environment.as_dictionary(env, executor=docker.environment_executor)
163163

164-
# check config python and pip are still on PATH
164+
# check config python is still on PATH
165165
which_python = docker.call(['which', 'python'], env=env, capture_output=True).strip()
166166
if PurePath(which_python) != python_bin / 'python':
167167
print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr)
168168
exit(1)
169169

170-
which_pip = docker.call(['which', 'pip'], env=env, capture_output=True).strip()
171-
if PurePath(which_pip) != python_bin / 'pip':
172-
print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr)
173-
exit(1)
170+
# TODO: ideally should be preinstalled. Don't include a version so that it won't change if already installed
171+
if options.pypa_build:
172+
docker.call(['python', '-m', 'pip', 'install', 'build'], env=env)
174173

175174
if options.before_build:
176175
log.step('Running before_build...')
@@ -184,13 +183,26 @@ def build(options: BuildOptions) -> None:
184183
docker.call(['rm', '-rf', built_wheel_dir])
185184
docker.call(['mkdir', '-p', built_wheel_dir])
186185

187-
docker.call([
188-
'pip', 'wheel',
189-
container_package_dir,
190-
'-w', built_wheel_dir,
191-
'--no-deps',
192-
*get_build_verbosity_extra_flags(options.build_verbosity)
193-
], env=env)
186+
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
187+
188+
if options.pypa_build:
189+
config_setting = " ".join(verbosity_flags)
190+
docker.call([
191+
'python', '-m', 'build',
192+
container_package_dir,
193+
'--wheel',
194+
'--outdir', built_wheel_dir,
195+
f'--config-setting="{config_setting}"',
196+
197+
], env=env)
198+
else:
199+
docker.call([
200+
'python', '-m', 'pip', 'wheel',
201+
container_package_dir,
202+
'-w', built_wheel_dir,
203+
'--no-deps',
204+
*verbosity_flags,
205+
], env=env)
194206

195207
built_wheel = docker.glob(built_wheel_dir, '*.whl')[0]
196208

cibuildwheel/macos.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,13 @@ def install_pypy(version: str, url: str) -> Path:
126126
return installation_bin_path
127127

128128

129-
def setup_python(python_configuration: PythonConfiguration,
130-
dependency_constraint_flags: Sequence[PathOrStr],
131-
environment: ParsedEnvironment) -> Dict[str, str]:
129+
def setup_python(
130+
python_configuration: PythonConfiguration,
131+
dependency_constraint_flags: Sequence[PathOrStr],
132+
environment: ParsedEnvironment,
133+
pypa_build: bool,
134+
) -> Dict[str, str]:
135+
132136
implementation_id = python_configuration.identifier.split("-")[0]
133137
log.step(f'Installing Python {implementation_id}...')
134138

@@ -188,7 +192,10 @@ def setup_python(python_configuration: PythonConfiguration,
188192
env.setdefault('ARCHFLAGS', '-arch x86_64')
189193

190194
log.step('Installing build tools...')
191-
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
195+
if pypa_build:
196+
call(['pip', 'install', '--upgrade', 'delocate', 'build', *dependency_constraint_flags], env=env)
197+
else:
198+
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
192199

193200
return env
194201

@@ -218,7 +225,7 @@ def build(options: BuildOptions) -> None:
218225
'-c', options.dependency_constraints.get_for_python_version(config.version)
219226
]
220227

221-
env = setup_python(config, dependency_constraint_flags, options.environment)
228+
env = setup_python(config, dependency_constraint_flags, options.environment, options.pypa_build)
222229

223230
if options.before_build:
224231
log.step('Running before_build...')
@@ -230,15 +237,27 @@ def build(options: BuildOptions) -> None:
230237
shutil.rmtree(built_wheel_dir)
231238
built_wheel_dir.mkdir(parents=True)
232239

233-
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
234-
# see https://github.com/joerick/cibuildwheel/pull/369
235-
call([
236-
'pip', 'wheel',
237-
options.package_dir.resolve(),
238-
'-w', built_wheel_dir,
239-
'--no-deps',
240-
*get_build_verbosity_extra_flags(options.build_verbosity)
241-
], env=env)
240+
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
241+
242+
if options.pypa_build:
243+
config_setting = " ".join(verbosity_flags)
244+
call([
245+
'python', '-m', 'build',
246+
options.package_dir,
247+
'--wheel',
248+
'--outdir', built_wheel_dir,
249+
f'--config-setting="{config_setting}"',
250+
], env=env)
251+
else:
252+
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
253+
# see https://github.com/joerick/cibuildwheel/pull/369
254+
call([
255+
'pip', 'wheel',
256+
options.package_dir.resolve(),
257+
'-w', built_wheel_dir,
258+
'--no-deps',
259+
*get_build_verbosity_extra_flags(options.build_verbosity)
260+
], env=env)
242261

243262
built_wheel = next(built_wheel_dir.glob('*.whl'))
244263

cibuildwheel/resources/constraints-python27.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
configparser==4.0.2
1012
# via importlib-metadata
1113
contextlib2==0.6.0.post1
@@ -19,14 +21,23 @@ distlib==0.3.1
1921
filelock==3.0.12
2022
# via virtualenv
2123
importlib-metadata==2.1.1
22-
# via virtualenv
24+
# via
25+
# build
26+
# pep517
27+
# virtualenv
2328
importlib-resources==3.3.1
2429
# via virtualenv
30+
packaging==20.8
31+
# via build
2532
pathlib2==2.3.5
2633
# via
2734
# importlib-metadata
2835
# importlib-resources
2936
# virtualenv
37+
pep517==0.9.1
38+
# via build
39+
pyparsing==2.4.7
40+
# via packaging
3041
scandir==1.10.0
3142
# via pathlib2
3243
singledispatch==3.4.0.3
@@ -35,10 +46,18 @@ six==1.15.0
3546
# via
3647
# pathlib2
3748
# virtualenv
49+
toml==0.10.2
50+
# via
51+
# build
52+
# pep517
3853
typing==3.7.4.3
39-
# via importlib-resources
54+
# via
55+
# build
56+
# importlib-resources
4057
virtualenv==20.2.2
41-
# via -r cibuildwheel/resources/constraints.in
58+
# via
59+
# -r cibuildwheel/resources/constraints.in
60+
# build
4261
wheel==0.36.2
4362
# via
4463
# -r cibuildwheel/resources/constraints.in
@@ -47,6 +66,7 @@ zipp==1.2.0
4766
# via
4867
# importlib-metadata
4968
# importlib-resources
69+
# pep517
5070

5171
# The following packages are considered to be unsafe in a requirements file:
5272
pip==20.3.3

cibuildwheel/resources/constraints-python35.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,33 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
delocate==0.8.2
1012
# via -r cibuildwheel/resources/constraints.in
1113
distlib==0.3.1
1214
# via virtualenv
1315
filelock==3.0.12
1416
# via virtualenv
1517
importlib-metadata==2.1.1
16-
# via virtualenv
18+
# via
19+
# build
20+
# pep517
21+
# virtualenv
1722
importlib-resources==3.2.1
1823
# via virtualenv
24+
packaging==20.8
25+
# via build
26+
pep517==0.9.1
27+
# via build
28+
pyparsing==2.4.7
29+
# via packaging
1930
six==1.15.0
2031
# via virtualenv
32+
toml==0.10.2
33+
# via
34+
# build
35+
# pep517
2136
virtualenv==20.2.2
2237
# via -r cibuildwheel/resources/constraints.in
2338
wheel==0.36.2
@@ -28,6 +43,7 @@ zipp==1.2.0
2843
# via
2944
# importlib-metadata
3045
# importlib-resources
46+
# pep517
3147

3248
# The following packages are considered to be unsafe in a requirements file:
3349
pip==20.3.3

cibuildwheel/resources/constraints-python36.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,33 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
delocate==0.8.2
1012
# via -r cibuildwheel/resources/constraints.in
1113
distlib==0.3.1
1214
# via virtualenv
1315
filelock==3.0.12
1416
# via virtualenv
1517
importlib-metadata==3.3.0
16-
# via virtualenv
18+
# via
19+
# build
20+
# pep517
21+
# virtualenv
1722
importlib-resources==4.1.1
1823
# via virtualenv
24+
packaging==20.8
25+
# via build
26+
pep517==0.9.1
27+
# via build
28+
pyparsing==2.4.7
29+
# via packaging
1930
six==1.15.0
2031
# via virtualenv
32+
toml==0.10.2
33+
# via
34+
# build
35+
# pep517
2136
typing-extensions==3.7.4.3
2237
# via importlib-metadata
2338
virtualenv==20.2.2
@@ -30,6 +45,7 @@ zipp==3.4.0
3045
# via
3146
# importlib-metadata
3247
# importlib-resources
48+
# pep517
3349

3450
# The following packages are considered to be unsafe in a requirements file:
3551
pip==20.3.3

cibuildwheel/resources/constraints-python37.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
delocate==0.8.2
1012
# via -r cibuildwheel/resources/constraints.in
1113
distlib==0.3.1
1214
# via virtualenv
1315
filelock==3.0.12
1416
# via virtualenv
1517
importlib-metadata==3.3.0
16-
# via virtualenv
18+
# via
19+
# build
20+
# pep517
21+
# virtualenv
22+
packaging==20.8
23+
# via build
24+
pep517==0.9.1
25+
# via build
26+
pyparsing==2.4.7
27+
# via packaging
1728
six==1.15.0
1829
# via virtualenv
30+
toml==0.10.2
31+
# via
32+
# build
33+
# pep517
1934
typing-extensions==3.7.4.3
2035
# via importlib-metadata
2136
virtualenv==20.2.2
@@ -25,7 +40,9 @@ wheel==0.36.2
2540
# -r cibuildwheel/resources/constraints.in
2641
# delocate
2742
zipp==3.4.0
28-
# via importlib-metadata
43+
# via
44+
# importlib-metadata
45+
# pep517
2946

3047
# The following packages are considered to be unsafe in a requirements file:
3148
pip==20.3.3

cibuildwheel/resources/constraints-python38.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
delocate==0.8.2
1012
# via -r cibuildwheel/resources/constraints.in
1113
distlib==0.3.1
1214
# via virtualenv
1315
filelock==3.0.12
1416
# via virtualenv
17+
packaging==20.8
18+
# via build
19+
pep517==0.9.1
20+
# via build
21+
pyparsing==2.4.7
22+
# via packaging
1523
six==1.15.0
1624
# via virtualenv
25+
toml==0.10.2
26+
# via
27+
# build
28+
# pep517
1729
virtualenv==20.2.2
1830
# via -r cibuildwheel/resources/constraints.in
1931
wheel==0.36.2

cibuildwheel/resources/constraints-python39.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@
66
#
77
appdirs==1.4.4
88
# via virtualenv
9+
build==0.1.0
10+
# via -r cibuildwheel/resources/constraints.in
911
delocate==0.8.2
1012
# via -r cibuildwheel/resources/constraints.in
1113
distlib==0.3.1
1214
# via virtualenv
1315
filelock==3.0.12
1416
# via virtualenv
17+
packaging==20.8
18+
# via build
19+
pep517==0.9.1
20+
# via build
21+
pyparsing==2.4.7
22+
# via packaging
1523
six==1.15.0
1624
# via virtualenv
25+
toml==0.10.2
26+
# via
27+
# build
28+
# pep517
1729
virtualenv==20.2.2
1830
# via -r cibuildwheel/resources/constraints.in
1931
wheel==0.36.2

0 commit comments

Comments
 (0)