Skip to content

Commit 78263dc

Browse files
committed
Stop using Label.relative(), as it is deprecated
According to the Bazel documentation, this method is deprecated: https://bazel.build/rules/lib/builtins/Label#relative In this specific case there is also no need to use it, as we can simply use .repo_name to obtain the repository's canonical name.
1 parent e5b01ac commit 78263dc

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

python/private/toolchains_repo.bzl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ load(
3131
load(":repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
3232
load(":text_util.bzl", "render")
3333

34-
def get_repository_name(repository_workspace):
35-
dummy_label = "//:_"
36-
return str(repository_workspace.relative(dummy_label))[:-len(dummy_label)] or "@"
37-
3834
def python_toolchain_build_file_content(
3935
prefix,
4036
python_version,
@@ -90,7 +86,7 @@ def _toolchains_repo_impl(rctx):
9086
# python_register_toolchains macro so you don't normally need to interact with
9187
# these targets.
9288
93-
load("@{rules_python}//python/private:py_toolchain_suite.bzl", "py_toolchain_suite")
89+
load("@@{rules_python}//python/private:py_toolchain_suite.bzl", "py_toolchain_suite")
9490
9591
""".format(
9692
rules_python = rctx.attr._rules_python_workspace.repo_name,
@@ -151,13 +147,13 @@ toolchain_aliases(
151147
rctx.file("defs.bzl", content = """\
152148
# Generated by python/private/toolchains_repo.bzl
153149
154-
load("{rules_python}//python:pip.bzl", _compile_pip_requirements = "compile_pip_requirements")
155-
load("{rules_python}//python/private:deprecation.bzl", "with_deprecation")
156-
load("{rules_python}//python/private:text_util.bzl", "render")
157-
load("{rules_python}//python:py_binary.bzl", _py_binary = "py_binary")
158-
load("{rules_python}//python:py_test.bzl", _py_test = "py_test")
150+
load("@@{rules_python}//python:pip.bzl", _compile_pip_requirements = "compile_pip_requirements")
151+
load("@@{rules_python}//python/private:deprecation.bzl", "with_deprecation")
152+
load("@@{rules_python}//python/private:text_util.bzl", "render")
153+
load("@@{rules_python}//python:py_binary.bzl", _py_binary = "py_binary")
154+
load("@@{rules_python}//python:py_test.bzl", _py_test = "py_test")
159155
load(
160-
"{rules_python}//python/entry_points:py_console_script_binary.bzl",
156+
"@@{rules_python}//python/entry_points:py_console_script_binary.bzl",
161157
_py_console_script_binary = "py_console_script_binary",
162158
)
163159
@@ -185,7 +181,7 @@ def compile_pip_requirements(**kwargs):
185181
""".format(
186182
name = rctx.attr.name,
187183
python_version = rctx.attr.python_version,
188-
rules_python = get_repository_name(rctx.attr._rules_python_workspace),
184+
rules_python = rctx.attr._rules_python_workspace.repo_name,
189185
))
190186

191187
toolchain_aliases = repository_rule(
@@ -308,13 +304,13 @@ def _multi_toolchain_aliases_impl(rctx):
308304
rctx.file(file, content = """\
309305
# Generated by python/private/toolchains_repo.bzl
310306
311-
load("{rules_python}//python:pip.bzl", _compile_pip_requirements = "compile_pip_requirements")
312-
load("{rules_python}//python/private:deprecation.bzl", "with_deprecation")
313-
load("{rules_python}//python/private:text_util.bzl", "render")
314-
load("{rules_python}//python:py_binary.bzl", _py_binary = "py_binary")
315-
load("{rules_python}//python:py_test.bzl", _py_test = "py_test")
307+
load("@@{rules_python}//python:pip.bzl", _compile_pip_requirements = "compile_pip_requirements")
308+
load("@@{rules_python}//python/private:deprecation.bzl", "with_deprecation")
309+
load("@@{rules_python}//python/private:text_util.bzl", "render")
310+
load("@@{rules_python}//python:py_binary.bzl", _py_binary = "py_binary")
311+
load("@@{rules_python}//python:py_test.bzl", _py_test = "py_test")
316312
load(
317-
"{rules_python}//python/entry_points:py_console_script_binary.bzl",
313+
"@@{rules_python}//python/entry_points:py_console_script_binary.bzl",
318314
_py_console_script_binary = "py_console_script_binary",
319315
)
320316
@@ -343,14 +339,14 @@ def compile_pip_requirements(**kwargs):
343339
repository_name = repository_name,
344340
name = rctx.attr.name,
345341
python_version = python_version,
346-
rules_python = get_repository_name(rctx.attr._rules_python_workspace),
342+
rules_python = rules_python,
347343
))
348344
rctx.file("{}/BUILD.bazel".format(python_version), "")
349345

350346
pip_bzl = """\
351347
# Generated by python/private/toolchains_repo.bzl
352348
353-
load("@{rules_python}//python:pip.bzl", "pip_parse", _multi_pip_parse = "multi_pip_parse")
349+
load("@@{rules_python}//python:pip.bzl", "pip_parse", _multi_pip_parse = "multi_pip_parse")
354350
355351
def multi_pip_parse(name, requirements_lock, **kwargs):
356352
return _multi_pip_parse(

0 commit comments

Comments
 (0)