Skip to content

Commit 628d40f

Browse files
Enabled CI for Windows (#585)
Co-authored-by: Alex Eagle <[email protected]>
1 parent a62864f commit 628d40f

File tree

12 files changed

+173
-53
lines changed

12 files changed

+173
-53
lines changed

.bazelci/presubmit.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,33 @@ buildifier:
44
# keep this argument in sync with .pre-commit-config.yaml
55
warnings: "all"
66
all_targets: &all_targets
7-
build_targets:
7+
build_targets:
88
- "..."
99
# As a regression test for #225, check that wheel targets still build when
1010
# their package path is qualified with the repo name.
1111
- "@rules_python//examples/wheel/..."
12-
# We control Bazel version in integration tests, so we don't need USE_BAZEL_VERSION for tests.
13-
skip_use_bazel_version_for_test: true
14-
test_targets:
12+
# We control Bazel version in integration tests, so we don't need USE_BAZEL_VERSION for tests.
13+
skip_use_bazel_version_for_test: true
14+
test_targets:
1515
- "..."
1616
platforms:
1717
ubuntu1804:
1818
<<: *all_targets
1919
macos:
2020
<<: *all_targets
21+
windows:
22+
build_targets:
23+
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
24+
- "..."
25+
# Gazelle is not fully Windows compatible: https://github.com/bazelbuild/bazel-gazelle/issues/1122
26+
- "-//gazelle/..."
27+
# As a regression test for #225, check that wheel targets still build when
28+
# their package path is qualified with the repo name.
29+
- "@rules_python//examples/wheel/..."
30+
# We control Bazel version in integration tests, so we don't need USE_BAZEL_VERSION for tests.
31+
skip_use_bazel_version_for_test: true
32+
test_targets:
33+
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
34+
- "..."
35+
# Gazelle is not fully Windows compatible: https://github.com/bazelbuild/bazel-gazelle/issues/1122
36+
- "-//gazelle/..."

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ test --test_output=errors
1515
# creating (possibly empty) __init__.py files and adding them to the srcs of
1616
# Python targets as required.
1717
build --incompatible_default_to_explicit_init_py
18+
19+
# Windows makes use of runfiles for some rules
20+
build --enable_runfiles

docs/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,27 @@ bzl_library(
7878
],
7979
)
8080

81+
# TODO: Stardoc does not guarantee consistent outputs accross platforms (Unix/Windows).
82+
# As a result we do not build or test docs on Windows.
83+
_NOT_WINDOWS = select({
84+
"@platforms//os:linux": [],
85+
"@platforms//os:macos": [],
86+
"//conditions:default": ["@platforms//:incompatible"],
87+
})
88+
8189
stardoc(
8290
name = "core-docs",
8391
out = "python.md_",
8492
input = "//python:defs.bzl",
93+
target_compatible_with = _NOT_WINDOWS,
8594
deps = [":defs"],
8695
)
8796

8897
stardoc(
8998
name = "pip-docs",
9099
out = "pip.md_",
91100
input = "//python:pip.bzl",
101+
target_compatible_with = _NOT_WINDOWS,
92102
deps = [
93103
":bazel_repo_tools",
94104
":pip_install_bzl",
@@ -100,6 +110,7 @@ stardoc(
100110
name = "packaging-docs",
101111
out = "packaging.md_",
102112
input = "//python:packaging.bzl",
113+
target_compatible_with = _NOT_WINDOWS,
103114
deps = [":packaging_bzl"],
104115
)
105116

@@ -109,6 +120,7 @@ stardoc(
109120
failure_message = "Please run: bazel run //docs:update",
110121
file1 = k + ".md",
111122
file2 = k + ".md_",
123+
target_compatible_with = _NOT_WINDOWS,
112124
)
113125
for k in _DOCS.keys()
114126
]
@@ -123,10 +135,12 @@ write_file(
123135
"cp -fv bazel-bin/docs/{0}.md_ docs/{0}.md".format(k)
124136
for k in _DOCS.keys()
125137
],
138+
target_compatible_with = _NOT_WINDOWS,
126139
)
127140

128141
sh_binary(
129142
name = "update",
130143
srcs = ["update.sh"],
131144
data = _DOCS.values(),
145+
target_compatible_with = _NOT_WINDOWS,
132146
)

