Add Python venv
Bug: b/287529705
Change-Id: I288158cc26defe38816341059af7743601fcd388
Reviewed-on: https://pigweed-review.googlesource.com/c/open-dice/+/152191
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/BUILD.gn b/BUILD.gn
index 4787252..6b02dd1 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -14,12 +14,16 @@
import("//build_overrides/pigweed.gni")
import("$dir_pw_bloat/bloat.gni")
+import("$dir_pw_build/python.gni")
+import("$dir_pw_build/python_dist.gni")
+import("$dir_pw_build/python_venv.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_unit_test/test.gni")
group("default") {
deps = [
":fuzzers(//toolchains:host_fuzz)",
+ ":python.install",
":optimized_libs(//toolchains:host_optimized)",
":tests.run(//toolchains:host_debug)",
]
@@ -535,3 +539,57 @@
"//src/android:bcc",
]
}
+
+# This group is built during bootstrap to setup the interactive Python
+# environment.
+pw_python_group("python") {
+ python_deps = [
+ ":pip_install_open_dice_tools",
+ ]
+}
+
+# In-tree Python packages
+_open_dice_python_packages = [ "//tools:tools" ]
+
+# Pigweed Python packages to include
+_pigweed_python_packages = [
+ "$dir_pw_env_setup:core_pigweed_python_packages",
+]
+
+_all_python_packages = _open_dice_python_packages + _pigweed_python_packages
+
+# The default venv for Python actions in GN
+# Set this gn arg in a declare_args block in this file 'BUILD.gn' or in '.gn' to
+# use this venv.
+#
+# pw_build_PYTHON_BUILD_VENV = "//:sample_project_build_venv"
+#
+pw_python_venv("open_dice_build_venv") {
+ path = "$root_build_dir/python-venv"
+ constraints = pw_build_PIP_CONSTRAINTS
+ requirements = pw_build_PIP_REQUIREMENTS
+
+ # Ensure all third party Python dependencies are installed into this venv.
+ # This works by checking the setup.cfg files for all packages listed here and
+ # installing the packages listed in the [options].install_requires field.
+ source_packages = _all_python_packages
+}
+
+# This template collects all python packages and their dependencies into a
+# single super Python package for installation into the bootstrapped virtual
+# environment.
+pw_python_distribution("generate_open_dice_tools_python_distribution") {
+ packages = _all_python_packages
+ generate_setup_cfg = {
+ name = "open-dice-tools"
+ version = "0.0.1"
+ append_date_to_version = true
+ include_default_pyproject_file = true
+ }
+}
+
+# Install the open-dice-tools super Python package into the bootstrapped Python
+# venv.
+pw_internal_pip_install("pip_install_open_dice_tools") {
+ packages = [ ":generate_open_dice_tools_python_distribution" ]
+}
diff --git a/tools/BUILD.gn b/tools/BUILD.gn
new file mode 100644
index 0000000..c3a1d8d
--- /dev/null
+++ b/tools/BUILD.gn
@@ -0,0 +1,34 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
+
+import("//build_overrides/pigweed.gni")
+
+import("$dir_pw_build/python.gni")
+
+pw_python_package("tools") {
+ setup = [
+ "pyproject.toml",
+ "setup.cfg",
+ "setup.py",
+ ]
+ sources = [
+ "open_dice_tools/__init__.py",
+ "open_dice_tools/presubmit.py",
+ ]
+ python_deps = [
+ "$dir_pw_cli/py",
+ "$dir_pw_presubmit/py",
+ ]
+ pylintrc = "$dir_pigweed/.pylintrc"
+}
diff --git a/tools/open_dice_tools/__init__.py b/tools/open_dice_tools/__init__.py
new file mode 100644
index 0000000..c3e1bdb
--- /dev/null
+++ b/tools/open_dice_tools/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
diff --git a/tools/open_dice_tools/presubmit.py b/tools/open_dice_tools/presubmit.py
new file mode 100644
index 0000000..c3e1bdb
--- /dev/null
+++ b/tools/open_dice_tools/presubmit.py
@@ -0,0 +1,13 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
diff --git a/tools/pyproject.toml b/tools/pyproject.toml
new file mode 100644
index 0000000..78668a7
--- /dev/null
+++ b/tools/pyproject.toml
@@ -0,0 +1,16 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
+[build-system]
+requires = ['setuptools', 'wheel']
+build-backend = 'setuptools.build_meta'
diff --git a/tools/setup.cfg b/tools/setup.cfg
new file mode 100644
index 0000000..17c00a1
--- /dev/null
+++ b/tools/setup.cfg
@@ -0,0 +1,32 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
+[metadata]
+name = sample_project_tools
+version = 0.0.1
+author = Pigweed Authors
+author_email = pigweed-developers@googlegroups.com
+description = Utilities for Sample Project development
+
+[options]
+packages = find:
+zip_safe = False
+install_requires =
+
+[options.entry_points]
+console_scripts =
+ find-files = sample_project_tools.find_files:main
+
+[options.package_data]
+sample_project_tools =
+ py.typed
diff --git a/tools/setup.py b/tools/setup.py
new file mode 100644
index 0000000..7faefad
--- /dev/null
+++ b/tools/setup.py
@@ -0,0 +1,18 @@
+# Copyright 2023 The Pigweed 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
+#
+# https://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.
+"""Utilities for Sample Project development."""
+
+import setuptools # type: ignore
+
+setuptools.setup() # Package definition in setup.cfg