diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 95bc96b9..40241ac1 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -114,25 +114,36 @@ def main() -> None: file=sys.stderr) exit(2) - output_dir = args.output_dir - test_command = get_option_from_environment('CIBW_TEST_COMMAND', platform=platform) - test_requires = get_option_from_environment('CIBW_TEST_REQUIRES', platform=platform, default='').split() - test_extras = get_option_from_environment('CIBW_TEST_EXTRAS', platform=platform, default='') package_dir = args.package_dir - before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform) - build_verbosity_str = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='') - build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '') + output_dir = args.output_dir + if platform == 'linux': repair_command_default = 'auditwheel repair -w {dest_dir} {wheel}' elif platform == 'macos': repair_command_default = 'delocate-listdeps {wheel} && delocate-wheel --require-archs x86_64 -w {dest_dir} {wheel}' else: repair_command_default = '' - repair_command = get_option_from_environment('CIBW_REPAIR_WHEEL_COMMAND', platform=platform, default=repair_command_default) - environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='') - before_test = get_option_from_environment('CIBW_BEFORE_TEST', platform=platform, default='') + build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '') + environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='') + before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform) + repair_command = get_option_from_environment('CIBW_REPAIR_WHEEL_COMMAND', platform=platform, default=repair_command_default) dependency_versions = get_option_from_environment('CIBW_DEPENDENCY_VERSIONS', platform=platform, default='pinned') + test_command = get_option_from_environment('CIBW_TEST_COMMAND', platform=platform) + before_test = get_option_from_environment('CIBW_BEFORE_TEST', platform=platform) + test_requires = get_option_from_environment('CIBW_TEST_REQUIRES', platform=platform, default='').split() + test_extras = get_option_from_environment('CIBW_TEST_EXTRAS', platform=platform, default='') + build_verbosity_str = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='') + + build_selector = BuildSelector(build_config, skip_config) + + try: + environment = parse_environment(environment_config) + except (EnvironmentParseError, ValueError): + print(f'cibuildwheel: Malformed environment option "{environment_config}"', file=sys.stderr) + traceback.print_exc(None, sys.stderr) + exit(2) + if dependency_versions == 'pinned': dependency_constraints: Optional[DependencyConstraints] = DependencyConstraints.with_defaults() elif dependency_versions == 'latest': @@ -148,15 +159,6 @@ def main() -> None: except ValueError: build_verbosity = 0 - try: - environment = parse_environment(environment_config) - except (EnvironmentParseError, ValueError): - print(f'cibuildwheel: Malformed environment option "{environment_config}"', file=sys.stderr) - traceback.print_exc(None, sys.stderr) - exit(2) - - build_selector = BuildSelector(build_config, skip_config) - # Add CIBUILDWHEEL environment variable # This needs to be passed on to the docker container in linux.py os.environ['CIBUILDWHEEL'] = '1' @@ -207,12 +209,12 @@ def main() -> None: test_command=test_command, test_requires=test_requires, test_extras=test_extras, + before_test=before_test, before_build=before_build, build_verbosity=build_verbosity, build_selector=build_selector, repair_command=repair_command, environment=environment, - before_test=before_test, dependency_constraints=dependency_constraints, manylinux_images=manylinux_images, ) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 80042039..499954b9 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -110,17 +110,17 @@ class DependencyConstraints: class BuildOptions(NamedTuple): package_dir: str output_dir: str + build_selector: BuildSelector + environment: ParsedEnvironment + before_build: Optional[str] + repair_command: str + manylinux_images: Optional[Dict[str, str]] + dependency_constraints: Optional[DependencyConstraints] test_command: Optional[str] + before_test: Optional[str] test_requires: List[str] test_extras: str - before_build: Optional[str] build_verbosity: int - build_selector: BuildSelector - repair_command: str - environment: ParsedEnvironment - before_test: str - dependency_constraints: Optional[DependencyConstraints] - manylinux_images: Optional[Dict[str, str]] resources_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'resources')) diff --git a/docs/options.md b/docs/options.md index 8ecaaf23..18d5417b 100644 --- a/docs/options.md +++ b/docs/options.md @@ -52,7 +52,6 @@ env: ## Build selection - ### `CIBW_PLATFORM` {: #platform} > Override the auto-detected target platform @@ -67,6 +66,7 @@ For `linux` you need Docker running, on macOS or Linux. For `macos`, you need a This option can also be set using the command-line option `--platform`. + ### `CIBW_BUILD`, `CIBW_SKIP` {: #build-skip} > Choose the Python versions to build @@ -155,7 +155,6 @@ CIBW_SKIP: pp* ## Build customization - ### `CIBW_ENVIRONMENT` {: #environment} > Set environment variables needed during the build @@ -296,6 +295,7 @@ CIBW_MANYLINUX_X86_64_IMAGE: dockcross/manylinux-x64 CIBW_MANYLINUX_I686_IMAGE: dockcross/manylinux-x86 ``` + ### `CIBW_DEPENDENCY_VERSIONS` {: #dependency-versions} > Specify how cibuildwheel controls the versions of the tools it uses @@ -372,6 +372,35 @@ CIBW_TEST_COMMAND: pytest {package}/tests ``` +### `CIBW_BEFORE_TEST` {: #before-test} +> Execute a shell command before testing each wheel + +A shell command to run in **each** test virtual environment, before your wheel is installed and tested. This is useful if you need to install a non pip package, change values of environment variables +or perform multi step pip installation (e.g. installing `scikit-build` or `cython` before install test package) + +The active Python binary can be accessed using `python`, and pip with `pip`; `cibuildwheel` makes sure the right version of Python and pip will be executed. The placeholder `{package}` can be used here; it will be replaced by the path to the package being built by `cibuildwheel`. + +The command is run in a shell, so you can write things like `cmd1 && cmd2`. + +Platform-specific variants also available:
+ `CIBW_BEFORE_TEST_MACOS` | `CIBW_BEFORE_TEST_WINDOWS` | `CIBW_BEFORE_TEST_LINUX` + +#### Examples +```yaml +# install test dependencies with overwritten environment variables. +CIBW_BEFORE_TEST: CC=gcc CXX=g++ pip install -r requirements.txt + +# chain commands using && +CIBW_BEFORE_TEST: rm -rf ./data/cache && mkdir -p ./data/cache + +# install non pip python package +CIBW_BEFORE_TEST: cd some_dir; ./configure; make; make install + +# install python packages that are required to install test dependencies +CIBW_BEFORE_TEST: pip install cmake scikit-build +``` + + ### `CIBW_TEST_REQUIRES` {: #test-requires} > Install Python dependencies before running the tests @@ -411,33 +440,6 @@ Platform-specific variants also available:
CIBW_TEST_EXTRAS: test,qt ``` -### `CIBW_BEFORE_TEST` {: #before-test} -> Execute a shell command before testing each wheel - -A shell command to run in **each** test virtual environment, before your wheel is installed and tested. This is useful if you need to install a non pip package, change values of environment variables -or perform multi step pip installation (e.g. installing `scikit-build` or `cython` before install test package) - -The active Python binary can be accessed using `python`, and pip with `pip`; `cibuildwheel` makes sure the right version of Python and pip will be executed. The placeholder `{package}` can be used here; it will be replaced by the path to the package being built by `cibuildwheel`. - -The command is run in a shell, so you can write things like `cmd1 && cmd2`. - -Platform-specific variants also available:
- `CIBW_BEFORE_TEST_MACOS` | `CIBW_BEFORE_TEST_WINDOWS` | `CIBW_BEFORE_TEST_LINUX` - -#### Examples -```yaml -# install test dependencies with overwritten environment variables. -CIBW_BEFORE_TEST: CC=gcc CXX=g++ pip install -r requirements.txt - -# chain commands using && -CIBW_BEFORE_TEST: rm -rf ./data/cache && mkdir -p ./data/cache - -# install non pip python package -CIBW_BEFORE_TEST: cd some_dir; ./configure; make; make install - -# install python packages that are required to install test dependencies -CIBW_BEFORE_TEST: pip install cmake scikit-build -``` ## Other