anki/pylib/anki/BUILD.bazel
Damien Elmes 7ac1fa17e6 move proto files into separate py_library in same namespace
Will allow importing the Protobuf without pulling in the rest of
the library. This is not a full PEP420 namespace, and the wheel still
bundles everything - it just makes things easier in a Bazel workspace.
I originally tried with PEP420, but it required more invasive changes,
and I ran into issues with mypy.
2021-07-11 14:51:25 +10:00

131 lines
2.9 KiB
Python

load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_python//python:defs.bzl", "py_library")
load("@py_deps//:requirements.bzl", "requirement")
load("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel")
load("//:defs.bzl", "anki_version")
load("//pylib:orjson.bzl", "orjson_if_available")
load("//pylib:protobuf.bzl", "py_proto")
copy_file(
name = "buildinfo",
src = "//:buildinfo.txt",
out = "buildinfo.txt",
)
genrule(
name = "hooks_gen",
outs = ["hooks_gen.py"],
cmd = "$(location //pylib/tools:genhooks) $@",
tools = ["//pylib/tools:genhooks"],
)
_py_srcs = glob(
["**/*.py"],
exclude = [
"hooks_gen.py",
],
)
py_library(
name = "anki",
srcs = _py_srcs,
data = [
"py.typed",
":buildinfo",
":hooks_gen",
"//pylib/anki/_backend",
],
imports = [
"..",
],
visibility = ["//visibility:public"],
deps = [
":proto",
requirement("beautifulsoup4"),
requirement("decorator"),
requirement("distro"),
requirement("protobuf"),
requirement("requests"),
requirement("flask"),
requirement("waitress"),
requirement("markdown"),
requirement("stringcase"),
] + orjson_if_available(),
)
py_package(
name = "anki_pkg",
packages = ["pylib.anki"],
deps = [":anki"],
)
py_wheel(
name = "wheel",
abi = "abi3",
description_file = "wheel_description.txt",
distribution = "anki",
extra_requires = {
"syncserver": [
"flask",
"waitress",
],
},
platform = select({
"//platforms:windows_x86_64": "win_amd64",
"//platforms:macos_x86_64": "macosx_10_7_x86_64",
"//platforms:linux_x86_64": "manylinux2014_x86_64",
"//platforms:linux_arm64": "manylinux2014_aarch64",
}),
python_tag = "cp38",
python_version = ">=3.8",
requires = [
"beautifulsoup4",
"requests[socks]",
"decorator",
"protobuf",
"markdown",
"stringcase",
'orjson; platform_machine == "x86_64"',
'psutil; sys_platform == "win32"',
'distro; sys_platform != "darwin" and sys_platform != "win32"',
],
strip_path_prefixes = [
"pylib/",
],
tags = ["manual"],
version = anki_version,
visibility = ["//visibility:public"],
deps = [":anki_pkg"],
)
filegroup(
name = "py_source_files",
srcs = _py_srcs + [
"//pylib/anki/_backend:py_source_files",
],
visibility = [
"//pylib:__subpackages__",
],
)
py_proto(
name = "proto_py",
srcs = ["//proto"],
visibility = [
"//visibility:public",
],
)
py_library(
name = "proto",
srcs = [
"__init__.py",
# includes the .py files
":proto_py",
],
# includes the .pyi files
data = [":proto_py", "py.typed"],
imports = [".."],
visibility = ["//visibility:public"],
)