Skip to content

Commit

Permalink
Merge branch 'main' into fix/correctly-translate-ppc64le
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas authored Jan 24, 2025
2 parents fdf2856 + ea716fe commit b6e3e34
Show file tree
Hide file tree
Showing 30 changed files with 382 additions and 150 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ Unreleased changes template.

{#v0-0-0-changed}
### Changed
* Nothing changed.
* (pypi) {obj}`pip.override` will now be ignored instead of raising an error,
fixes [#2550](https://github.com/bazelbuild/rules_python/issues/2550).
* (rules) deprecation warnings for deprecated symbols have been turned off by
default for now and can be enabled with `RULES_PYTHON_DEPRECATION_WARNINGS`
env var.

{#v0-0-0-fixed}
### Fixed
* (gazelle) Providing multiple input requirements files to `gazelle_python_manifest` now works correctly.
* (pypi) Handle trailing slashes in pip index URLs in environment variables,
fixes [#2554](https://github.com/bazelbuild/rules_python/issues/2554).
* (pypi) The `ppc64le` is now pointing to the right target in the `platforms` package.
* (runfiles) Runfile manifest and repository mapping files are now interpreted
as UTF-8 on all platforms.
* (coverage) Coverage with `--bootstrap_impl=script` is fixed
([#2572](https://github.com/bazelbuild/rules_python/issues/2572)).

{#v0-0-0-added}
### Added
Expand Down
7 changes: 6 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ python.toolchain(
is_default = True,
python_version = "3.11",
)
use_repo(python, "python_3_11", "python_versions", "pythons_hub")
use_repo(
python,
"python_3_11",
"pythons_hub",
python = "python_versions",
)

# This call registers the Python toolchains.
register_toolchains("@pythons_hub//:all")
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ load("//:internal_dev_setup.bzl", "rules_python_internal_setup")

rules_python_internal_setup()

load("@pythons_hub//:versions.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
load("@pythons_hub//:versions.bzl", "PYTHON_VERSIONS")
load("//python:repositories.bzl", "python_register_multi_toolchains")

python_register_multi_toolchains(
name = "python",
default_version = MINOR_MAPPING.values()[-3], # Use 3.11.10
default_version = "3.11",
# Integration tests verify each version, so register all of them.
python_versions = PYTHON_VERSIONS,
)
Expand Down
6 changes: 6 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ When `1`, bzlmod extensions will print debug information about what they're
doing. This is mostly useful for development to debug errors.
:::

:::{envvar} RULES_PYTHON_DEPRECATION_WARNINGS

When `1`, the rules_python will warn users about deprecated functionality that will
be removed in a subsequent major `rules_python` version. Defaults to `0` if unset.
:::

:::{envvar} RULES_PYTHON_ENABLE_PYSTAR

When `1`, the rules_python Starlark implementation of the core rules is used
Expand Down
5 changes: 3 additions & 2 deletions examples/bzlmod/other_module/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
load("@python_versions//3.11:defs.bzl", compile_pip_requirements_311 = "compile_pip_requirements")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

# NOTE: To update the requirements, you need to uncomment the rules_python
# override in the MODULE.bazel.
compile_pip_requirements_311(
compile_pip_requirements(
name = "requirements",
src = "requirements.in",
python_version = "3.11",
requirements_txt = "requirements_lock_3_11.txt",
)
8 changes: 3 additions & 5 deletions examples/bzlmod/other_module/other_module/pkg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
load(
"@python_3_11//:defs.bzl",
py_binary_311 = "py_binary",
)
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_library.bzl", "py_library")

py_library(
Expand All @@ -15,11 +12,12 @@ py_library(
# This is used for testing mulitple versions of Python. This is
# used only when you need to support multiple versions of Python
# in the same project.
py_binary_311(
py_binary(
name = "bin",
srcs = ["bin.py"],
data = ["data/data.txt"],
main = "bin.py",
python_version = "3.11",
visibility = ["//visibility:public"],
deps = [
":lib",
Expand Down
12 changes: 6 additions & 6 deletions examples/bzlmod/runfiles/runfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@ def testCurrentRepository(self):

def testRunfilesWithRepoMapping(self):
data_path = runfiles.Create().Rlocation("example_bzlmod/runfiles/data/data.txt")
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")

def testRunfileWithRlocationpath(self):
data_rlocationpath = os.getenv("DATA_RLOCATIONPATH")
data_path = runfiles.Create().Rlocation(data_rlocationpath)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")

def testRunfileInOtherModuleWithOurRepoMapping(self):
data_path = runfiles.Create().Rlocation(
"our_other_module/other_module/pkg/data/data.txt"
)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithItsRepoMapping(self):
data_path = lib.GetRunfilePathWithRepoMapping()
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithCurrentRepository(self):
data_path = lib.GetRunfilePathWithCurrentRepository()
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithRlocationpath(self):
data_rlocationpath = os.getenv("OTHER_MODULE_DATA_RLOCATIONPATH")
data_path = runfiles.Create().Rlocation(data_rlocationpath)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")


Expand Down
39 changes: 22 additions & 17 deletions examples/bzlmod/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
load("@python_versions//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test")
load("@python_versions//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test")
load("@python_versions//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_test.bzl", "py_test")
load("@rules_python//python/config_settings:transition.bzl", py_versioned_binary = "py_binary", py_versioned_test = "py_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

py_binary(
Expand All @@ -13,25 +9,28 @@ py_binary(
main = "version.py",
)

py_binary_3_9(
py_binary(
name = "version_3_9",
srcs = ["version.py"],
main = "version.py",
python_version = "3.9",
)

py_binary_3_10(
py_binary(
name = "version_3_10",
srcs = ["version.py"],
main = "version.py",
python_version = "3.10",
)

py_binary_3_11(
py_binary(
name = "version_3_11",
srcs = ["version.py"],
main = "version.py",
python_version = "3.11",
)

py_versioned_binary(
py_binary(
name = "version_3_10_versioned",
srcs = ["version.py"],
main = "version.py",
Expand All @@ -49,21 +48,23 @@ py_test(
deps = ["//libs/my_lib"],
)

py_test_3_9(
py_test(
name = "my_lib_3_9_test",
srcs = ["my_lib_test.py"],
main = "my_lib_test.py",
python_version = "3.9",
deps = ["//libs/my_lib"],
)

py_test_3_10(
py_test(
name = "my_lib_3_10_test",
srcs = ["my_lib_test.py"],
main = "my_lib_test.py",
python_version = "3.10",
deps = ["//libs/my_lib"],
)

py_versioned_test(
py_test(
name = "my_lib_versioned_test",
srcs = ["my_lib_test.py"],
main = "my_lib_test.py",
Expand Down Expand Up @@ -92,33 +93,36 @@ py_test(
main = "version_test.py",
)

py_test_3_9(
py_test(
name = "version_3_9_test",
srcs = ["version_test.py"],
env = {"VERSION_CHECK": "3.9"},
main = "version_test.py",
python_version = "3.9",
)

py_test_3_10(
py_test(
name = "version_3_10_test",
srcs = ["version_test.py"],
env = {"VERSION_CHECK": "3.10"},
main = "version_test.py",
python_version = "3.10",
)

py_versioned_test(
py_test(
name = "version_versioned_test",
srcs = ["version_test.py"],
env = {"VERSION_CHECK": "3.10"},
main = "version_test.py",
python_version = "3.10",
)

py_test_3_11(
py_test(
name = "version_3_11_test",
srcs = ["version_test.py"],
env = {"VERSION_CHECK": "3.11"},
main = "version_test.py",
python_version = "3.11",
)

py_test(
Expand All @@ -133,7 +137,7 @@ py_test(
main = "cross_version_test.py",
)

py_test_3_10(
py_test(
name = "version_3_10_takes_3_9_subprocess_test",
srcs = ["cross_version_test.py"],
data = [":version_3_9"],
Expand All @@ -143,9 +147,10 @@ py_test_3_10(
"VERSION_CHECK": "3.10",
},
main = "cross_version_test.py",
python_version = "3.10",
)

py_versioned_test(
py_test(
name = "version_3_10_takes_3_9_subprocess_test_2",
srcs = ["cross_version_test.py"],
data = [":version_3_9"],
Expand Down
12 changes: 6 additions & 6 deletions examples/bzlmod_build_file_generation/runfiles/runfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ def testRunfilesWithRepoMapping(self):
data_path = runfiles.Create().Rlocation(
"example_bzlmod_build_file_generation/runfiles/data/data.txt"
)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")

def testRunfileWithRlocationpath(self):
data_rlocationpath = os.getenv("DATA_RLOCATIONPATH")
data_path = runfiles.Create().Rlocation(data_rlocationpath)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, example_bzlmod!")

def testRunfileInOtherModuleWithOurRepoMapping(self):
data_path = runfiles.Create().Rlocation(
"our_other_module/other_module/pkg/data/data.txt"
)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithItsRepoMapping(self):
data_path = lib.GetRunfilePathWithRepoMapping()
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithCurrentRepository(self):
data_path = lib.GetRunfilePathWithCurrentRepository()
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")

def testRunfileInOtherModuleWithRlocationpath(self):
data_rlocationpath = os.getenv("OTHER_MODULE_DATA_RLOCATIONPATH")
data_path = runfiles.Create().Rlocation(data_rlocationpath)
with open(data_path) as f:
with open(data_path, "rt", encoding="utf-8", newline="\n") as f:
self.assertEqual(f.read().strip(), "Hello, other_module!")


Expand Down
17 changes: 9 additions & 8 deletions examples/multi_python_versions/requirements/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
load("@python//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
load("@python//3.11:defs.bzl", compile_pip_requirements_3_11 = "compile_pip_requirements")
load("@python//3.8:defs.bzl", compile_pip_requirements_3_8 = "compile_pip_requirements")
load("@python//3.9:defs.bzl", compile_pip_requirements_3_9 = "compile_pip_requirements")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements_3_8(
compile_pip_requirements(
name = "requirements_3_8",
src = "requirements.in",
python_version = "3.8",
requirements_txt = "requirements_lock_3_8.txt",
)

compile_pip_requirements_3_9(
compile_pip_requirements(
name = "requirements_3_9",
src = "requirements.in",
python_version = "3.9",
requirements_txt = "requirements_lock_3_9.txt",
)

compile_pip_requirements_3_10(
compile_pip_requirements(
name = "requirements_3_10",
src = "requirements.in",
python_version = "3.10",
requirements_txt = "requirements_lock_3_10.txt",
)

compile_pip_requirements_3_11(
compile_pip_requirements(
name = "requirements_3_11",
src = "requirements.in",
python_version = "3.11",
requirements_txt = "requirements_lock_3_11.txt",
)
Loading

0 comments on commit b6e3e34

Please sign in to comment.