Diff
Modified: trunk/Tools/ChangeLog (279011 => 279012)
--- trunk/Tools/ChangeLog 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/ChangeLog 2021-06-17 22:03:03 UTC (rev 279012)
@@ -1,5 +1,23 @@
2021-06-17 Jonathan Bedard <jbed...@apple.com>
+ [resultsdbpy] Adopt autoinstaller
+ https://bugs.webkit.org/show_bug.cgi?id=227096
+ <rdar://problem/79418080>
+
+ Rubber-stamped by Aakash Jain.
+
+ * Scripts/libraries/resultsdbpy/container: Moved from insdie library.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py: Register required libraries.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/container: Moved to containing folder.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/example/main.py:
+ * Scripts/libraries/resultsdbpy/resultsdbpy/run: Moved to containing folder.
+ * Scripts/libraries/resultsdbpy/resultsdbpy/view/view_routes_unittest.py: Use specific imports
+ * Scripts/libraries/resultsdbpy/run: Moved from insdie library.
+ * Scripts/libraries/resultsdbpy/run-tests: Use autoinstalled libraries.
+ * Scripts/libraries/resultsdbpy/setup.py: Bump version.
+
+2021-06-17 Jonathan Bedard <jbed...@apple.com>
+
[webkitcorepy] Retry downloads in Autoinstall
https://bugs.webkit.org/show_bug.cgi?id=227134
<rdar://problem/79462182>
Copied: trunk/Tools/Scripts/libraries/resultsdbpy/container (from rev 279011, trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/container) (0 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/container (rev 0)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/container 2021-06-17 22:03:03 UTC (rev 279012)
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import argparse
+import os
+import sys
+
+import resultsdbpy
+from webkitcorepy import AutoInstall
+
+libraries = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), 'libraries')
+if sys.platform == 'darwin':
+ is_root = not os.getuid()
+ does_own_libraries = os.stat(libraries).st_uid == os.getuid()
+ if (is_root or not does_own_libraries):
+ libraries = os.path.expanduser('~/Library/webkitpy')
+AutoInstall.set_directory(os.path.join(libraries, 'autoinstalled', 'python-{}'.format(sys.version_info[0])))
+
+from resultsdbpy.model.docker import Docker
+
+
+def start():
+ Docker.start()
+ Docker.start_project(Docker.DEFAULT_PROJECT)
+ return 0
+
+
+def stop():
+ if not Docker.is_running():
+ print('Docker is not running')
+ return 1
+ Docker.stop_project(Docker.DEFAULT_PROJECT)
+ Docker.stop()
+ return 0
+
+
+def restart():
+ if not Docker.is_running():
+ Docker.start()
+ Docker.stop_project(Docker.DEFAULT_PROJECT)
+ Docker.start_project(Docker.DEFAULT_PROJECT)
+ return 0
+
+
+def main():
+ parser = argparse.ArgumentParser(description='Manage resultsdbpy container instance inside Docker')
+ subparsers = parser.add_subparsers(help='sub-command help')
+
+ start_parser = subparsers.add_parser('start', help='Start the container inside Docker')
+ start_parser.set_defaults(function=start)
+
+ start_parser = subparsers.add_parser('stop', help='Stop the container inside Docker')
+ start_parser.set_defaults(function=stop)
+
+ start_parser = subparsers.add_parser('restart', help='Restart the container inside Docker')
+ start_parser.set_defaults(function=restart)
+
+ return getattr(parser.parse_args(), 'function', lambda: parser.print_help())()
+
+
+if __name__ == '__main__':
+ sys.exit(main())
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/__init__.py 2021-06-17 22:03:03 UTC (rev 279012)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 Apple Inc. All rights reserved.
+# Copyright (C) 2019-2021 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -36,7 +36,7 @@
_maybe_add_webkit_python_library_paths()
try:
- from webkitcorepy.version import Version
+ from webkitcorepy import AutoInstall, Package, Version
except ImportError:
raise ImportError(
"'webkitcorepy' could not be found on your Python path.\n" +
@@ -44,6 +44,34 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(2, 0, 5)
+version = Version(3, 0, 0)
+import webkitflaskpy
+
+AutoInstall.register(Package('aenum', Version(2, 2, 6)))
+AutoInstall.register(Package('attrs', Version(21, 2, 0)))
+AutoInstall.register(Package('aioredis', Version(1, 3, 1)))
+AutoInstall.register(Package('async-timeout', Version(3, 0, 1)))
+AutoInstall.register(Package('boto3', Version(1, 16, 63), wheel=True))
+AutoInstall.register(Package('botocore', Version(1, 19, 63), wheel=True))
+AutoInstall.register(Package('cassandra', Version(3, 25, 0), pypi_name='cassandra-driver', slow_install=True))
+AutoInstall.register(Package('click', Version(7, 1, 2)))
+AutoInstall.register(Package('Crypto', Version(3, 10, 1), pypi_name='pycryptodome'))
+AutoInstall.register(Package('fakeredis', Version(1, 5, 2)))
+AutoInstall.register(Package('geomet', Version(0, 2, 1)))
+AutoInstall.register(Package('gremlinpython', Version(3, 4, 6)))
+AutoInstall.register(Package('hiredis', Version(1, 1, 0)))
+AutoInstall.register(Package('isodate', Version(0, 6, 0)))
+AutoInstall.register(Package('jmespath', Version(0, 10, 0), wheel=True))
+AutoInstall.register(Package('lupa', Version(1, 9)))
+AutoInstall.register(Package('pyasn1_modules', Version(0, 2, 8), pypi_name='pyasn1-modules'))
+AutoInstall.register(Package('redis', Version(3, 5, 3)))
+AutoInstall.register(Package('selenium', Version(3, 141, 0)))
+AutoInstall.register(Package('service_identity', Version(21, 1, 0), pypi_name='service-identity'))
+AutoInstall.register(Package('sortedcontainers', Version(2, 4, 0)))
+AutoInstall.register(Package('tornado', Version(4, 5, 3)))
+AutoInstall.register(Package('twisted', Version(21, 2, 0), pypi_name='Twisted', implicit_deps=[
+ Package('incremental', Version(21, 3, 0)),
+]))
+
name = 'resultsdbpy'
Deleted: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/container (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/container 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/container 2021-06-17 22:03:03 UTC (rev 279012)
@@ -1,73 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (C) 2020 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import argparse
-import os
-import sys
-sys.dont_write_bytecode = True
-
-from model.docker import Docker
-
-
-def start():
- Docker.start()
- Docker.start_project(Docker.DEFAULT_PROJECT)
- return 0
-
-
-def stop():
- if not Docker.is_running():
- print('Docker is not running')
- return 1
- Docker.stop_project(Docker.DEFAULT_PROJECT)
- Docker.stop()
- return 0
-
-
-def restart():
- if not Docker.is_running():
- Docker.start()
- Docker.stop_project(Docker.DEFAULT_PROJECT)
- Docker.start_project(Docker.DEFAULT_PROJECT)
- return 0
-
-
-def main():
- parser = argparse.ArgumentParser(description='Manage resultsdbpy container instance inside Docker')
- subparsers = parser.add_subparsers(help='sub-command help')
-
- start_parser = subparsers.add_parser('start', help='Start the container inside Docker')
- start_parser.set_defaults(function=start)
-
- start_parser = subparsers.add_parser('stop', help='Stop the container inside Docker')
- start_parser.set_defaults(function=stop)
-
- start_parser = subparsers.add_parser('restart', help='Restart the container inside Docker')
- start_parser.set_defaults(function=restart)
-
- return getattr(parser.parse_args(), 'function', lambda: parser.print_help())()
-
-
-if __name__ == '__main__':
- sys.exit(main())
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/example/main.py (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/example/main.py 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/example/main.py 2021-06-17 22:03:03 UTC (rev 279012)
@@ -23,7 +23,7 @@
import hashlib
import json
-from example.environment import Environment, ModelFromEnvironment
+from resultsdbpy.example.environment import Environment, ModelFromEnvironment
from flask import abort, Flask, request
from resultsdbpy.controller.api_routes import APIRoutes
from resultsdbpy.view.view_routes import ViewRoutes
Deleted: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/run (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/run 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/run 2021-06-17 22:03:03 UTC (rev 279012)
@@ -1,173 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (C) 2020 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import argparse
-import os
-import subprocess
-import sys
-import time
-import threading
-
-sys.dont_write_bytecode = True
-
-from model.docker import Docker
-from multiprocessing import Process
-from redis import StrictRedis
-
-
-class DockerIfNeededContext(object):
-
- def __init__(self, args):
- self.docker = Docker.instance() if 'localhost' in [args.cassandra_server, args.redis_server] else None
-
- def __enter__(self):
- if self.docker:
- self.docker.__enter__()
-
- def __exit__(self, *args, **kwargs):
- if self.docker:
- self.docker.__exit__(*args, **kwargs)
-
-
-def has_gunicorn():
- return not subprocess.run(['python3', '/usr/local/bin/gunicorns', '--version'], capture_output=True).returncode
-
-
-def parse_arguments():
- parser = argparse.ArgumentParser(description='Run a simple instance of the results database for local development')
- parser.add_argument(
- '--local-cassandra', help='Use a local Cassandra instance',
- dest='cassandra_server', action='', const='localhost',
- )
- parser.add_argument(
- '--mock-cassandra', help='Use a mock Cassandra instance',
- dest='cassandra_server', action='', const='mock',
- )
- parser.set_defaults(cassandra_server='localhost' if Docker.installed() else 'mock')
-
- parser.add_argument(
- '--local-redis', help='Use a local Redis instance',
- dest='redis_server', action='', const='localhost',
- )
- parser.add_argument(
- '--mock-redis', help='Use a mock Redis instance',
- dest='redis_server', action='', const='mock',
- )
- parser.set_defaults(redis_server='localhost' if Docker.installed() else 'mock')
-
- parser.add_argument(
- '--drop-keyspace', help='Drop the existing keyspace before running the program',
- dest='drop_keyspace', action='',
- )
- parser.add_argument(
- '--no-drop-keyspace', help='Do NOT drop the existing keyspace before running the program',
- dest='drop_keyspace', action='',
- )
- parser.set_defaults(drop_keyspace=False)
-
- parser.add_argument(
- '--clear-redis', help='Clear redis before running the application',
- dest='clear_redis', action='',
- )
- parser.add_argument(
- '--no-clear-redis',
- help='Do not clear redis before running the application',
- dest='clear_redis', action='',
- )
- parser.set_defaults(clear_redis=True)
-
- parser.add_argument(
- '--gunicorn', help='Use the gunicorn webserver',
- dest='gunicorn', action='',
- )
- parser.add_argument(
- '--no-gunicorn',
- help='Do not use the gunicorn webserver',
- dest='gunicorn', action='',
- )
- parser.set_defaults(gunicorn=has_gunicorn())
-
- return parser.parse_args()
-
-
-def do_work():
- from example.worker import main
- main()
-
-
-def web_app():
- from example.main import main
- return main()
-
-
-def gunicorn():
- if not has_gunicorn():
- print('gunicorn is not installed, please run `pip3 install gunicorn`')
- return 1
-
- # Slight delay so that the worker is started before the webserver
- time.sleep(2)
- return subprocess.run([
- 'python3', '/usr/local/bin/gunicorn',
- 'example.main:app',
- '--log-file=-', '--reload',
- ]).returncode
-
-
-def main():
- args = parse_arguments()
- with DockerIfNeededContext(args):
- os.environ['CASSANDRA_SERVER'] = args.cassandra_server
- os.environ['REDIS_HOST'] = args.redis_server
- os.environ['DROP_KEYSPACE'] = '1' if args.drop_keyspace else '0'
- os.environ['CREATE_KEYSPACE'] = '1' # Unconditionally create keyspace for testing
-
- if args.clear_redis and args.redis_server != 'mock':
- StrictRedis(host=args.redis_server).flushdb()
-
- if args.gunicorn:
- if 'mock' in [args.redis_server, args.cassandra_server]:
- raise RuntimeError('Cannot run with gunicorn and mock databases, asynchronous workers rely on the real databases')
-
- from example.environment import main as environment_main
- environment_main()
-
- if not args.gunicorn:
- worker = threading.Thread(target=do_work)
- worker.daemon = True
- worker.start()
-
- return web_app()
-
- worker = Process(target=do_work)
- worker.start()
-
- try:
- return gunicorn()
- finally:
- worker.terminate()
- worker.join()
-
-if __name__ == '__main__':
- sys.exit(main())
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/view_routes_unittest.py (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/view_routes_unittest.py 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/view/view_routes_unittest.py 2021-06-17 22:03:03 UTC (rev 279012)
@@ -22,9 +22,9 @@
import time
-from controller.api_routes import APIRoutes
from fakeredis import FakeStrictRedis
from redis import StrictRedis
+from resultsdbpy.controller.api_routes import APIRoutes
from resultsdbpy.flask_support.flask_testcase import FlaskTestCase
from resultsdbpy.model.cassandra_context import CassandraContext
from resultsdbpy.model.mock_cassandra_context import MockCassandraContext
Copied: trunk/Tools/Scripts/libraries/resultsdbpy/run (from rev 279011, trunk/Tools/Scripts/libraries/resultsdbpy/resultsdbpy/run) (0 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/run (rev 0)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/run 2021-06-17 22:03:03 UTC (rev 279012)
@@ -0,0 +1,182 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2020, 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import argparse
+import os
+import subprocess
+import sys
+import time
+import threading
+
+import resultsdbpy
+from webkitcorepy import AutoInstall
+
+libraries = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), 'libraries')
+if sys.platform == 'darwin':
+ is_root = not os.getuid()
+ does_own_libraries = os.stat(libraries).st_uid == os.getuid()
+ if (is_root or not does_own_libraries):
+ libraries = os.path.expanduser('~/Library/webkitpy')
+AutoInstall.set_directory(os.path.join(libraries, 'autoinstalled', 'python-{}'.format(sys.version_info[0])))
+
+from resultsdbpy.model.docker import Docker
+from multiprocessing import Process
+from redis import StrictRedis
+
+
+class DockerIfNeededContext(object):
+
+ def __init__(self, args):
+ self.docker = Docker.instance() if 'localhost' in [args.cassandra_server, args.redis_server] else None
+
+ def __enter__(self):
+ if self.docker:
+ self.docker.__enter__()
+
+ def __exit__(self, *args, **kwargs):
+ if self.docker:
+ self.docker.__exit__(*args, **kwargs)
+
+
+def has_gunicorn():
+ return not subprocess.run(['python3', '/usr/local/bin/gunicorns', '--version'], capture_output=True).returncode
+
+
+def parse_arguments():
+ parser = argparse.ArgumentParser(description='Run a simple instance of the results database for local development')
+ parser.add_argument(
+ '--local-cassandra', help='Use a local Cassandra instance',
+ dest='cassandra_server', action='', const='localhost',
+ )
+ parser.add_argument(
+ '--mock-cassandra', help='Use a mock Cassandra instance',
+ dest='cassandra_server', action='', const='mock',
+ )
+ parser.set_defaults(cassandra_server='localhost' if Docker.installed() else 'mock')
+
+ parser.add_argument(
+ '--local-redis', help='Use a local Redis instance',
+ dest='redis_server', action='', const='localhost',
+ )
+ parser.add_argument(
+ '--mock-redis', help='Use a mock Redis instance',
+ dest='redis_server', action='', const='mock',
+ )
+ parser.set_defaults(redis_server='localhost' if Docker.installed() else 'mock')
+
+ parser.add_argument(
+ '--drop-keyspace', help='Drop the existing keyspace before running the program',
+ dest='drop_keyspace', action='',
+ )
+ parser.add_argument(
+ '--no-drop-keyspace', help='Do NOT drop the existing keyspace before running the program',
+ dest='drop_keyspace', action='',
+ )
+ parser.set_defaults(drop_keyspace=False)
+
+ parser.add_argument(
+ '--clear-redis', help='Clear redis before running the application',
+ dest='clear_redis', action='',
+ )
+ parser.add_argument(
+ '--no-clear-redis',
+ help='Do not clear redis before running the application',
+ dest='clear_redis', action='',
+ )
+ parser.set_defaults(clear_redis=True)
+
+ parser.add_argument(
+ '--gunicorn', help='Use the gunicorn webserver',
+ dest='gunicorn', action='',
+ )
+ parser.add_argument(
+ '--no-gunicorn',
+ help='Do not use the gunicorn webserver',
+ dest='gunicorn', action='',
+ )
+ parser.set_defaults(gunicorn=has_gunicorn())
+
+ return parser.parse_args()
+
+
+def do_work():
+ from resultsdbpy.example.worker import main
+ main()
+
+
+def web_app():
+ from resultsdbpy.example.main import main
+ return main()
+
+
+def gunicorn():
+ if not has_gunicorn():
+ print('gunicorn is not installed, please run `pip3 install gunicorn`')
+ return 1
+
+ # Slight delay so that the worker is started before the webserver
+ time.sleep(2)
+ return subprocess.run([
+ 'python3', '/usr/local/bin/gunicorn',
+ 'example.main:app',
+ '--log-file=-', '--reload',
+ ]).returncode
+
+
+def main():
+ args = parse_arguments()
+ with DockerIfNeededContext(args):
+ os.environ['CASSANDRA_SERVER'] = args.cassandra_server
+ os.environ['REDIS_HOST'] = args.redis_server
+ os.environ['DROP_KEYSPACE'] = '1' if args.drop_keyspace else '0'
+ os.environ['CREATE_KEYSPACE'] = '1' # Unconditionally create keyspace for testing
+
+ if args.clear_redis and args.redis_server != 'mock':
+ StrictRedis(host=args.redis_server).flushdb()
+
+ if args.gunicorn:
+ if 'mock' in [args.redis_server, args.cassandra_server]:
+ raise RuntimeError('Cannot run with gunicorn and mock databases, asynchronous workers rely on the real databases')
+
+ from resultsdbpy.example.environment import main as environment_main
+ environment_main()
+
+ if not args.gunicorn:
+ worker = threading.Thread(target=do_work)
+ worker.daemon = True
+ worker.start()
+
+ return web_app()
+
+ worker = Process(target=do_work)
+ worker.start()
+
+ try:
+ return gunicorn()
+ finally:
+ worker.terminate()
+ worker.join()
+
+if __name__ == '__main__':
+ sys.exit(main())
Added: trunk/Tools/Scripts/libraries/resultsdbpy/run-tests (0 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/run-tests (rev 0)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/run-tests 2021-06-17 22:03:03 UTC (rev 279012)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2019-2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import sys
+sys.dont_write_bytecode = True
+
+import argparse
+import os
+import sys
+import unittest
+
+import resultsdbpy
+from webkitcorepy import AutoInstall
+
+libraries = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), 'libraries')
+if sys.platform == 'darwin':
+ is_root = not os.getuid()
+ does_own_libraries = os.stat(libraries).st_uid == os.getuid()
+ if (is_root or not does_own_libraries):
+ libraries = os.path.expanduser('~/Library/webkitpy')
+AutoInstall.set_directory(os.path.join(libraries, 'autoinstalled', 'python-{}'.format(sys.version_info[0])))
+
+from cassandra.cqlengine.management import CQLENG_ALLOW_SCHEMA_MANAGEMENT
+
+
+def main():
+ parser = argparse.ArgumentParser(description='Run unit tests for resultsdbpy')
+ parser.add_argument('-v', '--verbose',
+ default=False, action='',
+ help='Verbose output')
+ parser.add_argument('--stop-on-fail',
+ default=False, action='',
+ help='Stop on first fail or error')
+ parser.add_argument('modules_to_test', nargs='*',
+ help='Modules to be tested. By default, this is the database, flask_support, model and view modules',
+ default=['controller', 'flask_support', 'model', 'view'])
+ parser.add_argument('-f', '--fast-tests',
+ default=False, action='',
+ help='Some tests require a docker instance and are slow, optionally skip these')
+ parser.add_argument('--no-web-server',
+ dest='web_server', default=True, action='',
+ help='Some tests use a Flask webserver, optionally skip these')
+ parser.add_argument('--no-selenium',
+ dest='selenium', default=True, action='',
+ help='Some tests use Selenium to test the UI of the site, optionally skip these')
+ options = parser.parse_args()
+
+ os.environ['slow_tests'] = '0' if options.fast_tests else '1'
+ os.environ['web_server'] = '1' if options.web_server else '0'
+ os.environ['selenium'] = '1' if options.selenium else '0'
+ os.environ[CQLENG_ALLOW_SCHEMA_MANAGEMENT] = '1'
+
+ root = os.path.dirname(os.path.abspath(__file__))
+
+ suite = unittest.TestSuite()
+ for module_name in options.modules_to_test:
+ module_suite = unittest.defaultTestLoader.discover(os.path.join(root, 'resultsdbpy', module_name.replace('.', '/')), pattern='*unittest.py', top_level_dir=os.path.join(root))
+ for tst in module_suite if module_suite else []:
+ suite.addTest(tst)
+
+ if suite.countTestCases() == 0:
+ raise RuntimeError('No tests matching...')
+
+ result = unittest.TextTestRunner(verbosity=2 if options.verbose else 1, failfast=options.stop_on_fail, buffer=not options.verbose).run(suite)
+ return len(result.errors)
+
+if __name__ == '__main__':
+ sys.exit(main())
Property changes on: trunk/Tools/Scripts/libraries/resultsdbpy/run-tests
___________________________________________________________________
Added: svn:executable
+*
\ No newline at end of property
Modified: trunk/Tools/Scripts/libraries/resultsdbpy/setup.py (279011 => 279012)
--- trunk/Tools/Scripts/libraries/resultsdbpy/setup.py 2021-06-17 22:01:55 UTC (rev 279011)
+++ trunk/Tools/Scripts/libraries/resultsdbpy/setup.py 2021-06-17 22:03:03 UTC (rev 279012)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2020 Apple Inc. All rights reserved.
+# Copyright (C) 2019-2021 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -30,7 +30,7 @@
setup(
name='resultsdbpy',
- version='2.0.5',
+ version='3.0.0',
description='Library for visualizing, processing and storing test results.',
long_description=readme(),
classifiers=[