Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bazel-contrib/rules_python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.21.0
Choose a base ref
...
head repository: bazel-contrib/rules_python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.22.0
Choose a head ref

Commits on Apr 24, 2023

  1. fix: remove reference to @bazel_tools//tools/python/private:defs.bzl (#…

    …1173)
    
    The file was removed in Bazel@HEAD in
    bazelbuild/bazel#17545
    This fixes failures when using rules_python with Bazel@HEAD.
    
    Addresses: bazelbuild/bazel#17874
    comius authored Apr 24, 2023
    Copy the full SHA
    73aec8f View commit details

Commits on Apr 25, 2023

  1. docs: Tell how to use GitHub to find commits in an upcoming release. (#…

    …1092)
    
    I can never remember what the syntax is of the compare URLs, so just doc
    it to make it easier.
    rickeylev authored Apr 25, 2023
    Copy the full SHA
    c5f24dd View commit details
  2. fix: compile_pip_requirements test from external repositories (#1124)

    Previously when running the compile_pip_requirements test from an
    external repository the test failed. This was due to the fact that paths
    in the annotations of the lock file contained paths from the external
    repository. Another problem was that the requirement files could not be
    located.
    Rasrack authored Apr 25, 2023
    Copy the full SHA
    9528806 View commit details
  3. feat: add Python 3.8.16 (#1168)

    Add python 3.8.16
    jml-derek authored Apr 25, 2023
    Copy the full SHA
    ba2a903 View commit details

Commits on Apr 26, 2023

  1. test: Set mac platform for test_mac_requires_darwin_for_execution (#1179

    )
    
    This makes the test pass on Bazel built from head. The failure appears
    due to not forcing the test to a Mac platform, so the underlying logic
    in `py_test` to detect the Mac platform fails and doesn't add the
    ExecutionInfo with the necessary info.
    
    Work towards bazelbuild/bazel/issues/18170
    rickeylev authored Apr 26, 2023
    Copy the full SHA
    fb6f49f View commit details
  2. fix: Don't reference deleted private bazel_tools bzl file (#1180)

    The latest versions of Bazel have removed the
    `@bazel_tools//tools/python:private/defs.bzl` file, so it can no longer
    be referenced.
    
    Work towards bazelbuild/bazel/issues/18170
    rickeylev authored Apr 26, 2023
    Copy the full SHA
    600dbe1 View commit details

Commits on Apr 27, 2023

  1. docs: Add starlark directive to code snippet (#1170)

    A very minor cleaup change.
    blorente authored Apr 27, 2023
    Copy the full SHA
    2882bb6 View commit details
  2. tests: Upgrade rules_testing to 0.0.5 (#1184)

    This just keeps it at a recent version, which makes errors easier to
    grok. rules_testing recently underwent a large refactor, so it's
    confusing when errors reference lines that no longer exist in recent
    versions.
    rickeylev authored Apr 27, 2023
    Copy the full SHA
    548ced5 View commit details

Commits on Apr 28, 2023

  1. tests: Set linux platform for test_non_mac_doesnt_require_darwin_for_…

    …execution (#1183)
    
    This is the inverse test of the one testing for the mac platform. As
    before, the line forcing the platform to a non-mac platform was
    commented out, which meant, when a mac host built it, it would build the
    underlying target for Mac, which violated the test's assumptions.
    
    Work towards bazelbuild/bazel/issues/18170
    
    Fixes #1185
    rickeylev authored Apr 28, 2023
    Copy the full SHA
    ce74914 View commit details

Commits on May 1, 2023

  1. fix(bzlmod): correctly template repository macros for requirements, e…

    …tc (#1190)
    
    It seems that the macros for specifying the requirements break when the
    user starts using `incompatible_generate_aliases=True`. This PR fixes
    this.
    
    Testing done:
    1. Modify the example:
       ```
       $ git diff
    diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel
       index ce91228..1750210 100644
       --- a/examples/bzlmod/MODULE.bazel
       +++ b/examples/bzlmod/MODULE.bazel
       @@ -26,6 +26,7 @@ register_toolchains(
        pip = use_extension("@rules_python//python:extensions.bzl", "pip")
        pip.parse(
            name = "pip",
       +    incompatible_generate_aliases=True,
            requirements_lock = "//:requirements_lock.txt",
            requirements_windows = "//:requirements_windows.txt",
        )
       ```
    2. Run `bazel build ...` and check that it is still working.
    
    I noticed this when working on #1189 and creating a separate PR for
    easier cherry-picking if we wanted to make a patch release which
    includes this. I am not sure how I could make an automated test for this
    other than creating a separate example.
    aignas authored May 1, 2023
    Copy the full SHA
    1d1efe9 View commit details
  2. type:docs Update README.md (#1186)

    Change instruction to refer to `MODULE.bazel` instead of
    `MODULES.bazel`.
    yuanweixin authored May 1, 2023
    Copy the full SHA
    c20aa1a View commit details

Commits on May 2, 2023

  1. fix: Allow passing a tuple to the tags attribute. (#1191)

    Starlark rules allow giving the tags as a tuple. The helper function
    that added the special migration tag assumed tags was always a list,
    resulting in an error when it tried to concatenate a list and tuple.
    
    To fix, check if tags is a tuple and concatenate a tuple if so. The
    input type of the tags attribute is preserved so that a test verifying
    tags can be passed to the underlying rule can be implemented (this test
    is to verify there isn't a regression during the rewrite to Starlark).
    rickeylev authored May 2, 2023
    Copy the full SHA
    2df3259 View commit details

Commits on May 3, 2023

  1. tests: Add skylib to various test dependencies to fix CI (#1199)

    This fixes a problem where bazel skylib does not load during the
    toolchain integration test.
    
    The skylib dependency was introduced by #1191, but skylib was not
    present in the WORKSPACE configs of several things. To fix, skylib just
    needs to be added to the workspace files.
    chrislovecnm authored May 3, 2023
    Copy the full SHA
    81a200b View commit details
  2. feat: removing bzlmod from example (#1200)

    Having both bzlmod and a WORKSPACE file confuses the user, and I have
    #1155 which adds a new example for gazelle and bzlmod.
    chrislovecnm authored May 3, 2023
    Copy the full SHA
    96b4fa1 View commit details
  3. feat: propagate visibility attribute for py_wheel publishing (#1203)

    py_wheel does not propagate "visibility" attribute to the "publish"
    rule. The visibility attribute on py_wheel target is not propagated to
    the auto-generated "publish" target. This commit adds the visibility
    attribute.
    
    Closes: #1192
    chrislovecnm authored May 3, 2023
    Copy the full SHA
    e400791 View commit details
  4. Copy the full SHA
    fc94642 View commit details
  5. tests: Force analysis test labels to resolve within @rules_python con…

    …text (#1187)
    
    When a string label is passed to the `@rules_testing` analysis_test
    functions, the strings are evaluated within the context of
    @rules_testing because that is where the actual rule invocation happens.
    Without bzlmod, this just requires qualifying the labels with the repo
    name (which is what was being done) because there's just a flat global
    namespace of repos.
    
    With bzlmod enabled, repo mapping happens, so rules_testing tries to
    resolve those repo names using its repo mapping, which doesn't work
    because rules_testing's mapping doesn't include every repo using it.
    rickeylev authored May 3, 2023
    Copy the full SHA
    532f07a View commit details

Commits on May 4, 2023

  1. fix(update_deleted_packages.sh): allow to run from anywhere in the re…

    …po (#1206)
    
    It seems that the tool was correctly trying to modify the `.bazelrc` at
    the
    root of the repo, but the `find` execution would run in the `$PWD`. This
    change ensures that the `find` is consistent with the file we are trying
    to modify and allows the user to execute the script from anywhere in the
    repo.
    
    Tested:
    1. Update the deleted packages with the version of the script at HEAD
    1. Fix the bug
    1. Rerun the script from the 'tests' sub-folder in the repo to ensure
    that
       running the script is noop.
    1. Revert the changes to '.bazelrc' to reduce conflicts as other PRs are
       modifying it.
    
    Work towards #958.
    aignas authored May 4, 2023
    Copy the full SHA
    262c699 View commit details
  2. feat(bzlmod): expose platform-agnostic repo target for toolchain inte…

    …rpreter (#1155)
    
    This exposes a new repo and target, `@{name}_host_interpreter//:python`,
    created by `python.toolchain()`, that points to the host OS's Python
    interpreter for that particular toolchain.
    
    This solves two problems:
    1. `pip.parse()` can now refer to the same interpreter used in the
    toolchains
    2. There is now a canonical, public, way to refer to the host OS Python
    interpreter
        for repository rules.
    
    The above were _sort of_ possible for users to do already, but it
    required them to write much more configuration and extension code to do
    so. This moves that sort of boilerplate into our code so they have a
    simpler configuration.
    
    Also:
    - removing bzlmod support in the build_file_generation example; making
    examples work
      with both WORKSPACE and MODULE is a pain, hence splitting them.
    - adding an example of bzlmod and gazelle
    - improved documentation in the pip arguments
    
    Closes: #1161
    chrislovecnm authored May 4, 2023
    Copy the full SHA
    0912bba View commit details
  3. fix(update_deleted_packages.sh): wheels example should not be include…

    …d in .bazelrc (#1207)
    
    This correctly handles the integration tests and examples that are a
    part of
    the `rules_python` workspace and should not be included in the deleted
    packages
    list.
    
    This brings the changes made to the `.bazelrc` very close to what is in
    `main`,
    but I would like to update this later once #1155 and #1205 are merged.
    
    Fixes #919.
    aignas authored May 4, 2023
    Copy the full SHA
    23cf6b6 View commit details

Commits on May 8, 2023

  1. fix: Strip trailing newline from python output (#1212)

    This is used to generate a path, which shouldn't have a trailing
    newline.
    illicitonion authored May 8, 2023
    Copy the full SHA
    799e63f View commit details
  2. fix: manually ignore bazel-* directories to make using custom Bazel b…

    …uilds easier (#1181)
    
    Normally, Bazel will ignore its convenience symlinks, so putting them in
    the .bazelignore file isn't necessary. However, when
    `--output_user_root` is set, which is beneficial to set when using
    different Bazel versions (it preserves the analysis cache between
    versions), the symlinks aren't ignored. Putting them in the bazelignore
    file fixes this.
    rickeylev authored May 8, 2023
    Copy the full SHA
    0efcd94 View commit details

Commits on May 14, 2023

  1. test(bzlmod): explicitly enable bzlmod in the test harness (#1204)

    Previously we would depend on the value of .bazelrc and this
    change ensures that we are explicitly enable bzlmod via CLI
    args. It seems that the `py_proto_library` integration tests
    defined in the `//examples:BUILD.bazel` file were not running
    using `bzlmod` before hand, however, they were correctly
    executed in the CI.
    
    Work towards #958.
    aignas authored May 14, 2023
    Copy the full SHA
    d434f10 View commit details

Commits on May 15, 2023

  1. feat(bzlmod): Cleaning up interpreter resolution (#1218)

    This commit cleans up the use of "canonical resolution" of
      the Python interpreter. When the extension toolchains run
      it collects a list of the interpreters and then
      uses the hub_repo rule to create a map of names and the
      interpreter labels.
     
     Next, we then use the interpreter_extension that, creates
     reports that have symlinks pointing to the different interpreter
     binaries.
    
    The user can then pass in a label to the pip call for the
     specific hermetic interpreter.
    chrislovecnm authored May 15, 2023
    Copy the full SHA
    ccea92a View commit details
  2. feat(bzlmod)!: Move each bzlmod extension into its own file (#1226)

    This commit refactors the files that contain the bzlmod
    extensions.
    
    - All extensions are moved under the new extensions folder
    - Private extensions are moved under extensions/private
    - All extension files are renamed to remove the _extension suffix
    - pip and internal_deps extensions are moved to their own file
    
    This commit organizes the extensions better and also follows the
    best practice of having a single extension per file. Having each
    extension in its own file allows them to use some additional features
    while helping avoid backwards incompatible changes.
    
    ## BREAKING CHANGES
    
    This splits `//python:extensions.bzl`, which previously held the
    `python`
    and `pip` extensions, into separate files (`python.bzl` and `pip.bzl`,
    respectively). Unfortunately, moving the location of the extensions is a
    breaking change due to how bzlmod extension identity works (see
    https://bazel.build/external/extension#extension_identity). Fortunately,
    by moving to one extension per file, we shouldn't have to ever do this
    again.
    
    Users must update the file path in their `use_repo()` statements as
    follows:
    
    * `use_extension("@rules_python//python:extensions.bzl", "python")` ->
    `use_extension("@rules_python//python/extensions:python.bzl", "python")`
    * `use_extension("@rules_python//python:extensions.bzl", "pip")` ->
    `use_extension("@rules_python//python/extensions:pip.bzl", "pip")`
    
    The following `sed` commands should approximate the necessary changes:
    
    ```
    sed 'sXuse_extension("@rules_python//python:extensions.bzl", "python")Xuse_extension("@rules_python//python/extensions:python.bzl", "python")X'`
    sed 'sXuse_extension("@rules_python//python:extensions.bzl", "pip")Xuse_extension("@rules_python//python/extensions:pip.bzl", "pip")X'`
    
    ```
    
    See `examples/bzlmod_build_file_generation/MODULE.bazel` for an example
    of the new paths.
    chrislovecnm authored May 15, 2023
    Copy the full SHA
    46537cf View commit details
  3. Adding bzlmod support document (#1214)

    This markdown file maintains the current status of our bzlmod
    implementation. Created section in README and linked to the bzlmod doc.
    chrislovecnm authored May 15, 2023
    Copy the full SHA
    9268d91 View commit details

Commits on May 16, 2023

  1. test(coverage): add a test to check the sys.path under bzlmod (#1223)

    Whilst it is for documentation purposes for maintainers it is also a
    regression
    test for #1045. Also add a test to ensure that the `html` module is not
    shadowed when running under `coverage`.
    
    Fixes #1196.
    aignas authored May 16, 2023
    Copy the full SHA
    16126d0 View commit details

Commits on May 17, 2023

  1. fix(toolchain): set correct return attrs to remove non-hermeticity wa…

    …rning (#1231)
    
    Fixes the incorrect debug statement when downloading the toolchain for
    the first
    time asking users to replace "urls" with "url" in the toolchain
    definition which
    we maintain:
    ```
    $ bazel build ...
    ... indicated that a canonical reproducible form can be obtained by modifying ...
    ```
    
    Even though this is seen only once by the user, it may confuse them.
    
    Summary of changes:
    - refactor(toolchain): rename a local variable url -> urls
    - fix(toolchain): set url return attrs correctly
    aignas authored May 17, 2023
    Copy the full SHA
    07e6856 View commit details
  2. fix: allow url fragments in requirements file (#1195)

    This commit addresses issue #1194 (see issue for details).
    
    It brings the `comment` detection of `requirements_parser.bzl` closer to
    the spec described here:
    -
    https://pip.pypa.io/en/stable/reference/requirements-file-format/#comments
    
    1. Lines that begin with `#` are comments.
    2. Content after (and including) ` #` is a comment.
    
    Prior to this commit, a dependency like this would result in invalid
    `pip wheel` arguments:
    
    ```
    requests @ https://github.com/psf/requests/releases/download/v2.29.0/requests-2.29.0.tar.gz#sha1=3897c249b51a1a405d615a8c9cb92e5fdbf0dd49
    ```
    mattoberle authored May 17, 2023
    Copy the full SHA
    02ace45 View commit details
  3. fix: example/build_file_generation/README.md (#1164)

    This PR updates outdated README.md of example.
    
    Closes #1160
    
    ---------
    
    Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
    Co-authored-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
    ofey404 and f0rmiga authored May 17, 2023
    Copy the full SHA
    28bc03c View commit details
  4. fix: Using canonical name in requirements.bzl (#1176)

    When `incompatible_generate_aliases = False`, `pip.parse` doesn't work
    in bzlmod, because requirements.bzl has:
    
    ```
    all_requirements = ["@rules_python~0.21.0~pip~pip_yapf//:pkg"]
    
    all_whl_requirements = ["@rules_python~0.21.0~pip~pip_yapf//:whl"]
    ```
    
    Starting Bazel 6, canonical names should be referred with double "@".
    
    The reason why `incompatible_generate_aliases = True` worked is because
    it uses apparent name by parsing the canonical label with `repo_name =
    rctx.attr.name.split("~")[-1]`. This is dangerous because Bazel may
    change its canonical name pattern in future versions.
    
    This PR adds a new attribute "repo_name" to `pip_repository_bzlmod`, so
    we have access to the human-readable name in the implementation.
    linzhp authored May 17, 2023
    Copy the full SHA
    1383bd4 View commit details

Commits on May 18, 2023

  1. feat(bzlmod): support entry_point macro (#1220)

    Add `entry_point` macro to the repo generated by the `pip.parse`
    extension.
    This works by using the canonical label literal, so should work without
    users
    needing to add the spoke repos to the `use_repo` statement. We test this
    by
    having an extra folder in the `bzlmod` example.
    
    Fixes #958.
    aignas authored May 18, 2023
    Copy the full SHA
    693a158 View commit details
Showing with 3,030 additions and 247 deletions.
  1. +80 −26 .bazelci/presubmit.yml
  2. +8 −0 .bazelignore
  3. +2 −2 .bazelrc
  4. +0 −1 BUILD.bazel
  5. +37 −0 BZLMOD_SUPPORT.md
  6. +13 −6 DEVELOPING.md
  7. +4 −1 MODULE.bazel
  8. +10 −3 README.md
  9. +4 −12 docs/BUILD.bazel
  10. +8 −6 docs/pip_repository.md
  11. +5 −0 examples/BUILD.bazel
  12. +1 −1 examples/build_file_generation/.bazelrc
  13. +0 −43 examples/build_file_generation/MODULE.bazel
  14. +3 −1 examples/build_file_generation/README.md
  15. +0 −2 examples/build_file_generation/WORKSPACE.bzlmod
  16. +1 −1 examples/build_file_generation/gazelle_python.yaml
  17. +1 −1 examples/build_file_generation/requirements_lock.txt
  18. +1 −1 examples/build_file_generation/requirements_windows.txt
  19. +13 −1 examples/bzlmod/BUILD.bazel
  20. +13 −2 examples/bzlmod/MODULE.bazel
  21. +20 −0 examples/bzlmod/entry_point/BUILD.bazel
  22. +43 −0 examples/bzlmod/entry_point/test_entry_point.py
  23. +590 −0 examples/bzlmod/gazelle_python.yaml
  24. +6 −6 examples/bzlmod/requirements_lock.txt
  25. +6 −6 examples/bzlmod/requirements_windows.txt
  26. +1 −0 examples/bzlmod/runfiles/BUILD.bazel
  27. +45 −0 examples/bzlmod/test.py
  28. +1 −0 examples/bzlmod_build_file_generation/.bazelignore
  29. +9 −0 examples/bzlmod_build_file_generation/.bazelrc
  30. +1 −0 examples/bzlmod_build_file_generation/.bazelversion
  31. +1 −0 examples/bzlmod_build_file_generation/.gitignore
  32. +103 −0 examples/bzlmod_build_file_generation/BUILD.bazel
  33. +119 −0 examples/bzlmod_build_file_generation/MODULE.bazel
  34. +28 −0 examples/bzlmod_build_file_generation/README.md
  35. +2 −0 examples/bzlmod_build_file_generation/WORKSPACE
  36. +18 −0 examples/bzlmod_build_file_generation/__main__.py
  37. +33 −0 examples/bzlmod_build_file_generation/__test__.py
  38. +590 −0 examples/bzlmod_build_file_generation/gazelle_python.yaml
  39. +19 −0 examples/bzlmod_build_file_generation/lib.py
  40. +5 −0 examples/bzlmod_build_file_generation/other_module/MODULE.bazel
  41. 0 examples/bzlmod_build_file_generation/other_module/WORKSPACE
  42. +11 −0 examples/bzlmod_build_file_generation/other_module/other_module/pkg/BUILD.bazel
  43. +1 −0 examples/bzlmod_build_file_generation/other_module/other_module/pkg/data/data.txt
  44. +27 −0 examples/bzlmod_build_file_generation/other_module/other_module/pkg/lib.py
  45. +6 −0 examples/bzlmod_build_file_generation/requirements.in
  46. +227 −0 examples/bzlmod_build_file_generation/requirements_lock.txt
  47. +231 −0 examples/bzlmod_build_file_generation/requirements_windows.txt
  48. +19 −0 examples/bzlmod_build_file_generation/runfiles/BUILD.bazel
  49. +1 −0 examples/bzlmod_build_file_generation/runfiles/data/data.txt
  50. +64 −0 examples/bzlmod_build_file_generation/runfiles/runfiles_test.py
  51. +4 −4 examples/pip_install/requirements.txt
  52. +3 −3 examples/pip_install/requirements_windows.txt
  53. +3 −3 examples/pip_parse/requirements_lock.txt
  54. +1 −1 examples/pip_parse_vendored/requirements.txt
  55. +2 −2 examples/pip_repository_annotations/requirements.txt
  56. +1 −1 examples/py_proto_library/MODULE.bazel
  57. +38 −7 gazelle/README.md
  58. +6 −3 internal_deps.bzl
  59. +23 −0 python/extensions/BUILD.bazel
  60. +75 −0 python/extensions/interpreter.bzl
  61. +6 −50 python/{extensions.bzl → extensions/pip.bzl}
  62. +23 −0 python/extensions/private/BUILD.bazel
  63. +25 −0 python/extensions/private/internal_deps.bzl
  64. +58 −0 python/extensions/private/interpreter_hub.bzl
  65. +64 −0 python/extensions/python.bzl
  66. +1 −0 python/packaging.bzl
  67. +20 −6 python/pip_install/pip_repository.bzl
  68. +11 −4 python/pip_install/pip_repository_requirements_bzlmod.bzl.tmpl
  69. +11 −3 python/pip_install/private/test/requirements_parser_tests.bzl
  70. +2 −1 python/pip_install/requirements.bzl
  71. +2 −2 python/pip_install/requirements_parser.bzl
  72. +50 −13 python/pip_install/tools/dependency_resolver/dependency_resolver.py
  73. +5 −1 python/private/BUILD.bazel
  74. +18 −1 python/private/util.bzl
  75. +11 −5 python/repositories.bzl
  76. +12 −0 python/tests/toolchains/workspace_template/WORKSPACE.tmpl
  77. +11 −0 python/versions.bzl
  78. +2 −2 tests/compile_pip_requirements/requirements_lock.txt
  79. +1 −0 tests/compile_pip_requirements_test_from_external_workspace/.bazelrc
  80. +1 −0 tests/compile_pip_requirements_test_from_external_workspace/.gitignore
  81. 0 tests/compile_pip_requirements_test_from_external_workspace/BUILD.bazel
  82. +3 −0 tests/compile_pip_requirements_test_from_external_workspace/README.md
  83. +36 −0 tests/compile_pip_requirements_test_from_external_workspace/WORKSPACE
  84. +15 −0 tests/ignore_root_user_error/WORKSPACE
  85. +3 −3 tests/pip_repository_entry_points/requirements.txt
  86. +3 −3 tests/pip_repository_entry_points/requirements_windows.txt
  87. +1 −0 tools/bazel_integration_test/test_runner.py
  88. +16 −2 tools/bazel_integration_test/update_deleted_packages.sh
  89. +22 −1 tools/build_defs/python/tests/base_tests.bzl
  90. +10 −4 tools/build_defs/python/tests/py_test/py_test_tests.bzl
106 changes: 80 additions & 26 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -48,6 +48,8 @@ buildifier:
test_targets: ["..."]
.coverage_targets_example_bzlmod: &coverage_targets_example_bzlmod
coverage_targets: ["//:test"]
.coverage_targets_example_bzlmod_build_file_generation: &coverage_targets_example_bzlmod_build_file_generation
coverage_targets: ["//:bzlmod_build_file_generation_test"]
.coverage_targets_example_multi_python: &coverage_targets_example_multi_python
coverage_targets:
- //tests:my_lib_3_10_test
@@ -147,32 +149,6 @@ tasks:
working_directory: examples/build_file_generation
platform: windows

integration_test_build_file_generation_bzlmod_ubuntu:
<<: *minimum_supported_bzlmod_version
<<: *common_bzlmod_flags
<<: *reusable_build_test_all
name: build_file_generation_bzlmod integration tests on Ubuntu
working_directory: examples/build_file_generation
platform: ubuntu2004
integration_test_build_file_generation_bzlmod_debian:
<<: *common_bzlmod_flags
<<: *reusable_build_test_all
name: build_file_generation_bzlmod integration tests on Debian
working_directory: examples/build_file_generation
platform: debian11
integration_test_build_file_generation_bzlmod_macos:
<<: *common_bzlmod_flags
<<: *reusable_build_test_all
name: build_file_generation_bzlmod integration tests on macOS
working_directory: examples/build_file_generation
platform: macos
integration_test_build_file_generation_bzlmod_windows:
<<: *common_bzlmod_flags
<<: *reusable_build_test_all
name: build_file_generation_bzlmod integration tests on Windows
working_directory: examples/build_file_generation
platform: windows

integration_test_bzlmod_ubuntu_min:
<<: *minimum_supported_bzlmod_version
<<: *reusable_build_test_all
@@ -205,6 +181,46 @@ tasks:
working_directory: examples/bzlmod
platform: windows

integration_test_bzlmod_generate_build_file_generation_ubuntu_min:
<<: *minimum_supported_bzlmod_version
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file min bazel version integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
integration_test_bzlmod_generation_build_files_ubuntu:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
integration_test_bzlmod_generation_build_files_ubuntu_run:
<<: *reusable_build_test_all
name: example bzlmod build file running gazelle and pip integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
shell_commands:
- "bazel run //:gazelle_python_manifest.update"
- "bazel run //:gazelle -- update"
integration_test_bzlmod_build_file_generation_debian:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: debian11
integration_test_bzlmod_build_file_generation_macos:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: macos
integration_test_bzlmod_build_file_generation_windows:
<<: *reusable_build_test_all
# coverage is not supported on Windows
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: windows

integration_test_multi_python_versions_ubuntu_min:
<<: *minimum_supported_version
<<: *reusable_build_test_all
@@ -509,3 +525,41 @@ tasks:
name: ignore_root_user_error integration tests on Windows
working_directory: tests/ignore_root_user_error
platform: windows

integration_compile_pip_requirements_test_from_external_repo_ubuntu_min:
<<: *minimum_supported_version
name: compile_pip_requirements test from external repo on Ubuntu using minimum supported Bazel version
working_directory: tests/compile_pip_requirements_test_from_external_workspace
platform: ubuntu2004
shell_commands:
# Assert that @external_repository//:requirements_test does the right thing.
- "bazel test @external_repository//..."
integration_compile_pip_requirements_test_from_external_repo_ubuntu:
name: compile_pip_requirements test from external repo on Ubuntu
working_directory: tests/compile_pip_requirements_test_from_external_workspace
platform: ubuntu2004
shell_commands:
# Assert that @external_repository//:requirements_test does the right thing.
- "bazel test @external_repository//..."
integration_compile_pip_requirements_test_from_external_repo_debian:
name: compile_pip_requirements test from external repo on Debian
working_directory: tests/compile_pip_requirements_test_from_external_workspace
platform: debian11
shell_commands:
# Assert that @external_repository//:requirements_test does the right thing.
- "bazel test @external_repository//..."
integration_compile_pip_requirements_test_from_external_repo_macos:
name: compile_pip_requirements test from external repo on macOS
working_directory: tests/compile_pip_requirements_test_from_external_workspace
platform: macos
shell_commands:
# Assert that @external_repository//:requirements_test does the right thing.
- "bazel test @external_repository//..."
integration_compile_pip_requirements_test_from_external_repo_windows:
name: compile_pip_requirements test from external repo on Windows
working_directory: tests/compile_pip_requirements_test_from_external_workspace
platform: windows
shell_commands:
# Assert that @external_repository//:requirements_test does the right thing.
- "bazel test @external_repository//..."

8 changes: 8 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Normally these are ignored, but if you're using a custom
# build of Bazel with a custom --output_user_root value, Bazel
# tries to follow the symlinks of the other builds and finds
# the WORKSPACE, BUILD, etc files and tries to build them.
bazel-rules_python
bazel-bin
bazel-out
bazel-testlogs
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
# This lets us glob() up all the files inside the examples to make them inputs to tests
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, run tools/bazel_integration_test/update_deleted_packages.sh
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_point,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,tests/compile_pip_requirements,tests/compile_pip_requirements_test_from_external_workspace,tests/ignore_root_user_error,tests/pip_repository_entry_points
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_point,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,tests/compile_pip_requirements,tests/compile_pip_requirements_test_from_external_workspace,tests/ignore_root_user_error,tests/pip_repository_entry_points

test --test_output=errors

1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ filegroup(
"//python/pip_install:bzl",
"//python:bzl",
# Requires Bazel 0.29 onward for public visibility of these .bzl files.
"@bazel_tools//tools/python:private/defs.bzl",
"@bazel_tools//tools/python:python_version.bzl",
"@bazel_tools//tools/python:srcs_version.bzl",
"@bazel_tools//tools/python:toolchain.bzl",
37 changes: 37 additions & 0 deletions BZLMOD_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Bzlmod support

## `rule_python` `bzlmod` support

- Status: Beta
- Full Feature Parity: No

Some features are missing or broken, and the public APIs are not yet stable.

## Configuration

The releases page will give you the latest version number, and a basic example. The release page is located [here](/bazelbuild/rules_python/releases).

## What is bzlmod?

> Bazel supports external dependencies, source files (both text and binary) used in your build that are not from your workspace. For example, they could be a ruleset hosted in a GitHub repo, a Maven artifact, or a directory on your local machine outside your current workspace.
>
> As of Bazel 6.0, there are two ways to manage external dependencies with Bazel: the traditional, repository-focused WORKSPACE system, and the newer module-focused MODULE.bazel system (codenamed Bzlmod, and enabled with the flag `--enable_bzlmod`). The two systems can be used together, but Bzlmod is replacing the WORKSPACE system in future Bazel releases.
> -- <cite>https://bazel.build/external/overview</cite>
## Examples

We have two examples that demonstrate how to configure `bzlmod`.

The first example is in [examples/bzlmod](examples/bzlmod), and it demonstrates basic bzlmod configuration.
A user does not use `local_path_override` stanza and would define the version in the `bazel_dep` line.

A second example, in [examples/bzlmod_build_file_generation](examples/bzlmod_build_file_generation) demonstrates the use of `bzlmod` to configure `gazelle` support for `rules_python`.

## Feature parity

This rule set does not have full feature partity with the older `WORKSPACE` type configuration:

1. Multiple python versions are not yet supported, as demonstrated in [this](examples/multi_python_versions) example.
2. Gazelle does not support finding deps in sub-modules. For instance we can have a dep like ` "@our_other_module//other_module/pkg:lib",` in a `py_test` definition.

Check ["issues"](/bazelbuild/rules_python/issues) for an up to date list.
19 changes: 13 additions & 6 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -7,17 +7,24 @@ Start from a clean checkout at `main`.
Before running through the release it's good to run the build and the tests locally, and make sure CI is passing. You can
also test-drive the commit in an existing Bazel workspace to sanity check functionality.

#### Steps
1. [Determine the next semantic version number](#determining-semantic-version)
1. Create a tag and push, e.g. `git tag 0.5.0 upstream/main && git push upstream --tags`
NOTE: Pushing the tag will trigger release automation.
1. Watch the release automation run on https://github.com/bazelbuild/rules_python/actions
1. Add missing information to the release notes. The automatic release note
generation only includes commits associated with issues.

#### Determining Semantic Version

**rules_python** is currently using [Zero-based versioning](https://0ver.org/) and thus backwards-incompatible API
changes still come under the minor-version digit. So releases with API changes and new features bump the minor, and
those with only bug fixes and other minor changes bump the patch digit.
those with only bug fixes and other minor changes bump the patch digit.

To find if there were any features added or incompatible changes made, review
the commit history. This can be done using github by going to the url:
`https://github.com/bazelbuild/rules_python/compare/<VERSION>...main`.

#### Steps
1. Determine what will be the next release, following semver.
1. Create a tag and push, e.g. `git tag 0.5.0 upstream/main && git push upstream --tags`
1. Watch the release automation run on https://github.com/bazelbuild/rules_python/actions

#### After release creation in Github

1. Ping @philwo to get the new release added to mirror.bazel.build. See [this comment on issue #400](https://github.com/bazelbuild/rules_python/issues/400#issuecomment-779159530) for more context.
5 changes: 4 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")

internal_deps = use_extension("@rules_python//python:extensions.bzl", "internal_deps")
internal_deps = use_extension("@rules_python//python/extensions/private:internal_deps.bzl", "internal_deps")
internal_deps.install()
use_repo(
internal_deps,
@@ -46,3 +46,6 @@ use_repo(
"pypi__coverage_cp39_x86_64-apple-darwin",
"pypi__coverage_cp39_x86_64-unknown-linux-gnu",
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
use_repo(python, "pythons_hub")
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,13 @@ Bazel team, provides support for the code. However, this repository is part of
the test suite used to vet new Bazel releases. See the [How to
contribute](CONTRIBUTING.md) page for information on our development workflow.

## `bzlmod` support

- Status: Beta
- Full Feature Parity: No

See [Bzlmod support](BZLMOD_SUPPORT.md) for more details.

## Getting started

The next two sections cover using `rules_python` with bzlmod and
@@ -39,12 +46,12 @@ the older way of configuring bazel with a `WORKSPACE` file.
### Using bzlmod

To import rules_python in your project, you first need to add it to your
`MODULES.bazel` file, using the snippet provided in the
`MODULE.bazel` file, using the snippet provided in the
[release you choose](https://github.com/bazelbuild/rules_python/releases).

#### Toolchain registration with bzlmod

To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runtime execution, you can add to the `MODULES.bazel` file:
To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runtime execution, you can add to the `MODULE.bazel` file:

```python
# Find the latest version number here: https://github.com/bazelbuild/rules_python/releases
@@ -161,7 +168,7 @@ target in the appropriate wheel repo.

#### Using bzlmod

To add pip dependencies to your `MODULES.bazel` file, use the `pip.parse` extension, and call it to create the
To add pip dependencies to your `MODULE.bazel` file, use the `pip.parse` extension, and call it to create the
central external repo and individual wheel external repos.

```python
16 changes: 4 additions & 12 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -32,17 +32,6 @@ _DOCS = {
# because they're only used for doc generation. This way, we avoid requiring
# our users to depend on Skylib.

# Requires Bazel 0.29 onward for public visibility of these .bzl files.
bzl_library(
name = "bazel_python_tools",
srcs = [
"@bazel_tools//tools/python:private/defs.bzl",
"@bazel_tools//tools/python:srcs_version.bzl",
"@bazel_tools//tools/python:toolchain.bzl",
"@bazel_tools//tools/python:utils.bzl",
],
)

bzl_library(
name = "bazel_repo_tools",
srcs = [
@@ -57,7 +46,7 @@ bzl_library(
"//python/private:reexports.bzl",
],
deps = [
":bazel_python_tools",
":bazel_repo_tools",
"//python:defs_bzl",
"//python/private:reexports_bzl",
],
@@ -91,6 +80,9 @@ bzl_library(
"//python/private:stamp.bzl",
"//python/private:util.bzl",
],
deps = [
"//python/private:util_bzl",
],
)

# TODO: Stardoc does not guarantee consistent outputs accross platforms (Unix/Windows).
Loading