Repository: grapl-security/grapl (language: python)

Issue:
Ensure that manage_virtualenv.sh runs from the repository root
Previously, if the script was executed from another
directory (particularly `build-support` itself), it would fail, but
leave behind an extra `venv` directory, which caused subsequent
problems with Pants.

Now, all the logic takes place from the repository root, eliminating
these issues.

Signed-off-by: Christopher Maier <chris@graplsecurity.com>



Discussion / hints:

Fix patch:
diff --git a/.buildkite/scripts/build_and_upload_containers.sh b/.buildkite/scripts/build_and_upload_containers.sh
index d1771b4727..d4a29c3e13 100755
--- a/.buildkite/scripts/build_and_upload_containers.sh
+++ b/.buildkite/scripts/build_and_upload_containers.sh
@@ -41,8 +41,10 @@ cloudsmith_tag() {
     local -r tag="${2}"
     echo "${CLOUDSMITH_DOCKER_REGISTRY}/${service}:${tag}"
 }
-echo "--- :python: Building required Python wheels"
-make build-python-wheels
+
+# These are then consumed by src/python/Dockerfile
+echo "--- :python: Building pex binaries"
+make build-service-pexs
 
 for service in "${services[@]}"; do
     # Build a single service
diff --git a/Makefile b/Makefile
index 00d489bb35..32a0c9f151 100644
--- a/Makefile
+++ b/Makefile
@@ -149,13 +149,8 @@ build-test-unit-js:
 	$(DOCKER_BUILDX_BAKE) \
 		--file ./test/docker-compose.unit-tests-js.yml
 
-.PHONY: build-test-typecheck
-build-test-typecheck: build-python-wheels
-	$(DOCKER_BUILDX_BAKE) \
-		--file ./test/docker-compose.typecheck-tests.yml
-
 .PHONY: build-test-integration
-build-test-integration: build-local
+build-test-integration: build
 	$(WITH_LOCAL_GRAPL_ENV) \
 	$(DOCKER_BUILDX_BAKE) --file ./test/docker-compose.integration-tests.build.yml
 
@@ -196,18 +191,9 @@ build-lambda-zips-js: ## Build JS lambda zips
 		graphql-endpoint-zip
 
 .PHONY: build-lambda-zips-python
-build-lambda-zips-python: build-python-wheels ## Build Python lambda zips
+build-lambda-zips-python: ## Build Python lambda zips
 	./pants filter --target-type=python_awslambda :: | xargs ./pants package
 
-.PHONY: build-python-wheels
-build-python-wheels:  ## Build all Python wheels
-	./pants filter --target-type=python_distribution :: | xargs ./pants package
-
-.PHONY: build-docker-images-local
-build-docker-images-local:
-	$(WITH_LOCAL_GRAPL_ENV) \
-	$(MAKE) build-docker-images
-
 .PHONY: build-docker-images
 build-docker-images: graplctl build-ux
 	$(DOCKER_BUILDX_BAKE) --file docker-compose.build.yml
@@ -215,9 +201,6 @@ build-docker-images: graplctl build-ux
 .PHONY: build
 build: build-lambda-zips build-docker-images ## Build Grapl services
 
-.PHONY: build-local
-build-local: build-lambda-zips build-docker-images-local ## Build Grapl services
-
 .PHONY: build-formatter
 build-formatter:
 	$(DOCKER_BUILDX_BAKE) \
@@ -414,7 +397,7 @@ up: build ## Build Grapl services and launch docker-compose up
 	docker-compose -f docker-compose.yml up
 
 .PHONY: up-detach
-up-detach: build-local ## Bring up local Grapl and detach to return control to tty
+up-detach: build ## Bring up local Grapl and detach to return control to tty
 	# Primarily used for bringing up an environment for integration testing.
 	# For use with a project name consider setting COMPOSE_PROJECT_NAME env var
 	# Usage: `make up-detach`
diff --git a/build-support/manage_virtualenv.sh b/build-support/manage_virtualenv.sh
index ed4f2500ef..547a4a37b1 100755
--- a/build-support/manage_virtualenv.sh
+++ b/build-support/manage_virtualenv.sh
@@ -99,18 +99,24 @@ EOF
 
 }
 
-case "${1:-help}" in
-    populate)
-        populate
-        ;;
-    regenerate-constraints)
-        regenerate_constraints
-        ;;
-    help)
-        usage
-        ;;
-    *)
-        usage
-        exit 1
-        ;;
-esac
+REPOSITORY_ROOT=$(git rev-parse --show-toplevel)
+readonly REPOSITORY_ROOT
+
+(
+    cd "${REPOSITORY_ROOT}"
+    case "${1:-help}" in
+        populate)
+            populate
+            ;;
+        regenerate-constraints)
+            regenerate_constraints
+            ;;
+        help)
+            usage
+            ;;
+        *)
+            usage
+            exit 1
+            ;;
+    esac
+)


