Skip to content

Add plugin mechanism. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/fireci/fireci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ci/fireci/fireci/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions ci/fireci/fireci/gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ci/fireci/fireci/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import logging

from . import commands
from . import plugins
from .internal import main

logging.basicConfig(
format='%(name)s: [%(levelname)s] %(message)s',
level=logging.DEBUG,
)

plugins.discover()

cli = main
33 changes: 33 additions & 0 deletions ci/fireci/fireci/plugins.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions ci/fireci/fireciplugins/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)