Anki/pylib/anki/BUILD.bazel
RumovZ 9dc3cf216a
PEP8 for rest of pylib (#1451)
* PEP8 dbproxy.py

* PEP8 errors.py

* PEP8 httpclient.py

* PEP8 lang.py

* PEP8 latex.py

* Add decorator to deprectate key words

* Make replacement for deprecated attribute optional

* Use new helper `_print_replacement_warning()`

* PEP8 media.py

* PEP8 rsbackend.py

* PEP8 sound.py

* PEP8 stdmodels.py

* PEP8 storage.py

* PEP8 sync.py

* PEP8 tags.py

* PEP8 template.py

* PEP8 types.py

* Fix DeprecatedNamesMixinForModule

The class methods need to be overridden with instance methods, so every
module has its own dicts.

* Use `# pylint: disable=invalid-name` instead of id

* PEP8 utils.py

* Only decorate `__getattr__` with `@no_type_check`

* Fix mypy issue with snakecase

Importing it from `anki._vendor` raises attribute errors.

* Format

* Remove inheritance of DeprecatedNamesMixin

There's almost no shared code now and overriding classmethods with
instance methods raises mypy issues.

* Fix traceback frames of deprecation warnings

* remove fn/TimedLog (dae)

Neither Anki nor add-ons appear to have been using it

* fix some issues with stringcase use (dae)

- the wheel was depending on the PyPI version instead of our vendored
version
- _vendor:stringcase should not have been listed in the anki py_library.
We already include the sources in py_srcs, and need to refer to them
directly. By listing _vendor:stringcase as well, we were making a
top-level stringcase library available, which would have only worked for
distributing because the wheel definition was also incorrect.
- mypy errors are what caused me to mistakenly add the above - they
were because the type: ignore at the top of stringcase.py was causing
mypy to completely ignore the file, so it was not aware of any attributes
it contained.
2021-10-25 14:50:13 +10:00

131 lines
2.9 KiB
Text

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//python:packaging.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",
],
) + ["//pylib/anki/_vendor"]
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"),
] + 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_13_x86_64",
"//platforms:linux_x86_64": "manylinux_2_28_x86_64",
# Built on a Debian 11 image that has Qt 5.15
"//platforms:linux_arm64": "manylinux_2_31_aarch64",
}),
python_tag = "cp39",
requires = [
"beautifulsoup4",
"requests[socks]",
"decorator",
"protobuf>=3.17",
"markdown",
"orjson",
'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 = [
"py.typed",
":proto_py",
],
imports = [".."],
visibility = ["//visibility:public"],
)