diff --git a/rules/lock.bzl b/rules/lock.bzl index 4079ead..9c9a822 100644 --- a/rules/lock.bzl +++ b/rules/lock.bzl @@ -27,7 +27,6 @@ def _pip_lock_impl(ctx): "@@USE_PY2@@": "true" if "2" in ctx.attr.python_version else "false", "@@USE_PY3@@": "true" if "3" in ctx.attr.python_version else "false", "@@WHEEL_DIRECTORY@@": wheel_dir, - "@@INDEX_URL@@": ctx.attr.index_url, } ctx.actions.expand_template( @@ -55,14 +54,14 @@ pip_lock = rule( doc = """ Defines a binary target that may be executed via `bazel run` in order to compile any number of `requirements.txt` files into a single `requirements-lock.json` - file. This binary should be executed on all supported platforms to add the - correct set of requirements to the lock file for each platform. + file. This binary should be executed on all supported platforms to add the + correct set of requirements to the lock file for each platform. """, attrs = { "requirements": attr.label_list( allow_files = True, doc = """ - Files following the standard requirements file format + Files following the standard requirements file format (https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format) These should define direct dependencies only, and should not pin @@ -73,7 +72,7 @@ pip_lock = rule( default = "requirements-lock.json", doc = """ A path relative to the package in which this rule is defined to which - the compiled lock file should be written. This file should + the compiled lock file should be written. This file should be source-controlled and provided as input to the `pip_repository` rule. """, ), @@ -82,7 +81,7 @@ pip_lock = rule( default = "PY2AND3", doc = """ The Python versions for which to compile the requirement set. The - requirements lock file will contain one environment per Python version + requirements lock file will contain one environment per Python version per platform. Each environment will define its locked requirement set. """, ), @@ -91,20 +90,16 @@ pip_lock = rule( doc = """ A path to a directory relative to the package in which this rule is defined in which built wheels will be stored. If the given directory - does not already exist, it will be created. - - Wheels will be built for any required distribution that is not already + does not already exist, it will be created. + + Wheels will be built for any required distribution that is not already available as a wheel for the given environment. These wheels may be - committed to source control or published to a custom Python package + committed to source control or published to a custom Python package index. If the latter approach is used, this binary should be run again - with the `index_url` attribute set to the URL of that index in order to + with the `--index-url` argument set to the URL of that index in order to resolve the new locations of those wheels. """, ), - "index_url": attr.string( - default = "https://pypi.org/simple", - doc = "The URL of a custom Python package index to use instead of PyPI.", - ), "_lock_pip_requirements_py2": attr.label( default = "//src/bin:lock_pip_requirements_py2", cfg = "target", diff --git a/src/bin/lock_pip_requirements.py b/src/bin/lock_pip_requirements.py index f09d673..ae92d6f 100644 --- a/src/bin/lock_pip_requirements.py +++ b/src/bin/lock_pip_requirements.py @@ -18,6 +18,7 @@ def main(): workspace_directory = get_workspace_directory() lock_file_path = os.path.join(workspace_directory, args.lock_file_path) wheel_directory = os.path.join(workspace_directory, args.wheel_dir) + index_urls = args.index_urls or ["https://pypi.org/simple"] LOG.info("Locking pip requirements for Python %s", sys.version_info.major) @@ -36,7 +37,7 @@ def main(): resolved_requirements = resolve.resolve_requirement_set( requirement_set, pip_session, - [args.index_url], + index_urls, wheel_directory, ) @@ -87,7 +88,8 @@ def parse_args(): ) parser.add_argument( "-i", "--index-url", - default="https://pypi.org/simple", + action="append", + dest="index_urls", ) parser.add_argument( "-w", "--wheel-dir", diff --git a/src/templates/lock_pip_requirements_wrapper_template.sh b/src/templates/lock_pip_requirements_wrapper_template.sh index 5f4f35b..e1f4691 100644 --- a/src/templates/lock_pip_requirements_wrapper_template.sh +++ b/src/templates/lock_pip_requirements_wrapper_template.sh @@ -10,7 +10,6 @@ REQUIREMENTS_LOCK_PATH="@@REQUIREMENTS_LOCK_PATH@@" USE_PY2=@@USE_PY2@@ USE_PY3=@@USE_PY3@@ WHEEL_DIRECTORY="@@WHEEL_DIRECTORY@@" -INDEX_URL=@@INDEX_URL@@ REQUESTING_HELP=0 for arg in $@; do @@ -23,7 +22,6 @@ if [ "$USE_PY2" = true ]; then $LOCK_PIP_REQUIREMENTS_PY2 \ --lock-file $REQUIREMENTS_LOCK_PATH \ --wheel-dir $WHEEL_DIRECTORY \ - --index-url $INDEX_URL \ --workspace-name $WORKSPACE_NAME \ "$@" \ $REQUIREMENTS_TXT_PATHS @@ -37,7 +35,6 @@ if [ "$USE_PY3" = true ]; then $LOCK_PIP_REQUIREMENTS_PY3 \ --lock-file $REQUIREMENTS_LOCK_PATH \ --wheel-dir $WHEEL_DIRECTORY \ - --index-url $INDEX_URL \ --workspace-name $WORKSPACE_NAME \ "$@" \ $REQUIREMENTS_TXT_PATHS