examples/wheel/wheel_test.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import platform
1617
import unittest
1718
import zipfile
1819

@@ -89,9 +90,24 @@ def test_customized_wheel(self):
8990
"example_customized-0.0.1.dist-info/entry_points.txt"
9091
)
9192
# The entries are guaranteed to be sorted.
92-
self.assertEquals(
93-
record_contents,
94-
b"""\
93+
if platform.system() == "Windows":
94+
self.assertEquals(
95+
record_contents,
96+
b"""\
97+
example_customized-0.0.1.dist-info/METADATA,sha256=pzE96o3Sp63TDzxAZgl0F42EFevm8x15vpDLqDVp_EQ,378
98+
example_customized-0.0.1.dist-info/RECORD,,
99+
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
100+
example_customized-0.0.1.dist-info/entry_points.txt,sha256=pqzpbQ8MMorrJ3Jp0ntmpZcuvfByyqzMXXi2UujuXD0,137
101+
examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12
102+
examples/wheel/lib/module_with_data.py,sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms,637
103+
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
104+
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
105+
""",
106+
)
107+
else:
108+
self.assertEquals(
109+
record_contents,
110+
b"""\
95111
example_customized-0.0.1.dist-info/METADATA,sha256=TeeEmokHE2NWjkaMcVJuSAq4_AXUoIad2-SLuquRmbg,372
96112
example_customized-0.0.1.dist-info/RECORD,,
97113
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
@@ -101,7 +117,7 @@ def test_customized_wheel(self):
101117
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
102118
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
103119
""",
104-
)
120+
)
105121
self.assertEquals(
106122
wheel_contents,
107123
b"""\
@@ -111,9 +127,28 @@ def test_customized_wheel(self):
111127
Tag: py3-none-any
112128
""",
113129
)
114-
self.assertEquals(
115-
metadata_contents,
116-
b"""\
130+
if platform.system() == "Windows":
131+
self.assertEquals(
132+
metadata_contents,
133+
b"""\
134+
Metadata-Version: 2.1
135+
Name: example_customized
136+
Version: 0.0.1
137+
Author: Example Author with non-ascii characters: \xc3\x85\xc2\xbc\xc3\x83\xc2\xb3\xc3\x85\xc2\x82w
138+
Author-email: [email protected]
139+
Home-page: www.example.com
140+
License: Apache 2.0
141+
Classifier: License :: OSI Approved :: Apache Software License
142+
Classifier: Intended Audience :: Developers
143+
Requires-Dist: pytest
144+
145+
This is a sample description of a wheel.
146+
""",
147+
)
148+
else:
149+
self.assertEquals(
150+
metadata_contents,
151+
b"""\
117152
Metadata-Version: 2.1
118153
Name: example_customized
119154
Version: 0.0.1
@@ -127,7 +162,7 @@ def test_customized_wheel(self):
127162
128163
This is a sample description of a wheel.
129164
""",
130-
)
165+
)
131166
self.assertEquals(
132167
entry_point_contents,
133168
b"""\

python/pip_install/extract_wheels/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88
import argparse
99
import glob
10-
import json
1110
import os
1211
import pathlib
1312
import subprocess

python/pip_install/extract_wheels/lib/BUILD

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ py_test(
7373
py_test(
7474
name = "whl_filegroup_test",
7575
size = "small",
76-
srcs = [
77-
"whl_filegroup_test.py",
78-
],
76+
srcs = ["whl_filegroup_test.py"],
7977
data = ["//examples/wheel:minimal_with_py_package"],
78+
main = "whl_filegroup_test.py",
8079
tags = ["unit"],
81-
deps = [
82-
":lib",
83-
],
80+
deps = [":lib"],
8481
)
8582

8683
py_test(

python/pip_install/extract_wheels/lib/bazel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def extract_wheel(
296296
enable_implicit_namespace_pkgs: bool,
297297
repo_prefix: str,
298298
incremental: bool = False,
299+
incremental_dir: Path = Path("."),
299300
) -> Optional[str]:
300301
"""Extracts wheel into given directory and creates py_library and filegroup targets.
301302
@@ -306,14 +307,15 @@ def extract_wheel(
306307
enable_implicit_namespace_pkgs: if true, disables conversion of implicit namespace packages and will unzip as-is
307308
incremental: If true the extract the wheel in a format suitable for an external repository. This
308309
effects the names of libraries and their dependencies, which point to other external repositories.
310+
incremental_dir: An optional override for the working directory of incremental builds.
309311
310312
Returns:
311313
The Bazel label for the extracted wheel, in the form '//path/to/wheel'.
312314
"""
313315

314316
whl = wheel.Wheel(wheel_file)
315317
if incremental:
316-
directory = "."
318+
directory = incremental_dir
317319
else:
318320
directory = sanitise_name(whl.name, prefix=repo_prefix)
319321

python/pip_install/extract_wheels/lib/wheel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def entry_points(self) -> Dict[str, str]:
5555
# Calculate the location of the entry_points.txt file
5656
metadata = self.metadata
5757
name = "{}-{}".format(metadata.name.replace("-", "_"), metadata.version)
58+
5859
# Note that the zipfile module always uses the forward slash as
5960
# directory separator, even on Windows, so don't use os.path.join
6061
# here. Reference for Python 3.10:

python/pip_install/extract_wheels/lib/whl_filegroup_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import tempfile
44
import unittest
5+
from pathlib import Path
56

67
from python.pip_install.extract_wheels.lib import bazel
78

@@ -12,12 +13,9 @@ def setUp(self) -> None:
1213
self.wheel_dir = tempfile.mkdtemp()
1314
self.wheel_path = os.path.join(self.wheel_dir, self.wheel_name)
1415
shutil.copy(os.path.join("examples", "wheel", self.wheel_name), self.wheel_dir)
15-
self.original_dir = os.getcwd()
16-
os.chdir(self.wheel_dir)
1716

1817
def tearDown(self):
1918
shutil.rmtree(self.wheel_dir)
20-
os.chdir(self.original_dir)
2119

2220
def _run(
2321
self,
@@ -31,12 +29,14 @@ def _run(
3129
enable_implicit_namespace_pkgs=False,
3230
incremental=incremental,
3331
repo_prefix=repo_prefix,
32+
incremental_dir=Path(self.wheel_dir),
3433
)
3534
# Take off the leading // from the returned label.
3635
# Assert that the raw wheel ends up in the package.
3736
generated_bazel_dir = (
3837
generated_bazel_dir[2:] if not incremental else self.wheel_dir
3938
)
39+
4040
self.assertIn(self.wheel_name, os.listdir(generated_bazel_dir))
4141
with open("{}/BUILD.bazel".format(generated_bazel_dir)) as build_file:
4242
build_file_content = build_file.read()

python/pip_install/parse_requirements_to_bzl/parse_requirements_to_bzl_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import argparse
22
import json
3+
import tempfile
34
import unittest
4-
from tempfile import NamedTemporaryFile
5+
from pathlib import Path
56

67
from python.pip_install.parse_requirements_to_bzl import (
78
generate_parsed_requirements_contents,
@@ -10,15 +11,15 @@
1011

1112
class TestParseRequirementsToBzl(unittest.TestCase):
1213
def test_generated_requirements_bzl(self) -> None:
13-
with NamedTemporaryFile() as requirements_lock:
14+
with tempfile.TemporaryDirectory() as temp_dir:
15+
requirements_lock = Path(temp_dir) / "requirements.txt"
1416
comments_and_flags = "#comment\n--require-hashes True\n"
1517
requirement_string = "foo==0.0.0 --hash=sha256:hashofFoowhl"
16-
requirements_lock.write(
18+
requirements_lock.write_bytes(
1719
bytes(comments_and_flags + requirement_string, encoding="utf-8")
1820
)
19-
requirements_lock.flush()
2021
args = argparse.Namespace()
21-
args.requirements_lock = requirements_lock.name
22+
args.requirements_lock = str(requirements_lock.resolve())
2223
args.repo_prefix = "pip_parsed_deps_pypi__"
2324
extra_pip_args = ["--index-url=pypi.org/simple"]
2425
pip_data_exclude = ["**.foo"]

0 commit comments

Comments
 (0)