-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(toolchain): use a helper method to convert an X.Y version to…
… X.Y.Z Before this PR in numerous places we would check the MINOR_MAPPING dict. This PR adds a function that also fails if the X.Y format is not in the MINOR_MAPPING dict making the code more robust. Split from #1340 to unblock #1364.
- Loading branch information
Showing
4 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2022 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A small helper to ensure that we are working with full versions.""" | ||
|
||
load("//python:versions.bzl", "MINOR_MAPPING") | ||
|
||
def full_version(version): | ||
"""Return a full version. | ||
Args: | ||
version: the version in `X.Y` or `X.Y.Z` format. | ||
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] | ||
|
||
parts = version.split(".") | ||
if len(parts) == 3: | ||
return version | ||
elif len(parts) == 2: | ||
fail( | ||
"Unknown Python version '{}', available values are: {}".format( | ||
version, | ||
",".join(MINOR_MAPPING.keys()), | ||
), | ||
) | ||
else: | ||
fail("Unknown version format: {}".format(version)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters