From 7b5ac7594e35a85956472622094a5eb877990425 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 19 Nov 2023 22:44:28 +0900 Subject: [PATCH] chore!: remove incompatible_generate_aliases and related flags 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. --- CHANGELOG.md | 4 ++ WORKSPACE | 1 - gazelle/manifest/defs.bzl | 21 ------- gazelle/manifest/generate/generate.go | 18 ------ gazelle/manifest/manifest.go | 3 - gazelle/pythonconfig/pythonconfig.go | 7 --- python/pip_install/pip_repository.bzl | 61 ++++++++++----------- python/private/bzlmod/pip.bzl | 8 +-- python/private/py_console_script_binary.bzl | 5 +- 9 files changed, 37 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37163b0ba9..4a002095da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/WORKSPACE b/WORKSPACE index 5631dce63d..713471726e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -120,7 +120,6 @@ pip_parse( "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 f1a16c4811..ef0f275464 100644 --- a/gazelle/manifest/defs.bzl +++ b/gazelle/manifest/defs.bzl @@ -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. @@ -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. @@ -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")], diff --git a/gazelle/manifest/generate/generate.go b/gazelle/manifest/generate/generate.go index 006b15e051..bdd0206ccb 100644 --- a/gazelle/manifest/generate/generate.go +++ b/gazelle/manifest/generate/generate.go @@ -42,8 +42,6 @@ func main() { manifestGeneratorHashPath string requirementsPath string pipRepositoryName string - usePipRepositoryAliases bool - omitUsePipRepositoryAliases bool modulesMappingPath string outputPath string updateTarget string @@ -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", @@ -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, diff --git a/gazelle/manifest/manifest.go b/gazelle/manifest/manifest.go index 55adef07cd..fb146f9439 100644 --- a/gazelle/manifest/manifest.go +++ b/gazelle/manifest/manifest.go @@ -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"` } diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go index 09d308ad35..cecf9dcea0 100644 --- a/gazelle/pythonconfig/pythonconfig.go +++ b/gazelle/pythonconfig/pythonconfig.go @@ -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. - // @_//:pkg - distributionRepositoryName = distributionRepositoryName + "_" + sanitizedDistribution - lbl := label.New(distributionRepositoryName, "", "pkg") - return lbl.String(), true - } // @// lbl := label.New(distributionRepositoryName, sanitizedDistribution, sanitizedDistribution) diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index a1e3de47e1..fe58472f53 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -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 = { @@ -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", @@ -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"), ], ) ``` @@ -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", @@ -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", diff --git a/python/private/bzlmod/pip.bzl b/python/private/bzlmod/pip.bzl index f843a8fb04..ae19dad610 100644 --- a/python/private/bzlmod/pip.bzl +++ b/python/private/bzlmod/pip.bzl @@ -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(): @@ -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( diff --git a/python/private/py_console_script_binary.bzl b/python/private/py_console_script_binary.bzl index deeded2f3a..d0c58bf759 100644 --- a/python/private/py_console_script_binary.bzl +++ b/python/private/py_console_script_binary.bzl @@ -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") @@ -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,