Test patch:
diff --git a/src/python/python-proto/python_proto/tests/strategies.py b/src/python/python-proto/python_proto/tests/strategies.py
index e8d17bf70f..68fa3b1149 100644
--- a/src/python/python-proto/python_proto/tests/strategies.py
+++ b/src/python/python-proto/python_proto/tests/strategies.py
@@ -39,6 +39,7 @@
 UINT64_MAX = 2 ** 64 - 1
 INT64_MIN = -(2 ** 63) - 1
 INT64_MAX = 2 ** 63 - 1
+MAX_LIST_SIZE = 5
 
 #
 # pipeline
@@ -82,7 +83,9 @@ def envelopes(
 
 
 def sessions(
-    primary_key_properties: st.SearchStrategy[Sequence[str]] = st.lists(st.text()),
+    primary_key_properties: st.SearchStrategy[Sequence[str]] = st.lists(
+        st.text(), max_size=MAX_LIST_SIZE
+    ),
     primary_key_requires_asset_ids: st.SearchStrategy[bool] = st.booleans(),
     create_times: st.SearchStrategy[int] = st.integers(
         min_value=UINT64_MIN, max_value=UINT64_MAX
@@ -105,7 +108,9 @@ def sessions(
 
 
 def statics(
-    primary_key_properties: st.SearchStrategy[Sequence[str]] = st.lists(st.text()),
+    primary_key_properties: st.SearchStrategy[Sequence[str]] = st.lists(
+        st.text(), max_size=MAX_LIST_SIZE
+    ),
     primary_key_requires_asset_ids: st.SearchStrategy[bool] = st.booleans(),
 ) -> st.SearchStrategy[Static]:
     return st.builds(
@@ -210,7 +215,9 @@ def node_descriptions(
     ),
     node_keys: st.SearchStrategy[str] = st.text(),
     node_types: st.SearchStrategy[str] = st.text(),
-    id_strategies: st.SearchStrategy[Sequence[IdStrategy]] = st.lists(id_strategies()),
+    id_strategies: st.SearchStrategy[Sequence[IdStrategy]] = st.lists(
+        id_strategies(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[NodeDescription]:
     return st.builds(
         NodeDescription,
@@ -269,7 +276,9 @@ def edges(
 
 
 def edge_lists(
-    edges: st.SearchStrategy[Sequence[Edge]] = st.lists(edges()),
+    edges: st.SearchStrategy[Sequence[Edge]] = st.lists(
+        edges(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[EdgeList]:
     return st.builds(
         EdgeList,
@@ -295,7 +304,9 @@ def merged_edges(
 
 
 def merged_edge_lists(
-    edges: st.SearchStrategy[Sequence[MergedEdge]] = st.lists(merged_edges()),
+    edges: st.SearchStrategy[Sequence[MergedEdge]] = st.lists(
+        merged_edges(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[MergedEdgeList]:
     return st.builds(
         MergedEdgeList,
@@ -365,7 +376,9 @@ def counters(
     increments: st.SearchStrategy[int] = st.integers(
         min_value=UINT64_MIN, max_value=UINT64_MAX
     ),
-    labels: st.SearchStrategy[Sequence[Label]] = st.lists(labels()),
+    labels: st.SearchStrategy[Sequence[Label]] = st.lists(
+        labels(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[Counter]:
     return st.builds(Counter, name=names, increment=increments, labels=labels)
 
@@ -378,7 +391,9 @@ def gauges(
     gauge_types: st.SearchStrategy[GaugeType] = gauge_types(),
     names: st.SearchStrategy[str] = st.text(),
     values: st.SearchStrategy[float] = st.floats(allow_nan=False, allow_infinity=False),
-    labels: st.SearchStrategy[Sequence[Label]] = st.lists(labels()),
+    labels: st.SearchStrategy[Sequence[Label]] = st.lists(
+        labels(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[Gauge]:
     return st.builds(
         Gauge, gauge_type=gauge_types, name=names, value=values, labels=labels
@@ -388,7 +403,9 @@ def gauges(
 def histograms(
     names: st.SearchStrategy[str] = st.text(),
     values: st.SearchStrategy[float] = st.floats(allow_nan=False, allow_infinity=False),
-    labels: st.SearchStrategy[Sequence[Label]] = st.lists(labels()),
+    labels: st.SearchStrategy[Sequence[Label]] = st.lists(
+        labels(), max_size=MAX_LIST_SIZE
+    ),
 ) -> st.SearchStrategy[Histogram]:
     return st.builds(Histogram, name=names, value=values, labels=labels)