//python/private:py_info.bzl
Implementation of PyInfo provider and PyInfo-specific utilities.
- providerPyInfo
Encapsulates information provided by the Python rules.
Instead of creating this object directly, use
PyInfoBuilderandthePyCommonApiutilities.- PyInfo.<init>(direct_original_sources,direct_pyc_files,direct_pyi_files,has_py2_only_sources,has_py3_only_sources,imports,transitive_implicit_pyc_files,transitive_implicit_pyc_source_files,transitive_original_sources,transitive_pyc_files,transitive_pyi_files,transitive_sources,uses_shared_libraries,venv_symlinks)
- PyInfo.direct_original_sources:depset[File]
The
.pysource files (if any) that are considered directly provided bythe target. This field is intended so that static analysis tools can recover theoriginal Python source files, regardless of any build settings (e.g.precompiling), so they can analyze source code. The values are typically the.pyfiles in thesrcsattribute (or equivalent).Added in version 1.1.0.
- PyInfo.direct_pyc_files:depset[File]
Precompiled Python files that are considered directly providedby the target andmust be included.
These files usually come from, e.g., a library setting
precompile=enabledto forcibly enable precompiling for itself. Downstream binaries are expectedto always include these files, as the originating target expects them to exist.
- PyInfo.direct_pyi_files:depset[File]
Type definition files (usually
.pyifiles) for the Python modules provided bythis target. Usually they describe the source files listed indirect_original_sources. This field is primarily for static analysis tools.These files areusually build-time only and not included as part of a runnableprogram.
Note
This may contain implementation-specific file types specific to a particulartype checker.
Added in version 1.1.0.
- PyInfo.has_py2_only_sources:bool
Whether any of this target’s transitive sources requires a Python 2 runtime.
- PyInfo.has_py3_only_sources:bool
Whether any of this target’s transitive sources requires a Python 3 runtime.
- PyInfo.imports:depset[str]
A depset of import path strings to be added to the
PYTHONPATHof executablePython targets. These are accumulated from the transitivedeps.The order of the depset is not guaranteed and may be changed in the future. Itis recommended to usedefaultorder (the default).
- PyInfo.transitive_implicit_pyc_files:depset[File]
Automatically generated pyc files that downstream binaries (or equivalent)can choose to include in their output. If not included, then
transitive_implicit_pyc_source_filesshould be included instead.Added in version 0.37.0.
- PyInfo.transitive_implicit_pyc_source_files:depset[File]
Source
.pyfiles fortransitive_implicit_pyc_filesthat downstreambinaries (or equivalent) can choose to include in their output. If not included,thentransitive_implicit_pyc_filesshould be included instead.Added in version 0.37.0.
- PyInfo.transitive_original_sources:depset[File]
The transitive set of
.pysource files (if any) that are considered theoriginal sources for this target and its transitive dependencies. This field isintended so that static analysis tools can recover the original Python sourcefiles, regardless of any build settings (e.g. precompiling), so they can analyzesource code. The values are typically the.pyfiles in thesrcsattribute(or equivalent).This is superset of
direct_original_sources.Added in version 1.1.0.
- PyInfo.transitive_pyc_files:depset[File]
The transitive set of precompiled files that must be included.
These files usually come from, e.g., a library setting
precompile=enabledto forcibly enable precompiling for itself. Downstream binaries are expectedto always include these files, as the originating target expects them to exist.
- PyInfo.transitive_pyi_files:depset[File]
The transitive set of type definition files (usually
.pyifiles) for thePython modules for this target and its transitive dependencies. this target.Usually they describe the source files listed intransitive_original_sources.This field is primarily for static analysis tools.These files areusually build-time only and not included as part of a runnableprogram.
Note
This may contain implementation-specific file types specific to a particulartype checker.
Added in version 1.1.0.
- PyInfo.transitive_sources:depset[File]
A (
postorder-compatible) depset of.pyfiles that are considered requiredand downstream binaries (or equivalent)must include in their outputsto have a functioning program.Normally, these are the
.pyfiles in the appearing in the target’ssrcsandthesrcsof the target’s transitivedeps,however, precompile settingsmay cause.pyfiles to be omitted. In particular, pyc-only builds may resultin this depset beingempty.Changed in version 0.37.0:The files are considered necessary for downstream binaries to function;previously they were considerd informational and largely unused.
- PyInfo.uses_shared_libraries:bool
Whether any of this target’s transitive
depshas a shared library file (suchas a.sofile).This field is currently unused in Bazel and may go away in the future.
- PyInfo.venv_symlinks:depset[VenvSymlinkEntry]
Warning
Experimental API. This API is still under development and may change or beremoved without notice.
Added in version 1.5.0.
- typedefPyInfoBuilder
Builder for PyInfo.
To create an instance, use
py_common.get()and callPyInfoBuilder()- PyInfoBuilder.build_builtin_py_info()
Builds into a Bazel-builtin PyInfo object, if available.
- Returns:
BuiltinPyInfo|NoneNone is returned if Bazel’sbuiltin PyInfo object is disabled.
- PyInfoBuilder.merge(direct=[],*infos)
Merge other PyInfos into this PyInfo.
- PyInfoBuilder.merge_all(transitive,direct=[])
Merge other PyInfos into this PyInfo.
- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.merge_has_py2_only_sources(value)
Sets
has_py2_only_sourcesbased on current and incomingvalue.- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.merge_has_py3_only_sources(value)
Sets
has_py3_only_sourcesbased on current and incomingvalue.- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.merge_target(target)
Merge a target’s Python information in this object.
- Args:
- Returns:
PyInfoBuilderself.
- PyInfoBuilder.merge_targets(targets)
Merge multiple targets into this object.
- Args:
- Returns:
PyInfoBuilderself.
- PyInfoBuilder.merge_uses_shared_libraries(value)
Sets
uses_shared_librariesbased on current and incomingvalue.- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.new()
Creates an instance.
- Returns:
- PyInfoBuilder.set_has_py2_only_sources(value)
Sets
has_py2_only_sourcestovalue.- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.set_has_py3_only_sources(value)
Sets
has_py3_only_sourcestovalue.- Args:
- Returns:
PyInfoBuilderself
- PyInfoBuilder.set_uses_shared_libraries(value)
Sets
uses_shared_librariestovalue.- Args:
- Returns:
PyInfoBuilderself
- providerVenvSymlinkEntry
An entry in
PyInfo.venv_symlinks- VenvSymlinkEntry.<init>(files,kind,link_to_file,link_to_path,package,venv_path,version)
- VenvSymlinkEntry.files:depset[File]
Files under
link_to_path.This is only used when multiple targets have overlapping
venv_pathpaths. e.g.if one adds files tovenv_path=a/and another adds files tovenv_path=a/b/.
- VenvSymlinkEntry.kind:str
One of the
VenvSymlinkKindvalues. It represents which directory withinthe venv to create the path under.
- VenvSymlinkEntry.link_to_file:File|None
A file that
venv_pathshould point to. The file to link to should also be infiles.Added in version 1.7.0.
- VenvSymlinkEntry.link_to_path:str|None
A runfiles-root relative path that
venv_pathwill symlink to (iflink_to_fileisNone). IfNone, it means to not create it in the venv.
- typedefVenvSymlinkKind
An enum of types of venv directories.
- VenvSymlinkKind.BIN:object
Indicates to create paths under the directory that has binarieswithin the venv.
- VenvSymlinkKind.LIB:object
Indicates to create paths under the venv’s site-packages directory.
- VenvSymlinkKind.INCLUDE:object
Indicates to create paths under the venv’s include directory.