From 47cf1438d0eb3c5ee6f50b312507e04755925022 Mon Sep 17 00:00:00 2001 From: ace-n Date: Wed, 20 Jan 2021 13:19:29 -0800 Subject: [PATCH] chore(GAE flex): rm unused memcache sample --- appengine/flexible/memcache/README.md | 49 ----- appengine/flexible/memcache/app.yaml | 16 -- appengine/flexible/memcache/main.py | 60 ------ appengine/flexible/memcache/main_test.py | 41 ----- appengine/flexible/memcache/noxfile.py | 171 ------------------ .../flexible/memcache/requirements-test.txt | 1 - appengine/flexible/memcache/requirements.txt | 3 - 7 files changed, 341 deletions(-) delete mode 100644 appengine/flexible/memcache/README.md delete mode 100644 appengine/flexible/memcache/app.yaml delete mode 100644 appengine/flexible/memcache/main.py delete mode 100644 appengine/flexible/memcache/main_test.py delete mode 100644 appengine/flexible/memcache/noxfile.py delete mode 100644 appengine/flexible/memcache/requirements-test.txt delete mode 100644 appengine/flexible/memcache/requirements.txt diff --git a/appengine/flexible/memcache/README.md b/appengine/flexible/memcache/README.md deleted file mode 100644 index 1bea0c2e99b..00000000000 --- a/appengine/flexible/memcache/README.md +++ /dev/null @@ -1,49 +0,0 @@ -## Note - -[![Open in Cloud Shell][shell_img]][shell_link] - -[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/flexible/memcache/README.md - -This sample demonstrates connecting to existing Memcache servers, or the -built-in Memcache server. - -A managed option for Memcache is RedisLabs: - -https://cloud.google.com/appengine/docs/flexible/python/using-redislabs-memcache - -You can install and manage a Memcache server on Google Compute Engine. One way -to do so is to use a Bitnami click-to-deploy: - -https://bitnami.com/stack/memcached/cloud/google - -Built-in Memcache for Flexible environments is currently in a allowlist-only alpha. To have your project allowlisted, -see the signup form here: - -https://cloud.google.com/appengine/docs/flexible/python/upgrading#memcache_service - -## Running locally - -Refer to the [top-level README](../README.md) for instructions on running and deploying. - -When running locally, you can use the [Google Cloud SDK](https://cloud.google.com/sdk) to provide authentication to use Google Cloud APIs: - - $ gcloud init - -Install dependencies, preferably with a virtualenv: - - $ virtualenv env - $ source env/bin/activate - $ pip install -r requirements.txt - -Start your application: - - $ python main.py - -## Deploying on App Engine - -Deploy using `gcloud`: - - gcloud app deploy - -You can now access the application at `https://your-app-id.appspot.com`. diff --git a/appengine/flexible/memcache/app.yaml b/appengine/flexible/memcache/app.yaml deleted file mode 100644 index e13699063d3..00000000000 --- a/appengine/flexible/memcache/app.yaml +++ /dev/null @@ -1,16 +0,0 @@ -runtime: python -env: flex -entrypoint: gunicorn -b :$PORT main:app - -runtime_config: - python_version: 3 - -# [START gae_flex_redislabs_memcache_yaml] -env_variables: - MEMCACHE_SERVER: your-memcache-server - # If you are using a third-party or self-hosted Memcached server with SASL - # authentiation enabled, uncomment and fill in these values with your - # username and password. - # MEMCACHE_USERNAME: your-memcache-username - # MEMCACHE_PASSWORD: your-memcache-password -# [END gae_flex_redislabs_memcache_yaml] diff --git a/appengine/flexible/memcache/main.py b/appengine/flexible/memcache/main.py deleted file mode 100644 index 3fa566a619a..00000000000 --- a/appengine/flexible/memcache/main.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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. - -import logging -import os - -from flask import Flask -import pylibmc - -app = Flask(__name__) - - -# [START gae_flex_redislabs_memcache] -# Environment variables are defined in app.yaml. -MEMCACHE_SERVER = os.environ.get('MEMCACHE_SERVER', 'localhost:11211') -MEMCACHE_USERNAME = os.environ.get('MEMCACHE_USERNAME') -MEMCACHE_PASSWORD = os.environ.get('MEMCACHE_PASSWORD') - -memcache_client = pylibmc.Client( - [MEMCACHE_SERVER], binary=True, - username=MEMCACHE_USERNAME, password=MEMCACHE_PASSWORD) -# [END gae_flex_redislabs_memcache] - - -@app.route('/') -def index(): - - # Set initial value if necessary - if not memcache_client.get('counter'): - memcache_client.set('counter', 0) - - value = memcache_client.incr('counter', 1) - - return 'Value is {}'.format(value) - - -@app.errorhandler(500) -def server_error(e): - logging.exception('An error occurred during a request.') - return """ - An internal error occurred:
{}
- See logs for full stacktrace. - """.format(e), 500 - - -if __name__ == '__main__': - # This is used when running locally. Gunicorn is used to run the - # application on Google App Engine. See entrypoint in app.yaml. - app.run(host='127.0.0.1', port=8080, debug=True) diff --git a/appengine/flexible/memcache/main_test.py b/appengine/flexible/memcache/main_test.py deleted file mode 100644 index f78f53ee294..00000000000 --- a/appengine/flexible/memcache/main_test.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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. - -import pytest - -try: - import main -except ImportError: - main = None - - -@pytest.mark.skipif( - not main, - reason='pylibmc not installed.') -def test_index(): - try: - main.memcache_client.set('counter', 0) - except Exception: - pytest.skip('Memcache is unavailable.') - - main.app.testing = True - client = main.app.test_client() - - r = client.get('/') - assert r.status_code == 200 - assert '1' in r.data.decode('utf-8') - - r = client.get('/') - assert r.status_code == 200 - assert '2' in r.data.decode('utf-8') diff --git a/appengine/flexible/memcache/noxfile.py b/appengine/flexible/memcache/noxfile.py deleted file mode 100644 index e3bf811ab99..00000000000 --- a/appengine/flexible/memcache/noxfile.py +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright 2019 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. - -from __future__ import print_function - -import os -from pathlib import Path - -import nox - - -# DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] - -# Any default versions that should be ignored. -IGNORED_VERSIONS = ["2.7", "3.8"] - -TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) - -# -# Style Checks -# - - -def _determine_local_import_names(start_dir): - """Determines all import names that should be considered "local". - - This is used when running the linter to insure that import order is - properly checked. - """ - file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] - return [ - basename - for basename, extension in file_ext_pairs - if extension == ".py" - or os.path.isdir(os.path.join(start_dir, basename)) - and basename not in ("__pycache__") - ] - - -# Linting with flake8. -# -# We ignore the following rules: -# E203: whitespace before ‘:’ -# E266: too many leading ‘#’ for block comment -# E501: line too long -# I202: Additional newline in a section of imports -# -# We also need to specify the rules which are ignored by default: -# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] -FLAKE8_COMMON_ARGS = [ - "--show-source", - "--builtin=gettext", - "--max-complexity=20", - "--import-order-style=google", - "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", - "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", - "--max-line-length=88", -] - - -@nox.session -def lint(session): - session.install("flake8", "flake8-import-order") - - local_names = _determine_local_import_names(".") - args = FLAKE8_COMMON_ARGS + [ - "--application-import-names", - ",".join(local_names), - ".", - ] - session.run("flake8", *args) - - -# -# Black -# - -@nox.session -def blacken(session): - session.install("black") - python_files = [path for path in os.listdir(".") if path.endswith(".py")] - - session.run("black", *python_files) - - -# -# Sample Tests -# - - -PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] - - -def _session_tests(session, post_install=None): - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5] - ) - - -@nox.session(python=ALL_VERSIONS) -def py(session): - """Runs py.test for a sample using the specified version of Python.""" - if session.python in TESTED_VERSIONS: - _session_tests(session) - else: - print("SKIPPED: {} tests are disabled for this sample.".format(session.python)) - - -# -# Readmegen -# - - -def _get_repo_root(): - """ Returns the root folder of the project. """ - # Get root of this repository. Assume we don't have directories nested deeper than 10 items. - p = Path(os.getcwd()) - for i in range(10): - if p is None: - break - if Path(p / ".git").exists(): - return str(p) - p = p.parent - raise Exception("Unable to detect repository root.") - - -GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) - - -@nox.session -@nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): - """(Re-)generates the readme for a sample.""" - session.install("jinja2", "pyyaml") - dir_ = os.path.dirname(path) - - if os.path.exists(os.path.join(dir_, "requirements.txt")): - session.install("-r", os.path.join(dir_, "requirements.txt")) - - in_file = os.path.join(dir_, "README.rst.in") - session.run( - "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file - ) diff --git a/appengine/flexible/memcache/requirements-test.txt b/appengine/flexible/memcache/requirements-test.txt deleted file mode 100644 index d5bd56fd179..00000000000 --- a/appengine/flexible/memcache/requirements-test.txt +++ /dev/null @@ -1 +0,0 @@ -pytest==6.2.1 diff --git a/appengine/flexible/memcache/requirements.txt b/appengine/flexible/memcache/requirements.txt deleted file mode 100644 index fec6bdd82ce..00000000000 --- a/appengine/flexible/memcache/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -Flask==1.1.2 -gunicorn==20.0.4 -pylibmc==1.6.1