From 5bb8b4bd58a170eee7454dbfade04dfdaf561ae2 Mon Sep 17 00:00:00 2001 From: Joao Antunes Date: Thu, 12 Oct 2023 10:53:13 -0600 Subject: [PATCH 1/4] Updated python example --- examples/python/python.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/python/python.py b/examples/python/python.py index e62cc05a5b..6ea7362813 100644 --- a/examples/python/python.py +++ b/examples/python/python.py @@ -2,6 +2,16 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +# How to run this example +# 1 - Build the docker image by running the command "docker build -t fsouza/fake-gcs-server ." +# 2 - Start the docker container: "docker run -d --name fake-gcs-server -p 4443:4443 -v ${PWD}/examples/data:/data fsouza/fake-gcs-server -scheme http" +# 3 - Check if it's working by running: "curl http://0.0.0.0:4443/storage/v1/b" +# 4 - Create a python virtual enviroment (Ex: python -m .venv venv) +# 5 - Source the env (source .venv/bin/activate) +# 7 - Go to the following directory examples/python: (cd examples/python) +# 6 - Install requirements: "pip install -r requirements.txt" and "pip install -r requirements.in" +# 7 - Run this script + import tempfile from google.auth.credentials import AnonymousCredentials @@ -10,6 +20,9 @@ client = storage.Client( credentials=AnonymousCredentials(), project="test", + # This endpoint assumes that you are using the default port 4443 from the container. + # If you are using a different port you need to update this endpoint + client_options={"api_endpoint": "http://localhost:4443"}, ) # List the Buckets From 5d37c28262cdae5aa2a92090825f1524515e3d1b Mon Sep 17 00:00:00 2001 From: Joao Antunes Date: Mon, 23 Oct 2023 11:21:20 -0600 Subject: [PATCH 2/4] Addressed PR comments --- examples/python/python.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/python/python.py b/examples/python/python.py index 6ea7362813..9509b226f8 100644 --- a/examples/python/python.py +++ b/examples/python/python.py @@ -12,17 +12,28 @@ # 6 - Install requirements: "pip install -r requirements.txt" and "pip install -r requirements.in" # 7 - Run this script +# For additional info on how to run this example or setup the docker container check the +# run script "ci/run-python-example.sh" + import tempfile +import os from google.auth.credentials import AnonymousCredentials from google.cloud import storage +# This endpoint assumes that you are using the default port 4443 from the container. +# If you are using a different port you need to update this endpoint +os.environ["STORAGE_EMULATOR_HOST"] = os.environ.get( + "STORAGE_EMULATOR_HOST", "http://localhost:4443" +) + + client = storage.Client( credentials=AnonymousCredentials(), project="test", - # This endpoint assumes that you are using the default port 4443 from the container. - # If you are using a different port you need to update this endpoint - client_options={"api_endpoint": "http://localhost:4443"}, + # Alternatively instead of using the global env STORAGE_EMULATOR_HOST. You can define it here. + # This will set this client object to point to the local google cloud storage. + # client_options={"api_endpoint": "http://localhost:4443"}, ) # List the Buckets From 5a45b09a6e630361b7951f0dfdf69bcd165b2a43 Mon Sep 17 00:00:00 2001 From: fsouza <108725+fsouza@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:41:20 -0400 Subject: [PATCH 3/4] Use `os.environ.setdefault` --- examples/python/python.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/python/python.py b/examples/python/python.py index 9509b226f8..2422c489b1 100644 --- a/examples/python/python.py +++ b/examples/python/python.py @@ -22,10 +22,8 @@ from google.cloud import storage # This endpoint assumes that you are using the default port 4443 from the container. -# If you are using a different port you need to update this endpoint -os.environ["STORAGE_EMULATOR_HOST"] = os.environ.get( - "STORAGE_EMULATOR_HOST", "http://localhost:4443" -) +# If you are using a different port, please set the environment variable STORAGE_EMULATOR_HOST. +os.environ.setdefault("STORAGE_EMULATOR_HOST", "http://localhost:4443") client = storage.Client( From 61fbd9cf9b812222935bcacfc4645a87cca69e2d Mon Sep 17 00:00:00 2001 From: fsouza <108725+fsouza@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:48:09 -0400 Subject: [PATCH 4/4] examples/python: remove reference to requirements.in --- examples/python/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/python/python.py b/examples/python/python.py index 2422c489b1..e1743d9997 100644 --- a/examples/python/python.py +++ b/examples/python/python.py @@ -9,7 +9,7 @@ # 4 - Create a python virtual enviroment (Ex: python -m .venv venv) # 5 - Source the env (source .venv/bin/activate) # 7 - Go to the following directory examples/python: (cd examples/python) -# 6 - Install requirements: "pip install -r requirements.txt" and "pip install -r requirements.in" +# 6 - Install requirements: "pip install -r requirements.txt" # 7 - Run this script # For additional info on how to run this example or setup the docker container check the