Skip to content

Commit

Permalink
chore!: remove incompatible_generate_aliases and related flags (bazel…
Browse files Browse the repository at this point in the history
…build#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.
  • Loading branch information
aignas authored Jan 10, 2024
1 parent 1249567 commit b106f91
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 91 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ A brief description of the categories of changes:

### 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
Expand Down
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ pip_parse(
"sphinxcontrib-applehelp",
],
},
incompatible_generate_aliases = True,
python_interpreter_target = interpreter,
requirements_lock = "//docs/sphinx:requirements.txt",
)
Expand Down
21 changes: 0 additions & 21 deletions gazelle/manifest/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def gazelle_python_manifest(
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.
Expand All @@ -35,8 +34,6 @@ def gazelle_python_manifest(
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.
Expand Down Expand Up @@ -85,24 +82,6 @@ def gazelle_python_manifest(
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")],
Expand Down
18 changes: 0 additions & 18 deletions gazelle/manifest/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func main() {
manifestGeneratorHashPath string
requirementsPath string
pipRepositoryName string
usePipRepositoryAliases bool
omitUsePipRepositoryAliases bool
modulesMappingPath string
outputPath string
updateTarget string
Expand All @@ -64,16 +62,6 @@ func main() {
"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",
Expand Down Expand Up @@ -117,12 +105,6 @@ func main() {
Name: pipRepositoryName,
}

if omitUsePipRepositoryAliases {
repository.UsePipRepositoryAliases = nil
} else {
repository.UsePipRepositoryAliases = &usePipRepositoryAliases
}

manifestFile := manifest.NewFile(&manifest.Manifest{
ModulesMapping: modulesMapping,
PipRepository: &repository,
Expand Down
3 changes: 0 additions & 3 deletions gazelle/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,4 @@ type Manifest struct {
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"`
}
7 changes: 0 additions & 7 deletions gazelle/pythonconfig/pythonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ func (c *Config) FindThirdPartyDependency(modName string) (string, bool) {
}
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)
Expand Down
61 changes: 30 additions & 31 deletions python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,10 @@ def _pip_repository_impl(rctx):
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 = {
Expand Down Expand Up @@ -562,23 +559,6 @@ pip_repository_attrs = {
"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",
Expand Down Expand Up @@ -623,27 +603,46 @@ In your WORKSPACE file:
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
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
"@pypi//numpy",
"@pypi//requests",
],
)
```
or
```starlark
load("@pip_deps//:requirements.bzl", "requirement")
load("@pypi//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
requirement("requests"),
requirement("numpy"),
requirement("requests"),
],
)
```
Expand All @@ -655,7 +654,7 @@ functionality for exposing [entry points][whl_ep] as `py_binary` targets as well
[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",
Expand All @@ -670,7 +669,7 @@ Note that for packages whose name and script are the same, only the name of the
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",
Expand Down
8 changes: 2 additions & 6 deletions python/private/bzlmod/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,6 @@ The labels are JSON config files describing the modifications.
# 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():
Expand Down Expand Up @@ -522,9 +519,8 @@ the BUILD files for wheels.
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(
Expand Down
5 changes: 1 addition & 4 deletions python/private/py_console_script_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def _dist_info(pkg):
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")
Expand Down Expand Up @@ -70,7 +68,6 @@ def py_console_script_binary(

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,
Expand Down

0 comments on commit b106f91

Please sign in to comment.