예제 #1
0
async def get_sources(
    request: SetupPySourcesRequest, source_root_config: SourceRootConfig
) -> SetupPySources:
    targets = request.targets
    stripped_srcs_list = await MultiGet(
        Get[SourceRootStrippedSources](
            StripSourcesFieldRequest(
                target.get(Sources),
                for_sources_types=(PythonSources, ResourcesSources),
                enable_codegen=True,
            )
        )
        for target in targets
    )

    # Create a chroot with all the sources, and any ancestor __init__.py files that might be needed
    # for imports to work.  Note that if a repo has multiple exported targets under a single ancestor
    # package, then that package must be a namespace package, which in Python 3 means it must not
    # have an __init__.py. We don't validate this here, because it would require inspecting *all*
    # targets, whether or not they are in the target set for this run - basically the entire repo.
    # So it's the repo owners' responsibility to ensure __init__.py hygiene.
    stripped_srcs_digests = [
        stripped_sources.snapshot.digest for stripped_sources in stripped_srcs_list
    ]
    ancestor_init_pys = await Get[AncestorInitPyFiles](Targets, targets)
    sources_digest = await Get[Digest](
        MergeDigests((*stripped_srcs_digests, *ancestor_init_pys.digests))
    )
    init_pys_snapshot = await Get[Snapshot](
        SnapshotSubset(sources_digest, PathGlobs(["**/__init__.py"]))
    )
    init_py_contents = await Get[FilesContent](Digest, init_pys_snapshot.digest)

    packages, namespace_packages, package_data = find_packages(
        source_roots=source_root_config.get_source_roots(),
        tgts_and_stripped_srcs=list(zip(targets, stripped_srcs_list)),
        init_py_contents=init_py_contents,
        py2=request.py2,
    )
    return SetupPySources(
        digest=sources_digest,
        packages=packages,
        namespace_packages=namespace_packages,
        package_data=package_data,
    )
예제 #2
0
async def get_sources(request: SetupPySourcesRequest) -> SetupPySources:
    python_sources = await Get(
        StrippedPythonSourceFiles,
        PythonSourceFilesRequest(targets=request.targets,
                                 include_resources=False,
                                 include_files=False),
    )
    all_sources = await Get(
        StrippedPythonSourceFiles,
        PythonSourceFilesRequest(targets=request.targets,
                                 include_resources=True,
                                 include_files=True),
    )

    python_files = set(python_sources.stripped_source_files.snapshot.files)
    all_files = set(all_sources.stripped_source_files.snapshot.files)
    resource_files = all_files - python_files

    init_py_digest_contents = await Get(
        DigestContents,
        DigestSubset(python_sources.stripped_source_files.snapshot.digest,
                     PathGlobs(["**/__init__.py"])),
    )

    packages, namespace_packages, package_data = find_packages(
        python_files=python_files,
        resource_files=resource_files,
        init_py_digest_contents=init_py_digest_contents,
        py2=request.py2,
    )
    return SetupPySources(
        digest=all_sources.stripped_source_files.snapshot.digest,
        packages=packages,
        namespace_packages=namespace_packages,
        package_data=package_data,
    )