Skip to content

Commit fb912fd

Browse files
committed
feat: support pypa build
1 parent 9f610d0 commit fb912fd

16 files changed

+221
-55
lines changed

cibuildwheel/__main__.py

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

137137
build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '')
138+
pypa_build = os.environ.get('CIBW_PYPA_BUILD', '0')
138139
environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='')
139140
before_all = get_option_from_environment('CIBW_BEFORE_ALL', platform=platform, default='')
140141
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
@@ -235,6 +236,7 @@ def main() -> None:
235236
environment=environment,
236237
dependency_constraints=dependency_constraints,
237238
manylinux_images=manylinux_images,
239+
pypa_build=bool(pypa_build),
238240
)
239241

240242
# 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: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,12 @@ def build(options: BuildOptions) -> None:
156156

157157
env = options.environment.as_dictionary(env, executor=docker.environment_executor)
158158

159-
# check config python and pip are still on PATH
159+
# check config python is still on PATH
160160
which_python = docker.call(['which', 'python'], env=env, capture_output=True).strip()
161161
if PurePath(which_python) != python_bin / 'python':
162162
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)
163163
exit(1)
164164

165-
which_pip = docker.call(['which', 'pip'], env=env, capture_output=True).strip()
166-
if PurePath(which_pip) != python_bin / 'pip':
167-
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)
168-
exit(1)
169-
170165
if options.before_build:
171166
log.step('Running before_build...')
172167
before_build_prepared = prepare_command(options.before_build, project=container_project_path, package=container_package_dir)
@@ -179,13 +174,26 @@ def build(options: BuildOptions) -> None:
179174
docker.call(['rm', '-rf', built_wheel_dir])
180175
docker.call(['mkdir', '-p', built_wheel_dir])
181176

182-
docker.call([
183-
'pip', 'wheel',
184-
container_package_dir,
185-
'-w', built_wheel_dir,
186-
'--no-deps',
187-
*get_build_verbosity_extra_flags(options.build_verbosity)
188-
], env=env)
177+
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
178+
179+
if options.pypa_build:
180+
config_setting = " ".join(verbosity_flags)
181+
docker.call([
182+
'python', '-m', 'build',
183+
container_package_dir,
184+
'--wheel',
185+
'--outdir', built_wheel_dir,
186+
f'--config-setting="{config_setting}"',
187+
188+
], env=env)
189+
else:
190+
docker.call([
191+
'python', '-m', 'pip', 'wheel',
192+
container_package_dir,
193+
'-w', built_wheel_dir,
194+
'--no-deps',
195+
*verbosity_flags,
196+
], env=env)
189197

190198
built_wheel = docker.glob(built_wheel_dir, '*.whl')[0]
191199

cibuildwheel/macos.py

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

120120

121-
def setup_python(python_configuration: PythonConfiguration,
122-
dependency_constraint_flags: Sequence[PathOrStr],
123-
environment: ParsedEnvironment) -> Dict[str, str]:
121+
def setup_python(
122+
python_configuration: PythonConfiguration,
123+
dependency_constraint_flags: Sequence[PathOrStr],
124+
environment: ParsedEnvironment,
125+
pypa_build: bool,
126+
) -> Dict[str, str]:
127+
124128
implementation_id = python_configuration.identifier.split("-")[0]
125129
log.step(f'Installing Python {implementation_id}...')
126130

@@ -180,7 +184,10 @@ def setup_python(python_configuration: PythonConfiguration,
180184
env.setdefault('ARCHFLAGS', '-arch x86_64')
181185

182186
log.step('Installing build tools...')
183-
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
187+
if pypa_build:
188+
call(['pip', 'install', '--upgrade', 'delocate', 'build', *dependency_constraint_flags], env=env)
189+
else:
190+
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
184191

185192
return env
186193

@@ -210,7 +217,7 @@ def build(options: BuildOptions) -> None:
210217
'-c', options.dependency_constraints.get_for_python_version(config.version)
211218
]
212219

213-
env = setup_python(config, dependency_constraint_flags, options.environment)
220+
env = setup_python(config, dependency_constraint_flags, options.environment, options.pypa_build)
214221

215222
if options.before_build:
216223
log.step('Running before_build...')
@@ -222,15 +229,27 @@ def build(options: BuildOptions) -> None:
222229
shutil.rmtree(built_wheel_dir)
223230
built_wheel_dir.mkdir(parents=True)
224231

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

235254
built_wheel = next(built_wheel_dir.glob('*.whl'))
236255

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

cibuildwheel/resources/constraints.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
build
2+
delocate
13
pip
24
setuptools
3-
wheel
4-
delocate
55
virtualenv
6+
wheel

0 commit comments

Comments
 (0)