Skip to content

Commit

Permalink
The pip_lock rule now supports multiple index URLs
Browse files Browse the repository at this point in the history
Instead of being an explicit attribute to the rule, this is simply exposed via binary
args.

Resolves #37
  • Loading branch information
apt-itude committed Jun 27, 2019
1 parent d86ed92 commit 82d3393
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
25 changes: 10 additions & 15 deletions rules/lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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.
""",
),
Expand All @@ -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.
""",
),
Expand All @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/bin/lock_pip_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -36,7 +37,7 @@ def main():
resolved_requirements = resolve.resolve_requirement_set(
requirement_set,
pip_session,
[args.index_url],
index_urls,
wheel_directory,
)

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions src/templates/lock_pip_requirements_wrapper_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 82d3393

Please sign in to comment.