//python/private:py_info.bzl
Implementation of PyInfo provider and PyInfo-specific utilities.
- provider PyInfo
Encapsulates information provided by the Python rules.
Instead of creating this object directly, use
PyInfoBuilderand thePyCommonApiutilities.- 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 by the target. This field is intended so that static analysis tools can recover the original 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 provided by the target and must be included.
These files usually come from, e.g., a library setting
precompile=enabledto forcibly enable precompiling for itself. Downstream binaries are expected to 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 by this target. Usually they describe the source files listed indirect_original_sources. This field is primarily for static analysis tools.These files are usually build-time only and not included as part of a runnable program.
Note
This may contain implementation-specific file types specific to a particular type 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 executable Python targets. These are accumulated from the transitivedeps. The order of the depset is not guaranteed and may be changed in the future. It is 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 downstream binaries (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 the original sources for this target and its transitive dependencies. This field is intended so that static analysis tools can recover the original 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).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 expected to 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 the Python 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 are usually build-time only and not included as part of a runnable program.
Note
This may contain implementation-specific file types specific to a particular type checker.
Added in version 1.1.0.
- PyInfo.transitive_sources: depset[File]
A (
postorder-compatible) depset of.pyfiles that are considered required and downstream binaries (or equivalent) must include in their outputs to have a functioning program.Normally, these are the
.pyfiles in the appearing in the target’ssrcsand thesrcsof the target’s transitivedeps, however, precompile settings may cause.pyfiles to be omitted. In particular, pyc-only builds may result in this depset being empty.Changed in version 0.37.0: The files are considered necessary for downstream binaries to function; previously they were considerd informational and largely unused.
Whether any of this target’s transitive
depshas a shared library file (such as 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 be removed without notice.
Added in version 1.5.0.
- typedef PyInfoBuilder
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’s builtin PyInfo object is disabled.
Get the
uses_shared_librariesvalue.- Returns:
- 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.
Sets
uses_shared_librariesbased on current and incomingvalue.- Args:
– (
bool)Another
uses_shared_librariesvalue. It will be merged into this builder’s state.
- 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
Sets
uses_shared_librariestovalue.- Args:
– (
bool)The value to set.
- Returns:
PyInfoBuilderself
- provider VenvSymlinkEntry
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 within the 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.
- typedef VenvSymlinkKind
An enum of types of venv directories.
- VenvSymlinkKind.BIN: object
Indicates to create paths under the directory that has binaries within 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.