blob: a90139005e67b233e94bb5d9c2caa8c6fc0c838a [file] [log] [blame]
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tools for tracking privacy budget.
load("@accounting_py_pip_deps//:requirements.bzl", "requirement")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
package(default_visibility = [
"//visibility:public",
])
licenses(["notice"])
# For specifying python version. When running with python version <= 3.6, should
# specify via this flag, e.g. --//dp_accounting:python_version=3.6
string_flag(
name = "python_version",
build_setting_default = "3.7",
)
config_setting(
name = "python_version_3.6",
flag_values = {
":python_version": "3.6",
},
)
# For python version 3.7 onwards, dataclasses module is already included as part
# of the core library.
DATACLASSES_DEP = select({
":python_version_3.6": [requirement("dataclasses")],
"//conditions:default": [],
})
py_library(
name = "common",
srcs = [
"common.py",
],
srcs_version = "PY3",
deps = [
requirement("numpy"),
requirement("scipy"),
] + DATACLASSES_DEP,
)
py_test(
name = "common_test",
size = "small",
srcs = ["common_test.py"],
python_version = "PY3",
deps = [
":common",
":test_util",
requirement("absl-py"),
],
)
py_library(
name = "privacy_loss_distribution",
srcs = [
"privacy_loss_distribution.py",
],
srcs_version = "PY3",
deps = [
":common",
":privacy_loss_mechanism",
requirement("numpy"),
],
)
py_test(
name = "privacy_loss_distribution_test",
size = "small",
srcs = ["privacy_loss_distribution_test.py"],
python_version = "PY3",
deps = [
":common",
":privacy_loss_distribution",
":test_util",
requirement("absl-py"),
requirement("scipy"),
],
)
py_library(
name = "privacy_loss_mechanism",
srcs = [
"privacy_loss_mechanism.py",
],
srcs_version = "PY3",
deps = [
":common",
requirement("numpy"),
requirement("scipy"),
] + DATACLASSES_DEP,
)
py_test(
name = "privacy_loss_mechanism_test",
size = "small",
srcs = ["privacy_loss_mechanism_test.py"],
python_version = "PY3",
deps = [
":common",
":privacy_loss_mechanism",
":test_util",
requirement("absl-py"),
requirement("scipy"),
],
)
py_library(
name = "accountant",
srcs = [
"accountant.py",
],
srcs_version = "PY3",
deps = [
":common",
":privacy_loss_distribution",
":privacy_loss_mechanism",
requirement("scipy"),
] + DATACLASSES_DEP,
)
py_test(
name = "accountant_test",
size = "small",
srcs = ["accountant_test.py"],
python_version = "PY3",
deps = [
":accountant",
":common",
":privacy_loss_mechanism",
requirement("absl-py"),
],
)
py_library(
name = "test_util",
srcs = [
"test_util.py",
],
srcs_version = "PY3",
deps = [requirement("numpy")],
)
py_test(
name = "test_util_test",
size = "small",
srcs = ["test_util_test.py"],
python_version = "PY3",
deps = [
":test_util",
requirement("absl-py"),
],
)
py_binary(
name = "privacy_loss_distribution_basic_example",
srcs = [
"privacy_loss_distribution_basic_example.py",
],
python_version = "PY3",
deps = [
":privacy_loss_distribution",
requirement("absl-py"),
],
)
py_library(
name = "dp_event",
srcs = ["dp_event.py"],
srcs_version = "PY3",
deps = [
requirement("attrs"),
],
)
py_library(
name = "dp_event_builder",
srcs = ["dp_event_builder.py"],
srcs_version = "PY3",
deps = [
":dp_event",
],
)
py_test(
name = "dp_event_builder_test",
srcs = ["dp_event_builder_test.py"],
python_version = "PY3",
srcs_version = "PY3",
deps = [
":dp_event",
":dp_event_builder",
requirement("absl-py"),
],
)
py_library(
name = "privacy_accountant",
srcs = ["privacy_accountant.py"],
srcs_version = "PY3",
deps = [
":dp_event",
":dp_event_builder",
],
)
py_library(
name = "privacy_accountant_test",
srcs = ["privacy_accountant_test.py"],
srcs_version = "PY3",
deps = [
":dp_event",
":privacy_accountant",
requirement("absl-py"),
],
)