-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is to better support nightly builds, with custom version strings such as `0.1.0-dev20250305`. e.g. ``` bazel run --//jax_tpu_embedding/sparsecore:version_suffix=dev$(date '+%Y%m%d') //build:build_pip_package --repo_env=HERMETIC_PYTHON_VERSION=3.12 -- $PWD ``` PiperOrigin-RevId: 733765952
- Loading branch information
1 parent
29c0160
commit 7aa32d2
Showing
6 changed files
with
171 additions
and
5 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,81 @@ | ||
# Copyright 2024 The JAX SC Authors. | ||
# | ||
# 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. | ||
"""Generate a file using a template.""" | ||
|
||
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") | ||
|
||
def _get_flag_substitutions(flag_substitutions): | ||
"""Extracts flag values.""" | ||
substitutions = {} | ||
for key, label in flag_substitutions.items(): | ||
substitutions[key] = label[BuildSettingInfo].value | ||
return substitutions | ||
|
||
def _create_substitution_map(string_substitutions): | ||
"""Replaces {key: value} with {${key}: value}""" | ||
substitutions = {} | ||
for key, value in string_substitutions.items(): | ||
key_var = "${" + key + "}" | ||
substitutions[key_var] = value | ||
return substitutions | ||
|
||
def configure_file( | ||
name, | ||
template, | ||
output, | ||
substitutions = {}, | ||
flag_substitutions = {}): | ||
"""Generates a file using a template. | ||
For every entry in the substitutions maps, replaces `${variable}` with `value`. | ||
Args: | ||
name: The name of the rule. | ||
template: The template file in which to perform the substitutions. | ||
output: The output file. | ||
substitutions: A map of string substitutions {variable: value}. | ||
flag_substitutions: A map of variable to bazel string_flag substitutions. \ | ||
Replacement values are extracted from the flag. | ||
Returns: | ||
A rule that generates the output file. | ||
""" | ||
_configure_file( | ||
name = name, | ||
template = template, | ||
output = output, | ||
substitutions = substitutions, | ||
flag_substitutions = flag_substitutions, | ||
) | ||
|
||
def _configure_file_impl(ctx): | ||
substitutions = _create_substitution_map(ctx.attr.substitutions | _get_flag_substitutions(ctx.attr.flag_substitutions)) | ||
ctx.actions.expand_template( | ||
template = ctx.file.template, | ||
output = ctx.outputs.output, | ||
substitutions = substitutions, | ||
) | ||
|
||
_configure_file = rule( | ||
implementation = _configure_file_impl, | ||
attrs = { | ||
"template": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, | ||
), | ||
"substitutions": attr.string_dict(), | ||
"flag_substitutions": attr.string_keyed_label_dict(), | ||
"output": attr.output(mandatory = True), | ||
}, | ||
) |
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,30 @@ | ||
# Copyright 2024 The JAX SC Authors. | ||
# | ||
# 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. | ||
"""Test version string generation.""" | ||
|
||
from absl.testing import absltest | ||
from jax_tpu_embedding import sparsecore | ||
from jax_tpu_embedding.sparsecore import version | ||
|
||
|
||
class VersionTest(absltest.TestCase): | ||
|
||
def test_version_string(self): | ||
self.assertEqual(sparsecore.__version__, version.__version__) | ||
self.assertTrue(version.__version__.startswith(version._base_version)) | ||
self.assertTrue(version.__version__.endswith(version._version_suffix)) | ||
|
||
|
||
if __name__ == "__main__": | ||
absltest.main() |
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,18 @@ | ||
"""JAX TPU Embedding versioning utilities | ||
|
||
For releases, the version is of the form: | ||
xx.yy.zz | ||
|
||
For nightly builds, the date of the build is added: | ||
xx.yy.zz-devYYYMMDD | ||
""" | ||
|
||
_base_version = "0.1.0" | ||
_version_suffix = "${VERSION_SUFFIX}" | ||
|
||
# Git commit corresponding to the build, if available. | ||
__git_commit__ = "${GIT_COMMIT}" | ||
|
||
# Library version. | ||
__version__ = _base_version + _version_suffix | ||
|