1#!/usr/bin/env bash 2# Copyright 2023 The Bazel Authors. All rights reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -o errexit -o nounset -o pipefail 17 18# Set by GH actions, see 19# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables 20TAG=${GITHUB_REF_NAME} 21# A prefix is added to better match the GitHub generated archives. 22PREFIX="rules_python-${TAG}" 23ARCHIVE="rules_python-$TAG.tar.gz" 24git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE 25SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') 26 27cat > release_notes.txt << EOF 28 29For more detailed setup instructions, see https://rules-python.readthedocs.io/en/latest/getting-started.html 30 31## Using Bzlmod 32 33Add to your \`MODULE.bazel\` file: 34 35\`\`\`starlark 36bazel_dep(name = "rules_python", version = "${TAG}") 37 38pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") 39 40pip.parse( 41 hub_name = "pip", 42 python_version = "3.11", 43 requirements_lock = "//:requirements_lock.txt", 44) 45 46use_repo(pip, "pip") 47\`\`\` 48 49## Using WORKSPACE 50 51Paste this snippet into your \`WORKSPACE\` file: 52 53\`\`\`starlark 54load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 55 56http_archive( 57 name = "rules_python", 58 sha256 = "${SHA}", 59 strip_prefix = "${PREFIX}", 60 url = "https://github.com/bazelbuild/rules_python/releases/download/${TAG}/rules_python-${TAG}.tar.gz", 61) 62 63load("@rules_python//python:repositories.bzl", "py_repositories") 64 65py_repositories() 66\`\`\` 67 68### Gazelle plugin 69 70Paste this snippet into your \`WORKSPACE\` file: 71 72\`\`\`starlark 73load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 74http_archive( 75 name = "rules_python_gazelle_plugin", 76 sha256 = "${SHA}", 77 strip_prefix = "${PREFIX}/gazelle", 78 url = "https://github.com/bazelbuild/rules_python/releases/download/${TAG}/rules_python-${TAG}.tar.gz", 79) 80 81# To compile the rules_python gazelle extension from source, 82# we must fetch some third-party go dependencies that it uses. 83 84load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps") 85 86_py_gazelle_deps() 87\`\`\` 88EOF 89