| 370 | |
| 371 | @attr.s(frozen=True) |
| 372 | class Targets(object): |
| 373 | @classmethod |
| 374 | def from_target(cls, target): |
| 375 | # type: (Target) -> Targets |
| 376 | if isinstance(target, AbbreviatedPlatform): |
| 377 | return cls(platforms=(target.platform,)) |
| 378 | elif isinstance(target, CompletePlatform): |
| 379 | return cls(complete_platforms=(target,)) |
| 380 | else: |
| 381 | return cls(interpreters=(target.get_interpreter(),)) |
| 382 | |
| 383 | interpreters = attr.ib(default=()) # type: Tuple[PythonInterpreter, ...] |
| 384 | interpreter_selection_strategy = attr.ib( |
| 385 | default=InterpreterSelectionStrategy.OLDEST |
| 386 | ) # type: InterpreterSelectionStrategy.Value |
| 387 | complete_platforms = attr.ib(default=()) # type: Tuple[CompletePlatform, ...] |
| 388 | platforms = attr.ib(default=()) # type: Tuple[Optional[Platform], ...] |
| 389 | |
| 390 | @property |
| 391 | def is_empty(self): |
| 392 | # type: () -> bool |
| 393 | return not self.interpreters and not self.complete_platforms and not self.platforms |
| 394 | |
| 395 | @property |
| 396 | def interpreter(self): |
| 397 | # type: () -> Optional[PythonInterpreter] |
| 398 | if not self.interpreters: |
| 399 | return None |
| 400 | return self.interpreter_selection_strategy.select(self.interpreters) |
| 401 | |
| 402 | def unique_targets(self, only_explicit=False): |
| 403 | # type: (bool) -> OrderedSet[Target] |
| 404 | |
| 405 | def iter_targets(): |
| 406 | # type: () -> Iterator[Target] |
| 407 | if ( |
| 408 | not only_explicit |
| 409 | and not self.interpreters |
| 410 | and not self.platforms |
| 411 | and not self.complete_platforms |
| 412 | ): |
| 413 | # No specified targets, so just build for the current interpreter (on the current |
| 414 | # platform). |
| 415 | yield current() |
| 416 | return |
| 417 | |
| 418 | for interpreter in self.interpreters: |
| 419 | # Build for the specified local interpreters (on the current platform). |
| 420 | yield LocalInterpreter.create(interpreter) |
| 421 | |
| 422 | for platform in self.platforms: |
| 423 | if platform is None and not self.interpreters: |
| 424 | # Build for the current platform (None) only if not done already (ie: no |
| 425 | # interpreters were specified). |
| 426 | yield current() |
| 427 | elif platform is not None: |
| 428 | # Build for specific platforms. |
| 429 | yield AbbreviatedPlatform.create(platform) |
no outgoing calls