Skip to content

Commit

Permalink
Expose Python configuration fragments to Starlark for Bazel
Browse files Browse the repository at this point in the history
Work towards #15897

PiperOrigin-RevId: 488684553
Change-Id: I6b439cf5b8fd75170e6647e4c76fa4ac8f72bdec
  • Loading branch information
rickeylev authored and Copybara-Service committed Nov 15, 2022
1 parent 4caae75 commit 38b2789
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Expand Up @@ -49,6 +49,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/common/options",
"//src/main/java/net/starlark/java/annot",
"//third_party:guava",
"//third_party:jsr305",
],
Expand Down
Expand Up @@ -30,9 +30,12 @@
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionMetadataTag;
import net.starlark.java.annot.StarlarkBuiltin;
import net.starlark.java.annot.StarlarkMethod;

/** Bazel-specific Python configuration. */
@Immutable
@StarlarkBuiltin(name = "bazel_py")
@RequiresOptions(options = {BazelPythonConfiguration.Options.class, PythonOptions.class})
public class BazelPythonConfiguration extends Fragment {

Expand Down Expand Up @@ -92,9 +95,7 @@ public static final class Options extends FragmentOptions {
+ "is less likely to experience import name collisions.")
public boolean experimentalPythonImportAllRepositories;

/**
* Make Python configuration options available for host configurations as well
*/
/** Make Python configuration options available for host configurations as well */
@Override
public FragmentOptions getHost() {
return clone(); // host options are the same as target options
Expand Down Expand Up @@ -151,8 +152,11 @@ public String getPythonPath() {
return options.pythonPath == null ? "python" : options.pythonPath;
}

@StarlarkMethod(
name = "python_import_all_repositories",
structField = true,
doc = "The value of the --experimental_python_import_all_repositories flag.")
public boolean getImportAllRepositories() {
return options.experimentalPythonImportAllRepositories;
}

}
Expand Up @@ -126,6 +126,10 @@ public String getOutputDirectoryName() {
}

/** Returns whether to build the executable zip file for Python binaries. */
@StarlarkMethod(
name = "build_python_zip",
structField = true,
doc = "The effective value of --build_python_zip")
public boolean buildPythonZip() {
switch (buildPythonZip) {
case YES:
Expand Down Expand Up @@ -157,6 +161,10 @@ public boolean useToolchains() {
return useToolchains;
}

@StarlarkMethod(
name = "default_to_explicit_init_py",
structField = true,
doc = "The value from the --incompatible_default_to_explicit_init_py flag")
/**
* Returns true if executable Python rules should only write out empty __init__ files to their
* runfiles tree when explicitly requested via {@code legacy_create_init}.
Expand Down

0 comments on commit 38b2789

Please sign in to comment.