diff --git a/python/pip_install/BUILD b/python/pip_install/BUILD index 7727b29089..9ff51375da 100644 --- a/python/pip_install/BUILD +++ b/python/pip_install/BUILD @@ -6,7 +6,6 @@ filegroup( "BUILD", "pip_compile.py", "//python/pip_install/extract_wheels:distribution", - "//python/pip_install/parse_requirements_to_bzl:distribution", "//python/pip_install/private:distribution", ], visibility = ["//:__pkg__"], @@ -24,7 +23,6 @@ filegroup( name = "py_srcs", srcs = [ "//python/pip_install/extract_wheels:py_srcs", - "//python/pip_install/parse_requirements_to_bzl:py_srcs", ], visibility = ["//python/pip_install/private:__pkg__"], ) diff --git a/python/pip_install/extract_wheels/BUILD b/python/pip_install/extract_wheels/BUILD index a92c562292..158d34ba27 100644 --- a/python/pip_install/extract_wheels/BUILD +++ b/python/pip_install/extract_wheels/BUILD @@ -1,20 +1,179 @@ -load("@rules_python//python:defs.bzl", "py_binary") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") +load("//python/pip_install:repositories.bzl", "requirement") +load(":annotations_test_helpers.bzl", "package_annotation", "package_annotations_file") + +py_library( + name = "lib", + srcs = [ + "annotation.py", + "arguments.py", + "bazel.py", + "extract_single_wheel.py", + "extract_wheels.py", + "namespace_pkgs.py", + "parse_requirements_to_bzl.py", + "requirements.py", + "wheel.py", + ], + deps = [ + requirement("installer"), + requirement("setuptools"), + ], +) py_binary( name = "extract_wheels", srcs = [ - "__init__.py", - "__main__.py", + "extract_wheels.py", + ], + deps = [":lib"], +) + +py_binary( + name = "extract_single_wheel", + srcs = [ + "extract_single_wheel.py", + ], + deps = [":lib"], +) + +py_binary( + name = "parse_requirements_to_bzl", + srcs = [ + "parse_requirements_to_bzl.py", + ], + deps = [":lib"], +) + +package_annotations_file( + name = "mock_annotations", + annotations = { + "pkg_a": package_annotation(), + "pkg_b": package_annotation( + data_exclude_glob = [ + "*.foo", + "*.bar", + ], + ), + "pkg_c": package_annotation( + # The `join` and `strip` here accounts for potential differences + # in new lines between unix and windows hosts. + additive_build_content = "\n".join([line.strip() for line in """\ +cc_library( + name = "my_target", + hdrs = glob(["**/*.h"]), + srcs = glob(["**/*.cc"]), +) +""".splitlines()]), + data = [":my_target"], + ), + "pkg_d": package_annotation( + srcs_exclude_glob = ["pkg_d/tests/**"], + ), + }, + tags = ["manual"], +) + +py_test( + name = "annotations_test", + size = "small", + srcs = ["annotations_test.py"], + data = [":mock_annotations"], + env = {"MOCK_ANNOTATIONS": "$(rootpath :mock_annotations)"}, + tags = ["unit"], + deps = [ + ":lib", + "//python/runfiles", + ], +) + +py_test( + name = "bazel_test", + size = "small", + srcs = [ + "bazel_test.py", + ], + tags = ["unit"], + deps = [ + ":lib", + ], +) + +py_test( + name = "namespace_pkgs_test", + size = "small", + srcs = [ + "namespace_pkgs_test.py", + ], + tags = ["unit"], + deps = [ + ":lib", + ], +) + +py_test( + name = "requirements_test", + size = "small", + srcs = [ + "requirements_test.py", + ], + tags = ["unit"], + deps = [ + ":lib", + ], +) + +py_test( + name = "arguments_test", + size = "small", + srcs = [ + "arguments_test.py", + ], + tags = ["unit"], + deps = [ + ":lib", + ], +) + +py_test( + name = "whl_filegroup_test", + size = "small", + srcs = ["whl_filegroup_test.py"], + data = ["//examples/wheel:minimal_with_py_package"], + main = "whl_filegroup_test.py", + tags = ["unit"], + deps = [":lib"], +) + +py_test( + name = "parse_requirements_to_bzl_test", + size = "small", + srcs = [ + "parse_requirements_to_bzl_test.py", + ], + tags = ["unit"], + deps = [ + ":lib", + ], +) + +py_test( + name = "requirements_bzl_test", + size = "small", + srcs = [ + "requirements_bzl_test.py", + ], + deps = [ + ":lib", ], - main = "__main__.py", - deps = ["//python/pip_install/extract_wheels/lib"], ) filegroup( name = "distribution", - srcs = glob(["*"]) + [ - "//python/pip_install/extract_wheels/lib:distribution", - ], + srcs = glob( + ["*"], + exclude = ["*_test.py"], + ), visibility = ["//python/pip_install:__subpackages__"], ) @@ -23,8 +182,6 @@ filegroup( srcs = glob( include = ["**/*.py"], exclude = ["**/*_test.py"], - ) + [ - "//python/pip_install/extract_wheels/lib:py_srcs", - ], + ), visibility = ["//python/pip_install:__subpackages__"], ) diff --git a/python/pip_install/extract_wheels/__init__.py b/python/pip_install/extract_wheels/__init__.py index cda6d541b0..e69de29bb2 100644 --- a/python/pip_install/extract_wheels/__init__.py +++ b/python/pip_install/extract_wheels/__init__.py @@ -1,128 +0,0 @@ -"""extract_wheels - -extract_wheels resolves and fetches artifacts transitively from the Python Package Index (PyPI) based on a -requirements.txt. It generates the required BUILD files to consume these packages as Python libraries. - -Under the hood, it depends on the `pip wheel` command to do resolution, download, and compilation into wheels. -""" -import argparse -import glob -import os -import pathlib -import subprocess -import sys - -from python.pip_install.extract_wheels.lib import ( - annotation, - arguments, - bazel, - requirements, - wheel, -) - - -def configure_reproducible_wheels() -> None: - """Modifies the environment to make wheel building reproducible. - - Wheels created from sdists are not reproducible by default. We can however workaround this by - patching in some configuration with environment variables. - """ - - # wheel, by default, enables debug symbols in GCC. This incidentally captures the build path in the .so file - # We can override this behavior by disabling debug symbols entirely. - # https://github.com/pypa/pip/issues/6505 - if "CFLAGS" in os.environ: - os.environ["CFLAGS"] += " -g0" - else: - os.environ["CFLAGS"] = "-g0" - - # set SOURCE_DATE_EPOCH to 1980 so that we can use python wheels - # https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md#python-setuppy-bdist_wheel-cannot-create-whl - if "SOURCE_DATE_EPOCH" not in os.environ: - os.environ["SOURCE_DATE_EPOCH"] = "315532800" - - # Python wheel metadata files can be unstable. - # See https://bitbucket.org/pypa/wheel/pull-requests/74/make-the-output-of-metadata-files/diff - if "PYTHONHASHSEED" not in os.environ: - os.environ["PYTHONHASHSEED"] = "0" - - -def main() -> None: - """Main program. - - Exits zero on successful program termination, non-zero otherwise. - """ - - configure_reproducible_wheels() - - parser = argparse.ArgumentParser( - description="Resolve and fetch artifacts transitively from PyPI" - ) - parser.add_argument( - "--requirements", - action="store", - required=True, - help="Path to requirements.txt from where to install dependencies", - ) - parser.add_argument( - "--annotations", - type=annotation.annotations_map_from_str_path, - help="A json encoded file containing annotations for rendered packages.", - ) - arguments.parse_common_args(parser) - args = parser.parse_args() - deserialized_args = dict(vars(args)) - arguments.deserialize_structured_args(deserialized_args) - - # Pip is run with the working directory changed to the folder containing the requirements.txt file, to allow for - # relative requirements to be correctly resolved. The --wheel-dir is therefore required to be repointed back to the - # current calling working directory (the repo root in .../external/name), where the wheel files should be written to - pip_args = ( - [sys.executable, "-m", "pip"] - + (["--isolated"] if args.isolated else []) - + ["wheel", "-r", args.requirements] - + ["--wheel-dir", os.getcwd()] - + deserialized_args["extra_pip_args"] - ) - - env = os.environ.copy() - env.update(deserialized_args["environment"]) - - # Assumes any errors are logged by pip so do nothing. This command will fail if pip fails - subprocess.run( - pip_args, - check=True, - env=env, - cwd=str(pathlib.Path(args.requirements).parent.resolve()), - ) - - extras = requirements.parse_extras(args.requirements) - - repo_label = "@%s" % args.repo - - # Locate all wheels - wheels = [whl for whl in glob.glob("*.whl")] - - # Collect all annotations - reqs = {whl: wheel.Wheel(whl).name for whl in wheels} - annotations = args.annotations.collect(reqs.values()) - - targets = [ - '"{}{}"'.format( - repo_label, - bazel.extract_wheel( - wheel_file=whl, - extras=extras, - pip_data_exclude=deserialized_args["pip_data_exclude"], - enable_implicit_namespace_pkgs=args.enable_implicit_namespace_pkgs, - repo_prefix=args.repo_prefix, - annotation=annotations.get(name), - ), - ) - for whl, name in reqs.items() - ] - - with open("requirements.bzl", "w") as requirement_file: - requirement_file.write( - bazel.generate_requirements_file_contents(repo_label, targets) - ) diff --git a/python/pip_install/extract_wheels/__main__.py b/python/pip_install/extract_wheels/__main__.py deleted file mode 100644 index 40b690e2fb..0000000000 --- a/python/pip_install/extract_wheels/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Main entry point.""" -from python.pip_install.extract_wheels import main - -if __name__ == "__main__": - main() diff --git a/python/pip_install/extract_wheels/lib/annotation.py b/python/pip_install/extract_wheels/annotation.py similarity index 100% rename from python/pip_install/extract_wheels/lib/annotation.py rename to python/pip_install/extract_wheels/annotation.py diff --git a/python/pip_install/extract_wheels/lib/annotations_test.py b/python/pip_install/extract_wheels/annotations_test.py similarity index 97% rename from python/pip_install/extract_wheels/lib/annotations_test.py rename to python/pip_install/extract_wheels/annotations_test.py index 94b92a1ed1..0c41bf70a4 100644 --- a/python/pip_install/extract_wheels/lib/annotations_test.py +++ b/python/pip_install/extract_wheels/annotations_test.py @@ -5,7 +5,7 @@ import unittest from pathlib import Path -from python.pip_install.extract_wheels.lib.annotation import Annotation, AnnotationsMap +from python.pip_install.extract_wheels.annotation import Annotation, AnnotationsMap from python.runfiles import runfiles diff --git a/python/pip_install/extract_wheels/lib/annotations_test_helpers.bzl b/python/pip_install/extract_wheels/annotations_test_helpers.bzl similarity index 100% rename from python/pip_install/extract_wheels/lib/annotations_test_helpers.bzl rename to python/pip_install/extract_wheels/annotations_test_helpers.bzl diff --git a/python/pip_install/extract_wheels/lib/arguments.py b/python/pip_install/extract_wheels/arguments.py similarity index 100% rename from python/pip_install/extract_wheels/lib/arguments.py rename to python/pip_install/extract_wheels/arguments.py diff --git a/python/pip_install/extract_wheels/lib/arguments_test.py b/python/pip_install/extract_wheels/arguments_test.py similarity index 96% rename from python/pip_install/extract_wheels/lib/arguments_test.py rename to python/pip_install/extract_wheels/arguments_test.py index 6a714beeef..8a3aec7a37 100644 --- a/python/pip_install/extract_wheels/lib/arguments_test.py +++ b/python/pip_install/extract_wheels/arguments_test.py @@ -2,7 +2,7 @@ import json import unittest -from python.pip_install.extract_wheels.lib import arguments +from python.pip_install.extract_wheels import arguments class ArgumentsTestCase(unittest.TestCase): diff --git a/python/pip_install/extract_wheels/lib/bazel.py b/python/pip_install/extract_wheels/bazel.py similarity index 99% rename from python/pip_install/extract_wheels/lib/bazel.py rename to python/pip_install/extract_wheels/bazel.py index da1e52c4d5..d7aa706433 100644 --- a/python/pip_install/extract_wheels/lib/bazel.py +++ b/python/pip_install/extract_wheels/bazel.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Dict, Iterable, List, Optional, Set -from python.pip_install.extract_wheels.lib import ( +from python.pip_install.extract_wheels import ( annotation, namespace_pkgs, wheel, diff --git a/python/pip_install/extract_wheels/lib/bazel_test.py b/python/pip_install/extract_wheels/bazel_test.py similarity index 88% rename from python/pip_install/extract_wheels/lib/bazel_test.py rename to python/pip_install/extract_wheels/bazel_test.py index c6c11dc197..7ecf422227 100644 --- a/python/pip_install/extract_wheels/lib/bazel_test.py +++ b/python/pip_install/extract_wheels/bazel_test.py @@ -1,6 +1,6 @@ import unittest -from python.pip_install.extract_wheels.lib.bazel import generate_entry_point_contents +from python.pip_install.extract_wheels.bazel import generate_entry_point_contents class BazelTestCase(unittest.TestCase): diff --git a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__init__.py b/python/pip_install/extract_wheels/extract_single_wheel.py similarity index 89% rename from python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__init__.py rename to python/pip_install/extract_wheels/extract_single_wheel.py index 198aefae83..c69fbd5958 100644 --- a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__init__.py +++ b/python/pip_install/extract_wheels/extract_single_wheel.py @@ -6,9 +6,9 @@ import sys from tempfile import NamedTemporaryFile -from python.pip_install.extract_wheels import configure_reproducible_wheels -from python.pip_install.extract_wheels.lib import arguments, bazel, requirements -from python.pip_install.extract_wheels.lib.annotation import annotation_from_str_path +from python.pip_install.extract_wheels.extract_wheels import configure_reproducible_wheels +from python.pip_install.extract_wheels import arguments, bazel, requirements +from python.pip_install.extract_wheels.annotation import annotation_from_str_path def main() -> None: @@ -75,3 +75,7 @@ def main() -> None: repo_prefix=args.repo_prefix, annotation=args.annotation, ) + + +if __name__ == "__main__": + main() diff --git a/python/pip_install/extract_wheels/extract_wheels.py b/python/pip_install/extract_wheels/extract_wheels.py new file mode 100644 index 0000000000..7e583eb442 --- /dev/null +++ b/python/pip_install/extract_wheels/extract_wheels.py @@ -0,0 +1,132 @@ +"""extract_wheels + +extract_wheels resolves and fetches artifacts transitively from the Python Package Index (PyPI) based on a +requirements.txt. It generates the required BUILD files to consume these packages as Python libraries. + +Under the hood, it depends on the `pip wheel` command to do resolution, download, and compilation into wheels. +""" +import argparse +import glob +import os +import pathlib +import subprocess +import sys + +from python.pip_install.extract_wheels import ( + annotation, + arguments, + bazel, + requirements, + wheel, +) + + +def configure_reproducible_wheels() -> None: + """Modifies the environment to make wheel building reproducible. + + Wheels created from sdists are not reproducible by default. We can however workaround this by + patching in some configuration with environment variables. + """ + + # wheel, by default, enables debug symbols in GCC. This incidentally captures the build path in the .so file + # We can override this behavior by disabling debug symbols entirely. + # https://github.com/pypa/pip/issues/6505 + if "CFLAGS" in os.environ: + os.environ["CFLAGS"] += " -g0" + else: + os.environ["CFLAGS"] = "-g0" + + # set SOURCE_DATE_EPOCH to 1980 so that we can use python wheels + # https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md#python-setuppy-bdist_wheel-cannot-create-whl + if "SOURCE_DATE_EPOCH" not in os.environ: + os.environ["SOURCE_DATE_EPOCH"] = "315532800" + + # Python wheel metadata files can be unstable. + # See https://bitbucket.org/pypa/wheel/pull-requests/74/make-the-output-of-metadata-files/diff + if "PYTHONHASHSEED" not in os.environ: + os.environ["PYTHONHASHSEED"] = "0" + + +def main() -> None: + """Main program. + + Exits zero on successful program termination, non-zero otherwise. + """ + + configure_reproducible_wheels() + + parser = argparse.ArgumentParser( + description="Resolve and fetch artifacts transitively from PyPI" + ) + parser.add_argument( + "--requirements", + action="store", + required=True, + help="Path to requirements.txt from where to install dependencies", + ) + parser.add_argument( + "--annotations", + type=annotation.annotations_map_from_str_path, + help="A json encoded file containing annotations for rendered packages.", + ) + arguments.parse_common_args(parser) + args = parser.parse_args() + deserialized_args = dict(vars(args)) + arguments.deserialize_structured_args(deserialized_args) + + # Pip is run with the working directory changed to the folder containing the requirements.txt file, to allow for + # relative requirements to be correctly resolved. The --wheel-dir is therefore required to be repointed back to the + # current calling working directory (the repo root in .../external/name), where the wheel files should be written to + pip_args = ( + [sys.executable, "-m", "pip"] + + (["--isolated"] if args.isolated else []) + + ["wheel", "-r", args.requirements] + + ["--wheel-dir", os.getcwd()] + + deserialized_args["extra_pip_args"] + ) + + env = os.environ.copy() + env.update(deserialized_args["environment"]) + + # Assumes any errors are logged by pip so do nothing. This command will fail if pip fails + subprocess.run( + pip_args, + check=True, + env=env, + cwd=str(pathlib.Path(args.requirements).parent.resolve()), + ) + + extras = requirements.parse_extras(args.requirements) + + repo_label = "@%s" % args.repo + + # Locate all wheels + wheels = [whl for whl in glob.glob("*.whl")] + + # Collect all annotations + reqs = {whl: wheel.Wheel(whl).name for whl in wheels} + annotations = args.annotations.collect(reqs.values()) + + targets = [ + '"{}{}"'.format( + repo_label, + bazel.extract_wheel( + wheel_file=whl, + extras=extras, + pip_data_exclude=deserialized_args["pip_data_exclude"], + enable_implicit_namespace_pkgs=args.enable_implicit_namespace_pkgs, + repo_prefix=args.repo_prefix, + annotation=annotations.get(name), + ), + ) + for whl, name in reqs.items() + ] + + with open("requirements.bzl", "w") as requirement_file: + requirement_file.write( + bazel.generate_requirements_file_contents(repo_label, targets) + ) + + +if __name__ == "__main__": + main() diff --git a/python/pip_install/extract_wheels/lib/BUILD b/python/pip_install/extract_wheels/lib/BUILD deleted file mode 100644 index 31d6bb8918..0000000000 --- a/python/pip_install/extract_wheels/lib/BUILD +++ /dev/null @@ -1,153 +0,0 @@ -load("@rules_python//python:defs.bzl", "py_library", "py_test") -load("//python/pip_install:repositories.bzl", "requirement") -load(":annotations_test_helpers.bzl", "package_annotation", "package_annotations_file") - -py_library( - name = "lib", - srcs = [ - "annotation.py", - "arguments.py", - "bazel.py", - "namespace_pkgs.py", - "requirements.py", - "wheel.py", - ], - visibility = [ - "//python/pip_install/extract_wheels:__subpackages__", - "//python/pip_install/parse_requirements_to_bzl:__subpackages__", - ], - deps = [ - requirement("installer"), - requirement("setuptools"), - ], -) - -package_annotations_file( - name = "mock_annotations", - annotations = { - "pkg_a": package_annotation(), - "pkg_b": package_annotation( - data_exclude_glob = [ - "*.foo", - "*.bar", - ], - ), - "pkg_c": package_annotation( - # The `join` and `strip` here accounts for potential differences - # in new lines between unix and windows hosts. - additive_build_content = "\n".join([line.strip() for line in """\ -cc_library( - name = "my_target", - hdrs = glob(["**/*.h"]), - srcs = glob(["**/*.cc"]), -) -""".splitlines()]), - data = [":my_target"], - ), - "pkg_d": package_annotation( - srcs_exclude_glob = ["pkg_d/tests/**"], - ), - }, - tags = ["manual"], -) - -py_test( - name = "annotations_test", - size = "small", - srcs = ["annotations_test.py"], - data = [":mock_annotations"], - env = {"MOCK_ANNOTATIONS": "$(rootpath :mock_annotations)"}, - tags = ["unit"], - deps = [ - ":lib", - "//python/runfiles", - ], -) - -py_test( - name = "bazel_test", - size = "small", - srcs = [ - "bazel_test.py", - ], - tags = ["unit"], - deps = [ - ":lib", - ], -) - -py_test( - name = "namespace_pkgs_test", - size = "small", - srcs = [ - "namespace_pkgs_test.py", - ], - tags = ["unit"], - deps = [ - ":lib", - ], -) - -py_test( - name = "requirements_test", - size = "small", - srcs = [ - "requirements_test.py", - ], - tags = ["unit"], - deps = [ - ":lib", - ], -) - -py_test( - name = "arguments_test", - size = "small", - srcs = [ - "arguments_test.py", - ], - tags = ["unit"], - deps = [ - ":lib", - "//python/pip_install/parse_requirements_to_bzl:lib", - ], -) - -py_test( - name = "whl_filegroup_test", - size = "small", - srcs = ["whl_filegroup_test.py"], - data = ["//examples/wheel:minimal_with_py_package"], - main = "whl_filegroup_test.py", - tags = ["unit"], - deps = [":lib"], -) - -py_test( - name = "requirements_bzl_test", - size = "small", - srcs = [ - "requirements_bzl_test.py", - ], - deps = [ - ":lib", - ], -) - -filegroup( - name = "distribution", - srcs = glob( - ["*"], - exclude = ["*_test.py"], - ), - visibility = ["//python/pip_install:__subpackages__"], -) - -filegroup( - name = "py_srcs", - srcs = glob( - include = ["**/*.py"], - exclude = ["**/*_test.py"], - ), - visibility = ["//python/pip_install:__subpackages__"], -) diff --git a/python/pip_install/extract_wheels/lib/__init__.py b/python/pip_install/extract_wheels/lib/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/python/pip_install/extract_wheels/lib/namespace_pkgs.py b/python/pip_install/extract_wheels/namespace_pkgs.py similarity index 100% rename from python/pip_install/extract_wheels/lib/namespace_pkgs.py rename to python/pip_install/extract_wheels/namespace_pkgs.py diff --git a/python/pip_install/extract_wheels/lib/namespace_pkgs_test.py b/python/pip_install/extract_wheels/namespace_pkgs_test.py similarity index 98% rename from python/pip_install/extract_wheels/lib/namespace_pkgs_test.py rename to python/pip_install/extract_wheels/namespace_pkgs_test.py index 815fe62b7e..8a9d97ca39 100644 --- a/python/pip_install/extract_wheels/lib/namespace_pkgs_test.py +++ b/python/pip_install/extract_wheels/namespace_pkgs_test.py @@ -5,7 +5,7 @@ import unittest from typing import Optional, Set -from python.pip_install.extract_wheels.lib import namespace_pkgs +from python.pip_install.extract_wheels import namespace_pkgs class TempDir: diff --git a/python/pip_install/parse_requirements_to_bzl/__init__.py b/python/pip_install/extract_wheels/parse_requirements_to_bzl.py similarity index 97% rename from python/pip_install/parse_requirements_to_bzl/__init__.py rename to python/pip_install/extract_wheels/parse_requirements_to_bzl.py index 07ee92d9d0..1a756e55d4 100644 --- a/python/pip_install/parse_requirements_to_bzl/__init__.py +++ b/python/pip_install/extract_wheels/parse_requirements_to_bzl.py @@ -16,7 +16,7 @@ ) from pip._internal.req.req_install import InstallRequirement -from python.pip_install.extract_wheels.lib import annotation, arguments, bazel +from python.pip_install.extract_wheels import annotation, arguments, bazel def parse_install_requirements( @@ -270,3 +270,8 @@ def main(output: TextIO) -> None: annotations=annotated_requirements, ) ) + + +if __name__ == "__main__": + with open("requirements.bzl", "w") as requirement_file: + main(requirement_file) diff --git a/python/pip_install/parse_requirements_to_bzl/parse_requirements_to_bzl_test.py b/python/pip_install/extract_wheels/parse_requirements_to_bzl_test.py similarity index 98% rename from python/pip_install/parse_requirements_to_bzl/parse_requirements_to_bzl_test.py rename to python/pip_install/extract_wheels/parse_requirements_to_bzl_test.py index fb22d63c07..74158a6855 100644 --- a/python/pip_install/parse_requirements_to_bzl/parse_requirements_to_bzl_test.py +++ b/python/pip_install/extract_wheels/parse_requirements_to_bzl_test.py @@ -7,7 +7,7 @@ from pip._internal.req.req_install import InstallRequirement -from python.pip_install.parse_requirements_to_bzl import ( +from python.pip_install.extract_wheels.parse_requirements_to_bzl import ( generate_parsed_requirements_contents, parse_install_requirements, parse_whl_library_args, diff --git a/python/pip_install/extract_wheels/lib/requirements.py b/python/pip_install/extract_wheels/requirements.py similarity index 100% rename from python/pip_install/extract_wheels/lib/requirements.py rename to python/pip_install/extract_wheels/requirements.py diff --git a/python/pip_install/extract_wheels/lib/requirements_bzl_test.py b/python/pip_install/extract_wheels/requirements_bzl_test.py similarity index 90% rename from python/pip_install/extract_wheels/lib/requirements_bzl_test.py rename to python/pip_install/extract_wheels/requirements_bzl_test.py index d753f6f0aa..ae28e1fc38 100644 --- a/python/pip_install/extract_wheels/lib/requirements_bzl_test.py +++ b/python/pip_install/extract_wheels/requirements_bzl_test.py @@ -1,6 +1,6 @@ import unittest -from python.pip_install.extract_wheels.lib import bazel +from python.pip_install.extract_wheels import bazel class TestGenerateRequirementsFileContents(unittest.TestCase): diff --git a/python/pip_install/extract_wheels/lib/requirements_test.py b/python/pip_install/extract_wheels/requirements_test.py similarity index 95% rename from python/pip_install/extract_wheels/lib/requirements_test.py rename to python/pip_install/extract_wheels/requirements_test.py index 4fe4d92e32..297cd91c38 100644 --- a/python/pip_install/extract_wheels/lib/requirements_test.py +++ b/python/pip_install/extract_wheels/requirements_test.py @@ -1,6 +1,6 @@ import unittest -from python.pip_install.extract_wheels.lib import requirements +from python.pip_install.extract_wheels import requirements class TestRequirementExtrasParsing(unittest.TestCase): diff --git a/python/pip_install/extract_wheels/lib/wheel.py b/python/pip_install/extract_wheels/wheel.py similarity index 100% rename from python/pip_install/extract_wheels/lib/wheel.py rename to python/pip_install/extract_wheels/wheel.py diff --git a/python/pip_install/extract_wheels/lib/whl_filegroup_test.py b/python/pip_install/extract_wheels/whl_filegroup_test.py similarity index 96% rename from python/pip_install/extract_wheels/lib/whl_filegroup_test.py rename to python/pip_install/extract_wheels/whl_filegroup_test.py index f5577136ff..2a7ade3b27 100644 --- a/python/pip_install/extract_wheels/lib/whl_filegroup_test.py +++ b/python/pip_install/extract_wheels/whl_filegroup_test.py @@ -4,7 +4,7 @@ import unittest from pathlib import Path -from python.pip_install.extract_wheels.lib import bazel +from python.pip_install.extract_wheels import bazel class TestWhlFilegroup(unittest.TestCase): diff --git a/python/pip_install/parse_requirements_to_bzl/BUILD b/python/pip_install/parse_requirements_to_bzl/BUILD deleted file mode 100644 index 8a876abfe7..0000000000 --- a/python/pip_install/parse_requirements_to_bzl/BUILD +++ /dev/null @@ -1,54 +0,0 @@ -load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") -load("//python/pip_install:repositories.bzl", "requirement") - -py_binary( - name = "parse_requirements_to_bzl", - srcs = [ - "__init__.py", - "__main__.py", - ], - main = "__main__.py", - deps = ["//python/pip_install/extract_wheels/lib"], -) - -py_library( - name = "lib", - srcs = ["__init__.py"], - visibility = ["//python/pip_install/extract_wheels:__subpackages__"], - deps = [requirement("pip")], -) - -py_test( - name = "parse_requirements_to_bzl_test", - size = "small", - srcs = [ - "parse_requirements_to_bzl_test.py", - ], - tags = ["unit"], - deps = [ - ":lib", - "//python/pip_install/extract_wheels/lib", - ], -) - -filegroup( - name = "distribution", - srcs = glob( - ["*"], - exclude = ["*_test.py"], - ) + [ - "//python/pip_install/parse_requirements_to_bzl/extract_single_wheel:distribution", - ], - visibility = ["//python/pip_install:__subpackages__"], -) - -filegroup( - name = "py_srcs", - srcs = glob( - include = ["**/*.py"], - exclude = ["**/*_test.py"], - ) + [ - "//python/pip_install/parse_requirements_to_bzl/extract_single_wheel:py_srcs", - ], - visibility = ["//python/pip_install:__subpackages__"], -) diff --git a/python/pip_install/parse_requirements_to_bzl/__main__.py b/python/pip_install/parse_requirements_to_bzl/__main__.py deleted file mode 100644 index aaa6bf4500..0000000000 --- a/python/pip_install/parse_requirements_to_bzl/__main__.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Main entry point.""" -import os -import sys - -from python.pip_install.parse_requirements_to_bzl import main - -if __name__ == "__main__": - with open("requirements.bzl", "w") as requirement_file: - main(requirement_file) diff --git a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/BUILD b/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/BUILD deleted file mode 100644 index bc0f640f81..0000000000 --- a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/BUILD +++ /dev/null @@ -1,17 +0,0 @@ -filegroup( - name = "distribution", - srcs = glob( - ["*"], - exclude = ["*_test.py"], - ), - visibility = ["//python/pip_install:__subpackages__"], -) - -filegroup( - name = "py_srcs", - srcs = glob( - include = ["**/*.py"], - exclude = ["**/*_test.py"], - ), - visibility = ["//python/pip_install:__subpackages__"], -) diff --git a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__main__.py b/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__main__.py deleted file mode 100644 index d45f90bbd1..0000000000 --- a/python/pip_install/parse_requirements_to_bzl/extract_single_wheel/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from python.pip_install.parse_requirements_to_bzl.extract_single_wheel import main - -if __name__ == "__main__": - main() diff --git a/python/pip_install/pip_repository.bzl b/python/pip_install/pip_repository.bzl index 743d3e3787..8b7479ad9f 100644 --- a/python/pip_install/pip_repository.bzl +++ b/python/pip_install/pip_repository.bzl @@ -187,7 +187,7 @@ def _pip_repository_impl(rctx): args = [ python_interpreter, "-m", - "python.pip_install.parse_requirements_to_bzl", + "python.pip_install.extract_wheels.parse_requirements_to_bzl", "--requirements_lock", rctx.path(requirements_txt), "--requirements_lock_label", @@ -209,7 +209,7 @@ def _pip_repository_impl(rctx): args = [ python_interpreter, "-m", - "python.pip_install.extract_wheels", + "python.pip_install.extract_wheels.extract_wheels", "--requirements", rctx.path(rctx.attr.requirements), "--annotations", @@ -410,7 +410,7 @@ def _whl_library_impl(rctx): args = [ python_interpreter, "-m", - "python.pip_install.parse_requirements_to_bzl.extract_single_wheel", + "python.pip_install.extract_wheels.extract_single_wheel", "--requirement", rctx.attr.requirement, "--repo", diff --git a/python/pip_install/private/srcs.bzl b/python/pip_install/private/srcs.bzl index a253b66bbb..bdd76b17d4 100644 --- a/python/pip_install/private/srcs.bzl +++ b/python/pip_install/private/srcs.bzl @@ -8,16 +8,13 @@ This file is auto-generated from the `@rules_python//python/pip_install/private: # sources changed. PIP_INSTALL_PY_SRCS = [ "@rules_python//python/pip_install/extract_wheels:__init__.py", - "@rules_python//python/pip_install/extract_wheels:__main__.py", - "@rules_python//python/pip_install/extract_wheels/lib:__init__.py", - "@rules_python//python/pip_install/extract_wheels/lib:annotation.py", - "@rules_python//python/pip_install/extract_wheels/lib:arguments.py", - "@rules_python//python/pip_install/extract_wheels/lib:bazel.py", - "@rules_python//python/pip_install/extract_wheels/lib:namespace_pkgs.py", - "@rules_python//python/pip_install/extract_wheels/lib:requirements.py", - "@rules_python//python/pip_install/extract_wheels/lib:wheel.py", - "@rules_python//python/pip_install/parse_requirements_to_bzl:__init__.py", - "@rules_python//python/pip_install/parse_requirements_to_bzl:__main__.py", - "@rules_python//python/pip_install/parse_requirements_to_bzl/extract_single_wheel:__init__.py", - "@rules_python//python/pip_install/parse_requirements_to_bzl/extract_single_wheel:__main__.py", + "@rules_python//python/pip_install/extract_wheels:annotation.py", + "@rules_python//python/pip_install/extract_wheels:arguments.py", + "@rules_python//python/pip_install/extract_wheels:bazel.py", + "@rules_python//python/pip_install/extract_wheels:extract_single_wheel.py", + "@rules_python//python/pip_install/extract_wheels:extract_wheels.py", + "@rules_python//python/pip_install/extract_wheels:namespace_pkgs.py", + "@rules_python//python/pip_install/extract_wheels:parse_requirements_to_bzl.py", + "@rules_python//python/pip_install/extract_wheels:requirements.py", + "@rules_python//python/pip_install/extract_wheels:wheel.py", ]