Switch zaza to a namespaced package (#763)

This is to remove the need to sync the __init__.py file between zaza and
zaza.openstack.tests.  This PR is to enable zaza.openstack to be a
properly namespaces module.
This commit is contained in:
Alex Kavanagh
2022-07-06 15:22:35 +01:00
committed by GitHub
parent b829fae632
commit 703c4a9477
2 changed files with 6 additions and 112 deletions

View File

@@ -20,7 +20,7 @@ from __future__ import print_function
import os
import sys
from setuptools import setup, find_packages
from setuptools import setup, find_namespace_packages
from setuptools.command.test import test as TestCommand
version = "0.0.1.dev1"
@@ -61,7 +61,8 @@ install_require = [
'python-ceilometerclient',
'python-cinderclient<6.0.0',
'python-swiftclient<3.9.0',
'zaza@git+https://github.com/openstack-charmers/zaza.git#egg=zaza',
# 'zaza@git+https://github.com/openstack-charmers/zaza.git#egg=zaza',
'zaza',
]
tests_require = [
@@ -114,7 +115,9 @@ if sys.argv[-1] == 'tag':
setup(
license='Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0',
packages=find_packages(exclude=["unit_tests"]),
# name='zaza-openstack-tests',
name='zaza.openstack',
packages=find_namespace_packages(include=['zaza.*'], exclude=["unit_tests"]),
zip_safe=False,
include_package_data=True,
cmdclass={'test': Tox},

View File

@@ -1,109 +0,0 @@
# Copyright 2018 Canonical Ltd.
#
# 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.
# __NOTE__
#
# Whenever this file is changed, make sure to update the copy of it in
# ``zaza-openstack-tests``.
#
# The ``zaza`` and ``zaza-openstack-tests`` projects are related, and currently
# the latter is installed as a package inside the former. As a consequence
# ``zaza-openstack-tests`` needs to carry a copy of this file
# (``zaza/__init__.py``) as this file will be overwritten by the copy in
# ``zaza-openstack-tests`` on install.
#
# We of course want a better solution to this, but in the interest of time
# this note is left here until we get around to fixing it properly.
#
# __NOTE__
"""Functions to support converting async function to a sync equivalent."""
import asyncio
import logging
from pkgutil import extend_path
from sys import version_info
__path__ = extend_path(__path__, __name__)
def run(*steps):
"""Run the given steps in an asyncio loop.
If the tasks spawns other future (tasks) then these are also cleaned up
after each step is performed.
:returns: The result of the last asyncio.Task
:rtype: Any
"""
if not steps:
return
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
except AttributeError:
# Remove once support for Python 3.6 is dropped
loop = asyncio.get_event_loop()
for step in steps:
task = loop.create_task(step)
loop.run_until_complete(asyncio.wait([task]))
# Let's also cancel any remaining tasks:
while True:
# issue #445 - asyncio.Task.all_tasks() deprecated in 3.7
if version_info.major == 3 and version_info.minor >= 7:
try:
tasklist = asyncio.all_tasks()
except RuntimeError:
# no running event loop
break
else:
tasklist = asyncio.Task.all_tasks()
pending_tasks = [p for p in tasklist if not p.done()]
if pending_tasks:
logging.info(
"async -> sync. cleaning up pending tasks: len: {}"
.format(len(pending_tasks)))
for pending_task in pending_tasks:
pending_task.cancel()
try:
loop.run_until_complete(pending_task)
except asyncio.CancelledError:
pass
except Exception as e:
logging.error(
"A pending task caused an exception: {}"
.format(str(e)))
else:
break
return task.result()
def sync_wrapper(f):
"""Convert the given async function into a sync function.
This is only to be called from sync code and it runs all tasks (and cancels
all tasks at the end of each run) for the code that is being given.
:returns: The de-async'd function
:rtype: function
"""
def _wrapper(*args, **kwargs):
async def _run_it():
return await f(*args, **kwargs)
return run(_run_it())
return _wrapper