chore!: remove incompatible_generate_aliases and related flags (#1567)
According to our breaking change policy, we are removing the flag
since in the previous release it has been flipped by default and
enabled to all users in 0.27.0.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5741d02..2e8f898 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,10 @@
### Changed
+* **BREAKING** The deprecated `incompatible_generate_aliases` feature flags
+ from `pip_parse` and `gazelle` got removed. They have been flipped to `True`
+ in 0.27.0 release.
+
### Fixed
* (bzlmod pip.parse) Use a platform-independent reference to the interpreter
diff --git a/WORKSPACE b/WORKSPACE
index 5631dce..7134717 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -120,7 +120,6 @@
"sphinxcontrib-applehelp",
],
},
- incompatible_generate_aliases = True,
python_interpreter_target = interpreter,
requirements_lock = "//docs/sphinx:requirements.txt",
)
diff --git a/gazelle/manifest/defs.bzl b/gazelle/manifest/defs.bzl
index f1a16c4..ef0f275 100644
--- a/gazelle/manifest/defs.bzl
+++ b/gazelle/manifest/defs.bzl
@@ -25,7 +25,6 @@
pip_repository_name = "",
pip_deps_repository_name = "",
manifest = ":gazelle_python.yaml",
- use_pip_repository_aliases = None,
**kwargs):
"""A macro for defining the updating and testing targets for the Gazelle manifest file.
@@ -35,8 +34,6 @@
requirements files that will be concatenated before passing on to
the manifest generator.
pip_repository_name: the name of the pip_install or pip_repository target.
- use_pip_repository_aliases: boolean flag to enable using user-friendly
- python package aliases. Defaults to True.
pip_deps_repository_name: deprecated - the old pip_install target name.
modules_mapping: the target for the generated modules_mapping.json file.
manifest: the target for the Gazelle manifest file.
@@ -85,24 +82,6 @@
update_target_label,
]
- # TODO @aignas 2023-10-31: When removing this code, cleanup the
- # code in gazelle to only work with aliased targets.
- if use_pip_repository_aliases == None:
- update_args += [
- "--omit-pip-repository-aliases-setting",
- "true",
- ]
- elif use_pip_repository_aliases:
- update_args += [
- "--use-pip-repository-aliases",
- "true",
- ]
- else:
- update_args += [
- "--use-pip-repository-aliases",
- "false",
- ]
-
go_binary(
name = update_target,
embed = [Label("//manifest/generate:generate_lib")],
diff --git a/gazelle/manifest/generate/generate.go b/gazelle/manifest/generate/generate.go
index 006b15e..bdd0206 100644
--- a/gazelle/manifest/generate/generate.go
+++ b/gazelle/manifest/generate/generate.go
@@ -42,8 +42,6 @@
manifestGeneratorHashPath string
requirementsPath string
pipRepositoryName string
- usePipRepositoryAliases bool
- omitUsePipRepositoryAliases bool
modulesMappingPath string
outputPath string
updateTarget string
@@ -64,16 +62,6 @@
"pip-repository-name",
"",
"The name of the pip_install or pip_repository target.")
- flag.BoolVar(
- &usePipRepositoryAliases,
- "use-pip-repository-aliases",
- true,
- "Whether to use the pip-repository aliases, which are generated when passing 'incompatible_generate_aliases = True'.")
- flag.BoolVar(
- &omitUsePipRepositoryAliases,
- "omit-pip-repository-aliases-setting",
- false,
- "Whether to omit use-pip-repository-aliases flag serialization into the manifest.")
flag.StringVar(
&modulesMappingPath,
"modules-mapping",
@@ -117,12 +105,6 @@
Name: pipRepositoryName,
}
- if omitUsePipRepositoryAliases {
- repository.UsePipRepositoryAliases = nil
- } else {
- repository.UsePipRepositoryAliases = &usePipRepositoryAliases
- }
-
manifestFile := manifest.NewFile(&manifest.Manifest{
ModulesMapping: modulesMapping,
PipRepository: &repository,
diff --git a/gazelle/manifest/manifest.go b/gazelle/manifest/manifest.go
index 55adef0..fb146f9 100644
--- a/gazelle/manifest/manifest.go
+++ b/gazelle/manifest/manifest.go
@@ -144,7 +144,4 @@
type PipRepository struct {
// The name of the pip_parse or pip_repository target.
Name string
- // UsePipRepositoryAliases allows to use aliases generated pip_repository
- // when passing incompatible_generate_aliases = True.
- UsePipRepositoryAliases *bool `yaml:"use_pip_repository_aliases,omitempty"`
}
diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go
index 09d308a..cecf9dc 100644
--- a/gazelle/pythonconfig/pythonconfig.go
+++ b/gazelle/pythonconfig/pythonconfig.go
@@ -239,13 +239,6 @@
}
sanitizedDistribution := SanitizeDistribution(distributionName)
- if repo := gazelleManifest.PipRepository; repo != nil && (repo.UsePipRepositoryAliases != nil && *repo.UsePipRepositoryAliases == false) {
- // TODO @aignas 2023-10-31: to be removed later.
- // @<repository_name>_<distribution_name>//:pkg
- distributionRepositoryName = distributionRepositoryName + "_" + sanitizedDistribution
- lbl := label.New(distributionRepositoryName, "", "pkg")
- return lbl.String(), true
- }
// @<repository_name>//<distribution_name>
lbl := label.New(distributionRepositoryName, sanitizedDistribution, sanitizedDistribution)
diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl
index a1e3de4..fe58472 100644
--- a/python/pip_install/pip_repository.bzl
+++ b/python/pip_install/pip_repository.bzl
@@ -353,13 +353,10 @@
if rctx.attr.experimental_target_platforms:
config["experimental_target_platforms"] = rctx.attr.experimental_target_platforms
- if rctx.attr.incompatible_generate_aliases:
- macro_tmpl = "@%s//{}:{}" % rctx.attr.name
- aliases = render_pkg_aliases(repo_name = rctx.attr.name, bzl_packages = bzl_packages)
- for path, contents in aliases.items():
- rctx.file(path, contents)
- else:
- macro_tmpl = "@%s_{}//:{}" % rctx.attr.name
+ macro_tmpl = "@%s//{}:{}" % rctx.attr.name
+ aliases = render_pkg_aliases(repo_name = rctx.attr.name, bzl_packages = bzl_packages)
+ for path, contents in aliases.items():
+ rctx.file(path, contents)
rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS)
rctx.template("requirements.bzl", rctx.attr._template, substitutions = {
@@ -562,23 +559,6 @@
"annotations": attr.string_dict(
doc = "Optional annotations to apply to packages",
),
- "incompatible_generate_aliases": attr.bool(
- default = True,
- doc = """\
-If true, extra aliases will be created in the main `hub` repo - i.e. the repo
-where the `requirements.bzl` is located. This means that for a Python package
-`PyYAML` initialized within a `pip` `hub_repo` there will be the following
-aliases generated:
-- `@pip//pyyaml` will point to `@pip_pyyaml//:pkg`
-- `@pip//pyyaml:data` will point to `@pip_pyyaml//:data`
-- `@pip//pyyaml:dist_info` will point to `@pip_pyyaml//:dist_info`
-- `@pip//pyyaml:pkg` will point to `@pip_pyyaml//:pkg`
-- `@pip//pyyaml:whl` will point to `@pip_pyyaml//:whl`
-
-This is to keep the dependencies coming from PyPI to have more ergonomic label
-names and support smooth transition to `bzlmod`.
-""",
- ),
"requirements_darwin": attr.label(
allow_single_file = True,
doc = "Override the requirements_lock attribute when the host platform is Mac OS",
@@ -623,27 +603,46 @@
load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
- name = "pip_deps",
+ name = "pypi",
requirements_lock = ":requirements.txt",
)
-load("@pip_deps//:requirements.bzl", "install_deps")
+load("@pypi//:requirements.bzl", "install_deps")
install_deps()
```
-You can then reference installed dependencies from a `BUILD` file with:
+You can then reference installed dependencies from a `BUILD` file with the alias targets generated in the same repo, for example, for `PyYAML` we would have the following:
+- `@pypi//pyyaml` and `@pypi//pyyaml:pkg` both point to the `py_library`
+ created after extracting the `PyYAML` package.
+- `@pypi//pyyaml:data` points to the extra data included in the package.
+- `@pypi//pyyaml:dist_info` points to the `dist-info` files in the package.
+- `@pypi//pyyaml:whl` points to the wheel file that was extracted.
```starlark
-load("@pip_deps//:requirements.bzl", "requirement")
+py_library(
+ name = "bar",
+ ...
+ deps = [
+ "//my/other:dep",
+ "@pypi//numpy",
+ "@pypi//requests",
+ ],
+)
+```
+
+or
+
+```starlark
+load("@pypi//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
- requirement("requests"),
requirement("numpy"),
+ requirement("requests"),
],
)
```
@@ -655,7 +654,7 @@
[whl_ep]: https://packaging.python.org/specifications/entry-points/
```starlark
-load("@pip_deps//:requirements.bzl", "entry_point")
+load("@pypi//:requirements.bzl", "entry_point")
alias(
name = "pip-compile",
@@ -670,7 +669,7 @@
is needed when calling the `entry_point` macro.
```starlark
-load("@pip_deps//:requirements.bzl", "entry_point")
+load("@pip//:requirements.bzl", "entry_point")
alias(
name = "flake8",
diff --git a/python/private/bzlmod/pip.bzl b/python/private/bzlmod/pip.bzl
index f843a8f..ae19dad 100644
--- a/python/private/bzlmod/pip.bzl
+++ b/python/private/bzlmod/pip.bzl
@@ -394,9 +394,6 @@
# don't allow users to override it.
attrs.pop("repo_prefix")
- # incompatible_generate_aliases is always True in bzlmod
- attrs.pop("incompatible_generate_aliases")
-
return attrs
def _whl_mod_attrs():
@@ -522,9 +519,8 @@
This tag class is used to create a pip hub and all of the spokes that are part of that hub.
This tag class reuses most of the pip attributes that are found in
@rules_python//python/pip_install:pip_repository.bzl.
-The exceptions are it does not use the args 'repo_prefix',
-and 'incompatible_generate_aliases'. We set the repository prefix
-for the user and the alias arg is always True in bzlmod.
+The exception is it does not use the arg 'repo_prefix'. We set the repository
+prefix for the user and the alias arg is always True in bzlmod.
""",
),
"whl_mods": tag_class(
diff --git a/python/private/py_console_script_binary.bzl b/python/private/py_console_script_binary.bzl
index deeded2..d0c58bf 100644
--- a/python/private/py_console_script_binary.bzl
+++ b/python/private/py_console_script_binary.bzl
@@ -27,9 +27,7 @@
rules_python does not know anything about the hub repos that the user has
available.
- NOTE: Works with `incompatible_generate_aliases` and without by assuming the
- following formats:
- * @pypi_pylint//:pkg
+ NOTE: Works with assuming the following label formats:
* @pypi//pylint
* @pypi//pylint:pkg
* Label("@pypi//pylint:pkg")
@@ -70,7 +68,6 @@
py_console_script_gen(
name = "_{}_gen".format(name),
- # NOTE @aignas 2023-08-05: Works with `incompatible_generate_aliases` and without.
entry_points_txt = entry_points_txt or _dist_info(pkg),
out = main,
console_script = script,