Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bzlmod): python.override for toolchain customization #2151

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
2e51b61
refactor: define internal vars for each tag class
aignas Aug 8, 2024
e7e2cbe
refactor: rename some classes and thread the available tool versions
aignas Aug 8, 2024
330008a
spike the override tag classes
aignas Aug 8, 2024
2d8642c
add base_url override as well
aignas Aug 8, 2024
12d8ec6
refactor: move the register_all_versions to python.override
aignas Aug 9, 2024
5ec8acd
wip
aignas Aug 13, 2024
35492e4
Add an example on how to override the URLs
aignas Aug 23, 2024
4b5da0e
add a doc
aignas Aug 23, 2024
c765d11
minor refactoring in processing the tag classes
aignas Aug 23, 2024
46af7f9
version_override -> single_version_override
aignas Aug 26, 2024
0a88a6e
improve docs - add repositories.bzl docs and improve docs for bzlmod
aignas Aug 26, 2024
b0e2f13
clarify docs
aignas Aug 26, 2024
dd70a04
cleanup the override impl
aignas Aug 27, 2024
53105dc
make patch_strip handling identical to strip_prefix
aignas Aug 27, 2024
30e922d
add docs
aignas Aug 27, 2024
1f28f07
add some thoughts
aignas Aug 28, 2024
82ae48f
refactor a little
aignas Aug 28, 2024
2a30710
ensure that only the root module can do overrides
aignas Aug 30, 2024
260d458
chore: move full_version usage to the extension
aignas Aug 30, 2024
eba99bd
allow overriding the minor_mapping used to register the toolchains
aignas Aug 30, 2024
dc039be
reduce the API a bit
aignas Aug 30, 2024
f2433f9
correctly set the overrides
aignas Aug 30, 2024
c262084
allow overriding just about everything
aignas Aug 30, 2024
de1f69d
wip
aignas Aug 30, 2024
1cddfe9
docs
aignas Aug 30, 2024
f4ac7c2
docs
aignas Aug 30, 2024
d0493ec
docs
aignas Aug 30, 2024
0508e2b
docs
aignas Aug 30, 2024
7379373
docs
aignas Aug 30, 2024
42c3f23
docs
aignas Aug 30, 2024
9553168
Merge branch 'main' into python-override
aignas Aug 31, 2024
e3bb92d
fix docs
aignas Aug 31, 2024
915a6ff
spike a unit test
aignas Sep 1, 2024
cd5b101
move the ignore_root_user_error to a different place
aignas Sep 1, 2024
3655ab0
move coverage registration tool so that we can reuse structs
aignas Sep 1, 2024
3ff9618
remove a duplicated var
aignas Sep 1, 2024
7beb84a
remove the default_toolchain from the struct
aignas Sep 1, 2024
933e6f8
make global_toolchain_versions an implementation detail
aignas Sep 1, 2024
ad6edba
refactor tests and ensure we have an ordering test
aignas Sep 1, 2024
3a459c8
refactor: expose from the module processing function only the bare mi…
aignas Sep 1, 2024
760d0eb
add a test to check what happens if multiple toolchain calls are made
aignas Sep 1, 2024
fab7a23
add todo notes
aignas Sep 1, 2024
061b760
remove todo
aignas Sep 1, 2024
c32b259
docs: attempt to add `module_ctx` inventory
aignas Sep 1, 2024
671d0d9
wip
aignas Sep 1, 2024
5e5b8f6
Allow overriding ignore_root_user_error via override API
aignas Sep 2, 2024
e17f208
test: add more override tests
aignas Sep 2, 2024
75314e5
refactor: dryer tests
aignas Sep 2, 2024
7a173e4
refactor: dryer tests
aignas Sep 2, 2024
43e0168
test that we can set patches
aignas Sep 2, 2024
a12751c
add a test for single version platform override
aignas Sep 2, 2024
a04d245
Merge branch 'main' into python-override
aignas Sep 2, 2024
4e2bb3e
docs
aignas Sep 2, 2024
f60febd
ensure that the new python version can be also added with a different…
aignas Sep 2, 2024
0a40f88
add a reference to a ticket
aignas Sep 2, 2024
83d2c64
fix the examples/bzlmod
aignas Sep 2, 2024
bd06e6d
improve example docs
aignas Sep 2, 2024
88a1d5e
cleanup
aignas Sep 2, 2024
581191d
remove TODOs
aignas Sep 3, 2024
c8b0833
refactor: add a semver function to consolidate code
aignas Sep 3, 2024
0aac200
improve the docs
aignas Sep 3, 2024
246febe
update the lock file
aignas Sep 3, 2024
cd3f844
Merge branch 'main' into python-override
aignas Sep 3, 2024
266e9ab
add path to inventory
aignas Sep 3, 2024
09b9cd6
fix integration tests
aignas Sep 4, 2024
93684eb
register_all_versions fix and fixup tests
aignas Sep 4, 2024
2f89234
improve the docs
aignas Sep 4, 2024
6cfd483
fixup tests
aignas Sep 5, 2024
cf96d55
Merge branch 'main' into python-override
aignas Sep 6, 2024
def721a
fix merge conflicts
aignas Sep 6, 2024
80a81aa
more cleanup
aignas Sep 6, 2024
8ad05af
infer MINOR_MAPPING automatically when registering toolchains
aignas Sep 6, 2024
f8d143f
chore: bazel mod deps --lockfile_mode=update
aignas Sep 6, 2024
f844962
fix a case when the first module in mctx.modules is not a root module
aignas Sep 6, 2024
f70676c
further cleanup
aignas Sep 6, 2024
d844c01
cleanup
aignas Sep 6, 2024
f0209a2
cleanup
aignas Sep 6, 2024
293685e
fixup
aignas Sep 6, 2024
dc07b3e
simplify
aignas Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,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_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,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_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered

