Skip to content

Commit

Permalink
Split TensorFlow Privacy pypi package into two parts-- one for DP tra…
Browse files Browse the repository at this point in the history
…ining, and one for privacy tests.

PiperOrigin-RevId: 603100586
  • Loading branch information
schien1729 authored and tensorflower-gardener committed Feb 5, 2024
1 parent bbb1b48 commit e5974d9
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 9 deletions.
39 changes: 39 additions & 0 deletions pip_tools/build_empirical_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to build the TensorFlow Privacy/Privacy Tests pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Build the pip package
pip install --upgrade setuptools wheel
python "setup_empirical.py" sdist bdist_wheel

# Cleanup.
deactivate
}

main "$@"
39 changes: 39 additions & 0 deletions pip_tools/build_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to build the TensorFlow Privacy pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Build the pip package
pip install --upgrade setuptools wheel
python "setup.py" sdist bdist_wheel

# Cleanup.
deactivate
}

main "$@"
41 changes: 41 additions & 0 deletions pip_tools/publish_empirical_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to publish the TensorFlow Privacy pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Publish the pip package.
package="$(ls "dist/"*".whl" | head -n1)"
pip install --upgrade twine
twine check "${package}"
twine upload "${package}"

# Cleanup.
deactivate
}

main "$@"
41 changes: 41 additions & 0 deletions pip_tools/publish_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to publish the TensorFlow Privacy pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Publish the pip package.
package="$(ls "dist/"*".whl" | head -n1)"
pip install --upgrade twine
twine check "${package}"
twine upload "${package}"

# Cleanup.
deactivate
}

main "$@"
41 changes: 41 additions & 0 deletions pip_tools/test_empirical_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to build the TensorFlow Privacy pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Test the pip package.
package="$(ls "dist/"*".whl" | head -n1)"
pip install --upgrade "${package}"
pip freeze
python -c "import tensorflow_privacy.privacy.privacy_tests as pt; print(pt.__version__)"

# Cleanup.
deactivate
}

main "$@"
41 changes: 41 additions & 0 deletions pip_tools/test_pip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright 2020, The TensorFlow Privacy Authors.
#
# 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.
#
# Tool to build the TensorFlow Privacy pip package.
set -e

main() {
# Create a working directory.
local temp_dir="$(mktemp -d)"
trap "rm -rf ${temp_dir}" EXIT

# Create a virtual environment
python3.11 -m venv "${temp_dir}/venv"
source "${temp_dir}/venv/bin/activate"
python --version
pip install --upgrade pip
pip --version

# Test the pip package.
package="$(ls "dist/"*".whl" | head -n1)"
pip install --upgrade "${package}"
pip freeze
python -c "import tensorflow_privacy as tfp; print(tfp.__version__)"

# Cleanup.
deactivate
}

main "$@"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# `~=x.0`.

absl-py>=1.0,==1.*
attrs>=21.4
dm-tree==0.1.8
dp-accounting==0.4.3
immutabledict~=2.2
Expand Down
10 changes: 2 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
"""TensorFlow Privacy library setup file for pip."""
"""TensorFlow Privacy/DP Training library setup file for pip."""

import setuptools

Expand All @@ -33,24 +33,18 @@
long_description_content_type='text/plain',
url='https://github.com/tensorflow/privacy',
license='Apache-2.0',
packages=setuptools.find_packages(),
packages=setuptools.find_packages(exclude=['*privacy.privacy_tests*']),
install_requires=[
'absl-py>=1.0,==1.*',
'attrs>=21.4',
'dm-tree==0.1.8',
'dp-accounting==0.4.3',
'immutabledict~=2.2',
'matplotlib~=3.3',
'numpy~=1.21',
'packaging~=22.0',
'pandas~=1.4',
'scikit-learn>=1.0,==1.*',
'scipy~=1.9',
'statsmodels==0.14.0',
'tensorflow-estimator~=2.4',
'tensorflow-probability~=0.22.0',
'tensorflow~=2.4',
'tf-models-official~=2.13',
],
python_requires='>=3.9.0,<3.12',
)
53 changes: 53 additions & 0 deletions setup_empirical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024, The TensorFlow Authors.
#
# 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.
"""TensorFlow Privacy/Privacy Tests library setup file for pip."""

import setuptools

with open('tensorflow_privacy/privacy/privacy_tests/version.py') as file:
globals_dict = {}
exec(file.read(), globals_dict) # pylint: disable=exec-used
VERSION = globals_dict['__version__']

README = (
'A Python library that includes implementations of tests for empirical '
'privacy.'
)

setuptools.setup(
name='tensorflow_empirical_privacy',
version=VERSION,
description='Tests for empirical privacy.',
long_description=README,
long_description_content_type='text/plain',
url='https://github.com/tensorflow/privacy',
license='Apache-2.0',
packages=setuptools.find_packages(
where='privacy', include=['privacy_tests*']
),
install_requires=[
'absl-py>=1.0,==1.*',
'immutabledict~=2.2',
'matplotlib~=3.3',
'numpy~=1.21',
'pandas~=1.4',
'scikit-learn>=1.0,==1.*',
'scipy~=1.9',
'statsmodels==0.14.0',
'tensorflow~=2.4',
'tensorflow-privacy>=0.8.12',
'tf-models-official~=2.13',
],
python_requires='>=3.9.0,<3.12',
)
9 changes: 9 additions & 0 deletions tensorflow_privacy/privacy/privacy_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ licenses(["notice"])
py_library(
name = "privacy_tests",
srcs = ["__init__.py"],
deps = [
":version",
],
)

py_test(
Expand Down Expand Up @@ -32,3 +35,9 @@ py_library(
name = "epsilon_lower_bound",
srcs = ["epsilon_lower_bound.py"],
)

py_library(
name = "version",
srcs = ["version.py"],
srcs_version = "PY3",
)
3 changes: 3 additions & 0 deletions tensorflow_privacy/privacy/privacy_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
# 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.
"""TensorFlow Empirical Privacy."""

from tensorflow_privacy.privacy.privacy_tests.version import __version__ # pylint: disable=g-bad-import-order
16 changes: 16 additions & 0 deletions tensorflow_privacy/privacy/privacy_tests/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024, The TensorFlow Privacy Authors.
#
# 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.
"""TensorFlow Privacy/Privacy Tests version."""

__version__ = '0.1.0'

0 comments on commit e5974d9

Please sign in to comment.