From 2790fd1dd7d37491c42001ae8f644a526612d466 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 31 May 2020 21:42:21 +0200 Subject: [PATCH] Put CIBW_TEST_COMMAND as first test option everywhere --- README.md | 4 ++-- cibuildwheel/__main__.py | 37 ++++++++++++++++--------------- cibuildwheel/util.py | 4 ++-- docs/options.md | 48 ++++++++++++++++++++-------------------- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 78e6a2f8..93c896ce 100644 --- a/README.md +++ b/README.md @@ -105,10 +105,10 @@ Options | | [`CIBW_BEFORE_BUILD`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-build) | Execute a shell command preparing each wheel's build | | | [`CIBW_REPAIR_WHEEL_COMMAND`](https://cibuildwheel.readthedocs.io/en/stable/options/#repair-wheel-command) | Execute a shell command to repair each (non-pure Python) built wheel | | | [`CIBW_MANYLINUX_X86_64_IMAGE`](https://cibuildwheel.readthedocs.io/en/stable/options/#manylinux-image) [`CIBW_MANYLINUX_I686_IMAGE`](https://cibuildwheel.readthedocs.io/en/stable/options/#manylinux-image) [`CIBW_MANYLINUX_PYPY_X86_64_IMAGE`](https://cibuildwheel.readthedocs.io/en/stable/options/#manylinux-image) | Specify alternative manylinux docker images | -| **Testing** | [`CIBW_BEFORE_TEST`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-test) | Execute shell command to prepare test environment | +| **Testing** | [`CIBW_TEST_COMMAND`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-command) | Execute a shell command to test each built wheel | +| | [`CIBW_BEFORE_TEST`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-test) | Execute shell command to prepare test environment | | | [`CIBW_TEST_REQUIRES`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-requires) | Install Python dependencies before running the tests | | | [`CIBW_TEST_EXTRAS`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-extras) | Install your wheel for testing using extras_require | -| | [`CIBW_TEST_COMMAND`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-command) | Execute a shell command to test each built wheel | | **Other** | [`CIBW_BUILD_VERBOSITY`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-verbosity) | Increase/decrease the output of pip wheel | Working examples diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index cb3b5349..53ac3870 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -114,15 +114,21 @@ def main() -> None: file=sys.stderr) exit(2) - output_dir = args.output_dir - 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='') - before_test = get_option_from_environment('CIBW_BEFORE_TEST', platform=platform, default='') - test_command = get_option_from_environment('CIBW_TEST_COMMAND', platform=platform) 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='') + output_dir = args.output_dir + build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '') + build_selector = BuildSelector(build_config, skip_config) + + environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='') + 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) + + before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform) if platform == 'linux': repair_command_default = 'auditwheel repair -w {dest_dir} {wheel}' elif platform == 'macos': @@ -130,7 +136,6 @@ def main() -> None: 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='') dependency_versions = get_option_from_environment('CIBW_DEPENDENCY_VERSIONS', platform=platform, default='pinned') if dependency_versions == 'pinned': @@ -140,23 +145,19 @@ def main() -> None: else: dependency_constraints = DependencyConstraints(dependency_versions) + 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='') if test_extras: test_extras = f'[{test_extras}]' + build_verbosity_str = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='') try: build_verbosity = min(3, max(-3, int(build_verbosity_str))) 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' @@ -206,12 +207,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 0742fc3f..499954b9 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -116,10 +116,10 @@ class BuildOptions(NamedTuple): repair_command: str manylinux_images: Optional[Dict[str, str]] dependency_constraints: Optional[DependencyConstraints] - before_test: str + test_command: Optional[str] + before_test: Optional[str] test_requires: List[str] test_extras: str - test_command: Optional[str] build_verbosity: int diff --git a/docs/options.md b/docs/options.md index 2e8dd324..18d5417b 100644 --- a/docs/options.md +++ b/docs/options.md @@ -348,6 +348,30 @@ CIBW_DEPENDENCY_VERSIONS: ./constraints.txt ## Testing +### `CIBW_TEST_COMMAND` {: #test-command} +> Execute a shell command to test each built wheel + +Shell command to run tests after the build. The wheel will be installed automatically and available for import from the tests. To ensure the wheel is imported by your tests (instead of your source copy), tests are run from a different directory. Use the placeholders `{project}` and `{package}` when specifying paths in your project. + +- `{project}` is an absolute path to the project root - the working directory where cibuildwheel was called. +- `{package}` is the path to the package being built - the `package_dir` argument supplied to cibuildwheel on the command line. + +The command is run in a shell, so you can write things like `cmd1 && cmd2`. + +Platform-specific variants also available:
+`CIBW_TEST_COMMAND_MACOS` | `CIBW_TEST_COMMAND_WINDOWS` | `CIBW_TEST_COMMAND_LINUX` + +#### Examples + +```yaml +# run the project tests against the installed wheel using `nose` +CIBW_TEST_COMMAND: nosetests {project}/tests + +# run the package tests using `pytest` +CIBW_TEST_COMMAND: pytest {package}/tests +``` + + ### `CIBW_BEFORE_TEST` {: #before-test} > Execute a shell command before testing each wheel @@ -417,30 +441,6 @@ CIBW_TEST_EXTRAS: test,qt ``` -### `CIBW_TEST_COMMAND` {: #test-command} -> Execute a shell command to test each built wheel - -Shell command to run tests after the build. The wheel will be installed automatically and available for import from the tests. To ensure the wheel is imported by your tests (instead of your source copy), tests are run from a different directory. Use the placeholders `{project}` and `{package}` when specifying paths in your project. - -- `{project}` is an absolute path to the project root - the working directory where cibuildwheel was called. -- `{package}` is the path to the package being built - the `package_dir` argument supplied to cibuildwheel on the command line. - -The command is run in a shell, so you can write things like `cmd1 && cmd2`. - -Platform-specific variants also available:
-`CIBW_TEST_COMMAND_MACOS` | `CIBW_TEST_COMMAND_WINDOWS` | `CIBW_TEST_COMMAND_LINUX` - -#### Examples - -```yaml -# run the project tests against the installed wheel using `nose` -CIBW_TEST_COMMAND: nosetests {project}/tests - -# run the package tests using `pytest` -CIBW_TEST_COMMAND: pytest {package}/tests -``` - - ## Other ### `CIBW_BUILD_VERBOSITY` {: #build-verbosity}