コード例 #1
0
def test_is_python2(constraints, compatibilities):
    Subsystem.reset()
    init_subsystem(
        PythonSetup,
        {
            PythonSetup.options_scope: {
                "interpreter_constraints":
                RankedValue(RankedValue.CONFIG, constraints)
            }
        },
    )
    assert is_python2(compatibilities, PythonSetup.global_instance())
コード例 #2
0
async def run_setup_pys(targets: HydratedTargets, options: SetupPyOptions,
                        console: Console, provenance_map: AddressProvenanceMap,
                        python_setup: PythonSetup, distdir: DistDir,
                        workspace: Workspace) -> SetupPy:
    """Run setup.py commands on all exported targets addressed."""
    args = tuple(options.values.args)
    validate_args(args)

    # Get all exported targets, ignoring any non-exported targets that happened to be
    # globbed over, but erroring on any explicitly-requested non-exported targets.

    exported_targets: List[ExportedTarget] = []
    explicit_nonexported_targets: List[HydratedTarget] = []

    for hydrated_target in targets:
        if _is_exported(hydrated_target):
            exported_targets.append(ExportedTarget(hydrated_target))
        elif provenance_map.is_single_address(hydrated_target.address):
            explicit_nonexported_targets.append(hydrated_target)
    if explicit_nonexported_targets:
        raise TargetNotExported(
            'Cannot run setup.py on these targets, because they have no `provides=` clause: '
            f'{", ".join(so.address.reference() for so in explicit_nonexported_targets)}'
        )

    if options.values.transitive:
        # Expand out to all owners of the entire dep closure.
        tht = await Get[TransitiveHydratedTargets](BuildFileAddresses(
            [et.hydrated_target.address for et in exported_targets]))
        owners = await MultiGet(Get[ExportedTarget](OwnedDependency(ht))
                                for ht in tht.closure if is_ownable_target(ht))
        exported_targets = list(set(owners))

    py2 = is_python2((getattr(target.adaptor, 'compatibility', None)
                      for target in targets), python_setup)
    chroots = await MultiGet(
        Get[SetupPyChroot](SetupPyChrootRequest(target, py2))
        for target in exported_targets)

    # If args were provided, run setup.py with them; Otherwise just dump chroots.
    if args:
        setup_py_results = await MultiGet(
            Get[RunSetupPyResult](RunSetupPyRequest(exported_target, chroot,
                                                    tuple(args)))
            for exported_target, chroot in zip(exported_targets, chroots))

        for exported_target, setup_py_result in zip(exported_targets,
                                                    setup_py_results):
            addr = exported_target.hydrated_target.address.reference()
            console.print_stderr(
                f'Writing dist for {addr} under {distdir.relpath}/.')
            workspace.materialize_directory(
                DirectoryToMaterialize(setup_py_result.output,
                                       path_prefix=str(distdir.relpath)))
    else:
        # Just dump the chroot.
        for exported_target, chroot in zip(exported_targets, chroots):
            addr = exported_target.hydrated_target.address.reference()
            provides = exported_target.hydrated_target.adaptor.provides
            setup_py_dir = distdir.relpath / f'{provides.name}-{provides.version}'
            console.print_stderr(
                f'Writing setup.py chroot for {addr} to {setup_py_dir}')
            workspace.materialize_directory(
                DirectoryToMaterialize(chroot.digest,
                                       path_prefix=str(setup_py_dir)))

    return SetupPy(0)