Skip to content

Commit fbe3009

Browse files
dabankicopybara-github
authored andcommitted
Upgrade rules_python to 1.7.0
This is a fork of #27498. From the comments/open items on that PR, I've: 1. Removed the tests that were called out as not needed. 2. Added manual tag to `focus_test` to avoid pickup in larger runs until issue with `--experimental_enable_skyfocus` is resolved. 3. Switched failing test cases from using `from bazel_tools.tools.python.runfiles import runfiles` to use `from python.runfiles import runfiles` There are still a couple failing tests, looking for some guidance on if these can be removed/ignored: ``` test_source_file_does_not_override_standard_library FAILED: Expected regexp 'I am lib!' not found. ``` and ``` 1) explicitInitPy_CanBeSelectivelyDisabled(com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryConfiguredTargetTest) value of : getEmptyFilenames() unexpected (4): pkg/_foo.venv/lib/python3.11/__init__.py, pkg/_foo.venv/__init__.py, pkg/_foo.venv/lib/python3.11/site-packages/__init__.py, pkg/_foo.venv/lib/__init__.py --- expected : [pkg/__init__.py] but was : [pkg/_foo.venv/lib/python3.11/__init__.py, pkg/_foo.venv/__init__.py, pkg/_foo.venv/lib/python3.11/site-packages/__init__.py, pkg/__init__.py, pkg/_foo.venv/lib/__init__.py] at com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryConfiguredTargetTest.explicitInitPy_CanBeSelectivelyDisabled(BazelPyBinaryConfiguredTargetTest.java:235) 2) explicitInitPy_CanBeGloballyDisabled(com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryConfiguredTargetTest) value of : getEmptyFilenames() unexpected (4): pkg/_foo.venv/lib/python3.11/__init__.py, pkg/_foo.venv/__init__.py, pkg/_foo.venv/lib/python3.11/site-packages/__init__.py, pkg/_foo.venv/lib/__init__.py --- expected : [pkg/__init__.py] but was : [pkg/_foo.venv/lib/python3.11/__init__.py, pkg/_foo.venv/__init__.py, pkg/_foo.venv/lib/python3.11/site-packages/__init__.py, pkg/__init__.py, pkg/_foo.venv/lib/__init__.py] at com.google.devtools.build.lib.bazel.rules.python.BazelPyBinaryConfiguredTargetTest.explicitInitPy_CanBeGloballyDisabled(BazelPyBinaryConfiguredTargetTest.java:250) ``` Closes #27792. PiperOrigin-RevId: 839448559 Change-Id: I888614dd92fcbc4deda63a86a452bbd94e8f1523
1 parent 57ccfd7 commit fbe3009

File tree

20 files changed

+594
-478
lines changed

20 files changed

