diff --git a/ci/fireci/fireci/__init__.py b/ci/fireci/fireci/__init__.py index 2e94f3e551a..29ef4adc881 100644 --- a/ci/fireci/fireci/__init__.py +++ b/ci/fireci/fireci/__init__.py @@ -11,3 +11,5 @@ # 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 .internal import ci_command diff --git a/ci/fireci/fireci/commands.py b/ci/fireci/fireci/commands.py index 2ca748210e0..ceaa6ce4ce7 100644 --- a/ci/fireci/fireci/commands.py +++ b/ci/fireci/fireci/commands.py @@ -16,7 +16,7 @@ import os from . import gradle -from .internal import ci_command +from . import ci_command @click.argument('task', required=True, nargs=-1) diff --git a/ci/fireci/fireci/gradle.py b/ci/fireci/fireci/gradle.py index e9b5b915fe7..dcb7e1c6742 100644 --- a/ci/fireci/fireci/gradle.py +++ b/ci/fireci/fireci/gradle.py @@ -22,6 +22,11 @@ ADB_INSTALL_TIMEOUT = '5' +def P(name, value): + """Returns name and value in the format of gradle's project property cli argument.""" + return '-P{}={}'.format(name, value) + + def run(*args, gradle_opts='', workdir=None): """Invokes gradle with specified args and gradle_opts.""" new_env = dict(os.environ) diff --git a/ci/fireci/fireci/main.py b/ci/fireci/fireci/main.py index e8f61d9ae77..0f9ba16614a 100644 --- a/ci/fireci/fireci/main.py +++ b/ci/fireci/fireci/main.py @@ -15,6 +15,7 @@ import logging from . import commands +from . import plugins from .internal import main logging.basicConfig( @@ -22,4 +23,6 @@ level=logging.DEBUG, ) +plugins.discover() + cli = main diff --git a/ci/fireci/fireci/plugins.py b/ci/fireci/fireci/plugins.py new file mode 100644 index 00000000000..73ad79297ac --- /dev/null +++ b/ci/fireci/fireci/plugins.py @@ -0,0 +1,33 @@ +# Copyright 2018 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. + +import importlib +import pkgutil +import fireciplugins + + +def discover(): + """Discovers fireci plugins available on PYTHONPATH under firebaseplugins subpackages. + + Discovery works by importing all direct subpackages of firebaseplugins and importing them, + plugins are supposed to register ci_command's with fireci in their __init__.py files directly + or by importing from their own subpackages. + + Note: plugins *must* define the `firebaseplugins` package as a namespace package. + See: https://packaging.python.org/guides/packaging-namespace-packages/ + """ + modules = pkgutil.iter_modules(fireciplugins.__path__, + fireciplugins.__name__ + ".") + for module in modules: + importlib.import_module(module.name) diff --git a/ci/fireci/fireciplugins/__init__.py b/ci/fireci/fireciplugins/__init__.py new file mode 100644 index 00000000000..8bd4c961aab --- /dev/null +++ b/ci/fireci/fireciplugins/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2018 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. +__path__ = __import__('pkgutil').extend_path(__path__, __name__)