Please sign in to comment.
Canonicalize enum pattern matching for execution strategy, platform, …
…and elsewhere (pantsbuild#7226) ### Problem In pantsbuild#7092 we added [`NailgunTask#do_for_execution_strategy_variant()`](https://github.com/cosmicexplorer/pants/blob/70977ef064305b78406a627e07f4dae3a60e4ae4/src/python/pants/backend/jvm/tasks/nailgun_task.py#L31-L43), which allowed performing more declarative execution strategy-specific logic in nailgunnable tasks. Further work with rsc will do even more funky things with our nailgunnable task logic, and while we will eventually have a unified story again for nailgun and subprocess invocations with the v2 engine (see pantsbuild#7079), for now having this check that we have performed the logic we expect all execution strategy variants is very useful. This PR puts that pattern matching logic into `enum()`: https://github.com/pantsbuild/pants/blob/84cf9a75dbf68cf7126fe8372ab9b2f48720464d/src/python/pants/util/objects.py#L173-L174, among other things. **Note:** `TypeCheckError` and other exceptions are moved up from further down in `objects.py`. ### Solution - add `resolve_for_enum_variant()` method to `enum` which does the job of the previous `do_for_execution_strategy_variant()` - make the native backend's `Platform` into an enum. - stop silently converting a `None` argument to the enum's `create()` classmethod into its`default_value`. - add `register_enum_option()` helper method to register options based on enum types. ### Result We have a low-overhead way to convert potentially-tricky conditional logic into a checked pattern matching-style interface with `enum()`, and it is easier to register enum options.
- Loading branch information...
Showing with 369 additions and 259 deletions.
- +4 −4 src/python/pants/backend/jvm/tasks/jvm_compile/rsc/rsc_compile.py
- +17 −22 src/python/pants/backend/jvm/tasks/nailgun_task.py
- +6 −29 src/python/pants/backend/native/config/environment.py
- +3 −3 src/python/pants/backend/native/subsystems/binaries/gcc.py
- +4 −7 src/python/pants/backend/native/subsystems/binaries/llvm.py
- +6 −11 src/python/pants/backend/native/subsystems/native_build_step.py
- +15 −5 src/python/pants/backend/native/subsystems/native_toolchain.py
- +3 −3 src/python/pants/backend/native/targets/native_artifact.py
- +3 −3 src/python/pants/backend/native/tasks/conan_fetch.py
- +4 −6 src/python/pants/backend/native/tasks/link_shared_libraries.py
- +3 −3 src/python/pants/backend/python/tasks/unpack_wheels.py
- +3 −2 src/python/pants/engine/fs.py
- +2 −1 src/python/pants/init/engine_initializer.py
- +7 −9 src/python/pants/option/global_options.py
- +154 −62 src/python/pants/util/objects.py
- +1 −0 tests/python/pants_test/backend/native/tasks/test_cpp_compile.py
- +53 −57 tests/python/pants_test/backend/python/tasks/native/test_ctypes_integration.py
- +81 −32 tests/python/pants_test/util/test_objects.py
Oops, something went wrong.