test --test_output=errors

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ A brief description of the categories of changes:
* (gazelle): Update error messages when unable to resolve a dependency to be more human-friendly.
* (flags) The {obj}`--python_version` flag now also returns
{obj}`config_common.FeatureFlagInfo`.
* (toolchain): The toolchain patches now expose the `patch_strip` attribute
that one should use when patching toolchains. Please set it if you are
patching python interpreter. In the next release the default will be set to
`0` which better reflects the defaults used in public `bazel` APIs.

### Fixed
* (whl_library): Remove `--no-index` and add `--no-build-isolation` to the
Expand All @@ -51,6 +55,10 @@ A brief description of the categories of changes:


### Added
* (bzlmod): Toolchain overrides can now be done using the new
{bzl:obj}`python.override`, {bzl:obj}`python.single_version_override` and
{bzl:obj}`python.single_version_platform_override` tag classes.
See [#2081](https://github.com/bazelbuild/rules_python/issues/2081).
* (rules) Executables provide {obj}`PyExecutableInfo`, which contains
executable-specific information useful for packaging an executable or
or deriving a new one from the original.
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dev_python = use_extension(
"python",
dev_dependency = True,
)
dev_python.rules_python_private_testing(
dev_python.override(
register_all_versions = True,
)

Expand Down
13 changes: 12 additions & 1 deletion docs/toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ Remember to call `use_repo()` to make repos visible to your module:
Python toolchains can be utilized in other bazel rules, such as `genrule()`, by adding the `toolchains=["@rules_python//python:current_py_toolchain"]` attribute. You can obtain the path to the Python interpreter using the `$(PYTHON2)` and `$(PYTHON3)` ["Make" Variables](https://bazel.build/reference/be/make-variables). See the
{gh-path}`test_current_py_toolchain <tests/load_from_macro/BUILD.bazel>` target for an example.

### Overriding toolchain defaults and adding more toolchains

One can perform various overrides for the registered toolchains from the root module. For example, the following usecases would be supported using the existing attributes:

* Limiting the available toolchains for the entire `bzlmod` transitive graph
via {attr}`python.override.available_python_versions`.
* Setting particular `X.Y.Z` python versions when modules request `X.Y` version
via {attr}`python.override.minor_mapping`.
* Adding custom {attr}`python.single_version_platform_override.coverage_tool`.
* Adding new python versions via {bzl:obj}`python.single_version_override` or
{bzl:obj}`python.single_version_platform_override`.

## Workspace configuration

Expand Down Expand Up @@ -240,5 +251,5 @@ automatically registers a higher-priority toolchain; it won't be used unless
there is a toolchain misconfiguration somewhere.

To aid migration off the Bazel-builtin toolchain, rules_python provides
{obj}`@rules_python//python/runtime_env_toolchains:all`. This is an equivalent
{bzl:obj}`@rules_python//python/runtime_env_toolchains:all`. This is an equivalent
toolchain, but is implemented using rules_python's objects.
50 changes: 49 additions & 1 deletion examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bazel_dep(name = "protobuf", version = "24.4", repo_name = "com_google_protobuf"
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
configure_coverage_tool = True,
# Only set when you have mulitple toolchain versions.
# Only set when you have multiple toolchain versions.
is_default = True,
python_version = "3.9",
)
Expand All @@ -37,6 +37,54 @@ python.toolchain(
python_version = "3.10",
)

# One can override the actual toolchain versions that are available, which can be useful
# to when optimizing what gets downloaded and when.
python.override(
available_python_versions = [
"3.10.9",
"3.9.19",
# The following is used by the `other_module` and we need to include it here
# as well.
"3.11.8",
],
# Also override the `minor_mapping` so that when the modules specify a particular
# `3.X` version, we decide what gets used.
minor_mapping = {
"3.10": "3.10.9",
"3.11": "3.11.8",
"3.9": "3.9.19",
},
)

# Or the sources that the toolchains come from for all platforms
python.single_version_override(
patch_strip = 1,
# The user can specify patches to be applied to all interpreters.
patches = [],
python_version = "3.10.2",
sha256 = {
"aarch64-apple-darwin": "1409acd9a506e2d1d3b65c1488db4e40d8f19d09a7df099667c87a506f71c0ef",
"aarch64-unknown-linux-gnu": "8f351a8cc348bb45c0f95b8634c8345ec6e749e483384188ad865b7428342703",
"x86_64-apple-darwin": "8146ad4390710ec69b316a5649912df0247d35f4a42e2aa9615bffd87b3e235a",
"x86_64-pc-windows-msvc": "a1d9a594cd3103baa24937ad9150c1a389544b4350e859200b3e5c036ac352bd",
"x86_64-unknown-linux-gnu": "9b64eca2a94f7aff9409ad70bdaa7fbbf8148692662e764401883957943620dd",
},
urls = ["20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz"],
)

# Or a single platform. This can be used in combination with the
# `single_version_override` and `single_version_platform_override` will be
# applied after `single_version_override`. Any values present in this override
# will overwrite the values set by the `single_version_override`
python.single_version_platform_override(
patch_strip = 1,
patches = [],
platform = "aarch64-apple-darwin",
python_version = "3.10.2",
sha256 = "1409acd9a506e2d1d3b65c1488db4e40d8f19d09a7df099667c87a506f71c0ef",
urls = ["20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz"],
)

# You only need to load this repositories if you are using multiple Python versions.
# See the tests folder for various examples on using multiple Python versions.
# The names "python_3_9" and "python_3_10" are autmatically created by the repo
Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion python/extensions/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"Python toolchain module extensions for use with bzlmod"
"""Python toolchain module extensions for use with bzlmod.

## Basic usage

The simplest way to configure the toolchain with `rules_python` is as follows.

```starlark
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = "3.11",
)
use_repo(python, "python_3_11")
```

For more in-depth documentation see the {rule}`python.toolchain`.

## Overrides

Overrides can be done at 3 different levels:
* Overrides affecting all python toolchain versions on all platforms - {obj}`python.override`.
* Overrides affecting a single toolchain versions on all platforms - {obj}`python.single_version_override`.
* Overrides affecting a single toolchain versions on a single platforms - {obj}`python.single_version_platform_override`.

:::{seealso}
The main documentation page on registering [toolchains](/toolchains).
:::
"""

load("//python/private:python.bzl", _python = "python")

Expand Down
11 changes: 9 additions & 2 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ bzl_library(
name = "python_bzl",
srcs = ["python.bzl"],
deps = [
":full_version_bzl",
":python_repositories_bzl",
":pythons_hub_bzl",
":repo_utils_bzl",
":semver_bzl",
":toolchains_repo_bzl",
":util_bzl",
"//python:repositories_bzl",
"@bazel_features//:features",
],
)
Expand All @@ -161,7 +163,6 @@ bzl_library(
name = "pythons_hub_bzl",
srcs = ["pythons_hub.bzl"],
deps = [
":full_version_bzl",
":py_toolchain_suite_bzl",
"//python:versions_bzl",
],
Expand Down Expand Up @@ -294,6 +295,12 @@ bzl_library(
srcs = ["repo_utils.bzl"],
)

bzl_library(
name = "semver_bzl",
srcs = ["semver.bzl"],
visibility = ["//:__subpackages__"],
)

bzl_library(
name = "stamp_bzl",
srcs = ["stamp.bzl"],
Expand Down
8 changes: 4 additions & 4 deletions python/private/common/py_runtime_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ See @bazel_tools//tools/python:python_bootstrap_template.txt for more variables.
"coverage_tool": attr.label(
allow_files = False,
doc = """
This is a target to use for collecting code coverage information from `py_binary`
and `py_test` targets.
This is a target to use for collecting code coverage information from
{rule}`py_binary` and {rule}`py_test` targets.

If set, the target must either produce a single file or be an executable target.
The path to the single file, or the executable if the target is executable,
Expand All @@ -214,7 +214,7 @@ runfiles will be added to the runfiles when coverage is enabled.

The entry point for the tool must be loadable by a Python interpreter (e.g. a
`.py` or `.pyc` file). It must accept the command line arguments
of coverage.py (https://coverage.readthedocs.io), at least including
of [`coverage.py`](https://coverage.readthedocs.io), at least including
the `run` and `lcov` subcommands.
""",
),
Expand Down Expand Up @@ -306,7 +306,7 @@ The template to use when two stage bootstrapping is enabled
default = DEFAULT_STUB_SHEBANG,
doc = """
"Shebang" expression prepended to the bootstrapping Python stub script
used when executing `py_binary` targets.
used when executing {rule}`py_binary` targets.

See https://github.com/bazelbuild/bazel/issues/8685 for
motivation.
Expand Down
9 changes: 5 additions & 4 deletions python/private/full_version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

load("//python:versions.bzl", "MINOR_MAPPING")

def full_version(version):
def full_version(version, minor_mapping = MINOR_MAPPING):
"""Return a full version.

Args:
version: the version in `X.Y` or `X.Y.Z` format.
minor_mapping: the mapping from `X.Y` to `X.Y.Z`.

Returns:
a full version given the version string. If the string is already a
major version then we return it as is.
"""
if version in MINOR_MAPPING:
return MINOR_MAPPING[version]
if version in minor_mapping:
return minor_mapping[version]

parts = version.split(".")
if len(parts) == 3:
Expand All @@ -36,7 +37,7 @@ def full_version(version):
fail(
"Unknown Python version '{}', available values are: {}".format(
version,
",".join(MINOR_MAPPING.keys()),
",".join(minor_mapping.keys()),
),
)
else:
Expand Down
1 change: 1 addition & 0 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bzl_library(
"//python/private:full_version_bzl",
"//python/private:normalize_name_bzl",
"//python/private:version_label_bzl",
"//python/private:semver_bzl",
"@bazel_features//:features",
] + [
"@pythons_hub//:interpreters_bzl",
Expand Down
17 changes: 2 additions & 15 deletions python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ load("@pythons_hub//:interpreters.bzl", "DEFAULT_PYTHON_VERSION", "INTERPRETER_L
load("//python/private:auth.bzl", "AUTH_ATTRS")
load("//python/private:normalize_name.bzl", "normalize_name")
load("//python/private:repo_utils.bzl", "repo_utils")
load("//python/private:semver.bzl", "semver")
load("//python/private:version_label.bzl", "version_label")
load(":attrs.bzl", "use_isolated")
load(":evaluate_markers.bzl", "evaluate_markers", EVALUATE_MARKERS_SRCS = "SRCS")
Expand All @@ -32,22 +33,8 @@ load(":simpleapi_download.bzl", "simpleapi_download")
load(":whl_library.bzl", "whl_library")
load(":whl_repo_name.bzl", "whl_repo_name")

def _parse_version(version):
major, _, version = version.partition(".")
minor, _, version = version.partition(".")
patch, _, version = version.partition(".")
build, _, version = version.partition(".")

return struct(
# use semver vocabulary here
major = major,
minor = minor,
patch = patch, # this is called `micro` in the Python interpreter versioning scheme
build = build,
)

def _major_minor_version(version):
version = _parse_version(version)
version = semver(version)
return "{}.{}".format(version.major, version.minor)

def _whl_mods_impl(mctx):
Expand Down
Loading