+594
-478
lines changed

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bazel_dep(name = "rules_java", version = "9.1.0")
2929
bazel_dep(name = "rules_jvm_external", version = "6.6")
3030
bazel_dep(name = "rules_license", version = "1.0.0")
3131
bazel_dep(name = "rules_pkg", version = "1.1.0")
32-
bazel_dep(name = "rules_python", version = "1.6.0")
32+
bazel_dep(name = "rules_python", version = "1.7.0")
3333
bazel_dep(name = "rules_shell", version = "0.6.1")
3434
bazel_dep(name = "rules_testing", version = "0.9.0")
3535
bazel_dep(name = "stardoc", version = "0.8.0", repo_name = "io_bazel_skydoc")
@@ -138,9 +138,9 @@ maven.install(
138138
# keep sorted
139139
"args4j:args4j:2.37",
140140
"com.beust:jcommander:1.82",
141-
"com.dylibso.chicory:log:1.5.2",
142141
"com.dylibso.chicory:runtime:1.5.2",
143142
"com.dylibso.chicory:wasm:1.5.2",
143+
"com.dylibso.chicory:log:1.5.2",
144144
"com.github.ben-manes.caffeine:caffeine:3.1.8",
145145
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
146146
"com.google.api-client:google-api-client:1.35.2",

MODULE.bazel.lock

Lines changed: 239 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MODULE.tools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use_repo(buildozer_binary, "buildozer_binary")
3535
bazel_dep(name = "protobuf", version = "33.0", repo_name = "com_google_protobuf")
3636
bazel_dep(name = "rules_java", version = "9.1.0")
3737
bazel_dep(name = "rules_cc", version = "0.2.14")
38-
bazel_dep(name = "rules_python", version = "1.6.0")
38+
bazel_dep(name = "rules_python", version = "1.7.0")
3939
bazel_dep(name = "rules_shell", version = "0.6.1")
4040
bazel_dep(name = "apple_support", version = "1.24.2") # xcode_configure needs it
4141
bazel_dep(name = "rules_apple", version = "4.1.0", repo_name = None) # version bump, older versions contribute lockfile entries

src/test/java/com/google/devtools/build/lib/bazel/rules/python/BUILD

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@ java_library(
1717
name = "PythonTests_lib",
1818
srcs = glob(["*.java"]),
1919
deps = [
20-
"//src/main/java/com/google/devtools/build/lib/actions",
21-
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
22-
"//src/main/java/com/google/devtools/build/lib/analysis:actions/substitution",
23-
"//src/main/java/com/google/devtools/build/lib/analysis:actions/template_expansion_action",
24-
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
25-
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
2620
"//src/main/java/com/google/devtools/build/lib/analysis/config:invalid_configuration_exception",
2721
"//src/main/java/com/google/devtools/build/lib/bazel/rules/python",
28-
"//src/main/java/com/google/devtools/build/lib/util:os",
29-
"//src/main/java/com/google/devtools/build/lib/vfs",
30-
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
3122
"//src/test/java/com/google/devtools/build/lib/analysis/util",
3223
"//src/test/java/com/google/devtools/build/lib/rules/python:PythonTestUtils",
3324
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",

src/test/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBinaryConfiguredTargetTest.java

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818
import static com.google.devtools.build.lib.rules.python.PythonTestUtils.getPyLoad;
1919

20-
import com.google.devtools.build.lib.actions.Action;
21-
import com.google.devtools.build.lib.actions.Artifact;
22-
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
23-
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
24-
import com.google.devtools.build.lib.analysis.actions.Substitution;
25-
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
2620
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
2721
import com.google.devtools.build.lib.testutil.TestConstants;
28-
import com.google.devtools.build.lib.util.OS;
29-
import com.google.devtools.build.lib.vfs.FileSystemUtils;
30-
import com.google.devtools.build.lib.vfs.PathFragment;
3122
import java.util.regex.Pattern;
3223
import org.junit.Test;
3324
import org.junit.runner.RunWith;
@@ -44,157 +35,11 @@ private static String join(String... lines) {
4435
return String.join("\n", lines);
4536
}
4637

47-
/**
48-
* Given a {@code py_binary} or {@code py_test} target and substitution key, returns the
49-
* corresponding substitution value used by the generated stub script.
50-
*
51-
* <p>This works by casting the stub script's generating action to a template expansion action and
52-
* looking for the requested substitution key. It's therefore linked to the implementation of the
53-
* rule, but that's the cost we pay for avoiding an execution-time test.
54-
*/
55-
private String getSubstitutionValueFromStub(
56-
ConfiguredTarget pyExecutableTarget, String substitutionKey) {
57-
// First find the stub script. Normally this is just the executable associated with the target.
58-
// But for Windows the executable is a separate launcher with an ".exe" extension, and the stub
59-
// script artifact has the same base name with the extension ".temp" instead. (At least, when
60-
// --build_python_zip is enabled, which is the default on Windows.)
61-
Artifact executable = pyExecutableTarget.getProvider(FilesToRunProvider.class).getExecutable();
62-
Artifact stub;
63-
if (OS.getCurrent() == OS.WINDOWS) {
64-
stub =
65-
getDerivedArtifact(
66-
FileSystemUtils.replaceExtension(executable.getRootRelativePath(), ".temp"),
67-
executable.getRoot(),
68-
executable.getArtifactOwner());
69-
} else {
70-
stub = executable;
71-
}
72-
assertThat(stub).isNotNull();
73-
// Now grab its generating action, which should be a template action, and get the key for the
74-
// binary path.
75-
Action generatingAction = getGeneratingAction(stub);
76-
assertThat(generatingAction).isInstanceOf(TemplateExpansionAction.class);
77-
TemplateExpansionAction templateAction = (TemplateExpansionAction) generatingAction;
78-
for (Substitution sub : templateAction.getSubstitutions()) {
79-
if (sub.getKey().equals(substitutionKey)) {
80-
return sub.getValueUnchecked();
81-
}
82-
}
83-
throw new AssertionError(
84-
"Failed to find the '"
85-
+ substitutionKey
86-
+ "' key in the stub script's template "
87-
+ "expansion action");
88-
}
89-
90-
private String getInterpreterPathFromStub(ConfiguredTarget pyExecutableTarget) {
91-
return getSubstitutionValueFromStub(pyExecutableTarget, "%python_binary%");
92-
}
93-
94-
private String getShebangFromStub(ConfiguredTarget pyExecutableTarget) {
95-
return getSubstitutionValueFromStub(pyExecutableTarget, "%shebang%");
96-
}
97-
9838
// TODO(brandjon): Move generic toolchain tests that don't access legacy behavior to
9939
// PyExecutableConfiguredtargetTestBase. Asserting on the chosen PyRuntimeInfo is problematic to
10040
// do at analysis time though. It's easier in this test because we know the PythonSemantics is
10141
// BazelPythonSemantics.
10242

103-
/** Adds toolchain definitions to a //toolchains package, for user by the below tests. */
104-
private void defineToolchains() throws Exception {
105-
scratch.file(
106-
"toolchains/BUILD",
107-
getPyLoad("py_runtime"),
108-
getPyLoad("py_runtime_pair"),
109-
"py_runtime(",
110-
" name = 'py3_runtime',",
111-
" interpreter_path = '/system/python3',",
112-
" python_version = 'PY3',",
113-
" stub_shebang = '#!/usr/bin/env python3',",
114-
")",
115-
"py_runtime_pair(",
116-
" name = 'py_runtime_pair',",
117-
" py3_runtime = ':py3_runtime',",
118-
")",
119-
"toolchain(",
120-
" name = 'py_toolchain',",
121-
" toolchain = ':py_runtime_pair',",
122-
" toolchain_type = '" + TOOLCHAIN_TYPE + "',",
123-
")",
124-
"py_runtime_pair(",
125-
" name = 'py_runtime_pair_for_py3_only',",
126-
" py3_runtime = ':py3_runtime',",
127-
")",
128-
"toolchain(",
129-
" name = 'py_toolchain_for_py3_only',",
130-
" toolchain = ':py_runtime_pair_for_py3_only',",
131-
" toolchain_type = '" + TOOLCHAIN_TYPE + "',",
132-
")");
133-
}
134-
135-
@Test
136-
public void runtimeObtainedFromToolchain() throws Exception {
137-
defineToolchains();
138-
scratch.file(
139-
"pkg/BUILD",
140-
getPyLoad("py_binary"),
141-
"""
142-
py_binary(
143-
name = "py3_bin",
144-
srcs = ["py3_bin.py"],
145-
python_version = "PY3",
146-
)
147-
""");
148-
useConfiguration("--extra_toolchains=//toolchains:py_toolchain");
149-
150-
ConfiguredTarget py3 = getConfiguredTarget("//pkg:py3_bin");
151-
152-
String py3Path = getInterpreterPathFromStub(py3);
153-
assertThat(py3Path).isEqualTo("/system/python3");
154-
155-
String py3Shebang = getShebangFromStub(py3);
156-
assertThat(py3Shebang).isEqualTo("#!/usr/bin/env python3");
157-
}
158-
159-
@Test
160-
public void toolchainCanOmitUnusedRuntimeVersion() throws Exception {
161-
defineToolchains();
162-
scratch.file(
163-
"pkg/BUILD",
164-
getPyLoad("py_binary"),
165-
"""
166-
py_binary(
167-
name = "py3_bin",
168-
srcs = ["py3_bin.py"],
169-
python_version = "PY3",
170-
)
171-
""");
172-
useConfiguration("--extra_toolchains=//toolchains:py_toolchain_for_py3_only");
173-
174-
String path = getInterpreterPathFromStub(getConfiguredTarget("//pkg:py3_bin"));
175-
assertThat(path).isEqualTo("/system/python3");
176-
}
177-
178-
@Test
179-
public void toolchainTakesPrecedenceOverLegacyFlags() throws Exception {
180-
defineToolchains();
181-
scratch.file(
182-
"pkg/BUILD",
183-
getPyLoad("py_binary"),
184-
"""
185-
py_binary(
186-
name = "py3_bin",
187-
srcs = ["py3_bin.py"],
188-
python_version = "PY3",
189-
)
190-
""");
191-
useConfiguration(
192-
"--extra_toolchains=//toolchains:py_toolchain", "--python_path=/better/not/be/this/one");
193-
194-
String path = getInterpreterPathFromStub(getConfiguredTarget("//pkg:py3_bin"));
195-
assertThat(path).isEqualTo("/system/python3");
196-
}
197-
19843
/**
19944
* Creates a custom toolchain at //toolchains:custom that has the given lines in its rule
20045
* implementation function.
@@ -282,37 +127,6 @@ public void explicitInitPy_CanBeGloballyEnabled() throws Exception {
282127
assertThat(getDefaultRunfiles(getConfiguredTarget("//pkg:foo")).getEmptyFilenames()).isEmpty();
283128
}
284129

285-
@Test
286-
public void explicitInitPy_CanBeSelectivelyDisabled() throws Exception {
287-
scratch.file(
288-
"pkg/BUILD",
289-
getPyLoad("py_binary"),
290-
join(
291-
"py_binary(", //
292-
" name = 'foo',",
293-
" srcs = ['foo.py'],",
294-
" legacy_create_init = True,",
295-
")"));
296-
useConfiguration("--incompatible_default_to_explicit_init_py=true");
297-
assertThat(getDefaultRunfiles(getConfiguredTarget("//pkg:foo")).getEmptyFilenames())
298-
.containsExactly(PathFragment.create("pkg/__init__.py"));
299-
}
300-
301-
@Test
302-
public void explicitInitPy_CanBeGloballyDisabled() throws Exception {
303-
scratch.file(
304-
"pkg/BUILD",
305-
getPyLoad("py_binary"),
306-
join(
307-
"py_binary(", //
308-
" name = 'foo',",
309-
" srcs = ['foo.py'],",
310-
")"));
311-
useConfiguration("--incompatible_default_to_explicit_init_py=false");
312-
assertThat(getDefaultRunfiles(getConfiguredTarget("//pkg:foo")).getEmptyFilenames())
313-
.containsExactly(PathFragment.create("pkg/__init__.py"));
314-
}
315-
316130
@Test
317131
public void explicitInitPy_CanBeSelectivelyEnabled() throws Exception {
318132
scratch.file(

src/test/java/com/google/devtools/build/lib/buildtool/BUILD

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,6 @@ java_test(
102102
],
103103
)
104104

105-
java_test(
106-
name = "CompileOneDependencyIntegrationTest",
107-
srcs = ["CompileOneDependencyIntegrationTest.java"],
108-
tags = [
109-
"no_windows",
110-
],
111-
deps = [
112-
"//src/main/java/com/google/devtools/build/lib/actions",
113-
"//src/main/java/com/google/devtools/build/lib/events",
114-
"//src/test/java/com/google/devtools/build/lib/buildtool/util",
115-
"//src/test/java/com/google/devtools/build/lib/rules/python:PythonTestUtils",
116-
"//third_party:junit4",
117-
"//third_party:truth",
118-
],
119-
)
120-
121105
java_test(
122106
name = "ContextProviderInitializationTest",
123107
srcs = ["ContextProviderInitializationTest.java"],

0 commit comments

Comments
 (0)