Skip to content

Commit 2133714

Browse files
authored
Add plugin mechanism. (#35)
The motivation is to be able to discover ci_command's on the PYTHONPATH provided by packages outside of fireci.
1 parent 79d1166 commit 2133714

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

ci/fireci/fireci/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
from .internal import ci_command

ci/fireci/fireci/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717

1818
from . import gradle
19-
from .internal import ci_command
19+
from . import ci_command
2020

2121

2222
@click.argument('task', required=True, nargs=-1)

ci/fireci/fireci/gradle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
ADB_INSTALL_TIMEOUT = '5'
2323

2424

25+
def P(name, value):
26+
"""Returns name and value in the format of gradle's project property cli argument."""
27+
return '-P{}={}'.format(name, value)
28+
29+
2530
def run(*args, gradle_opts='', workdir=None):
2631
"""Invokes gradle with specified args and gradle_opts."""
2732
new_env = dict(os.environ)

ci/fireci/fireci/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
import logging
1616

1717
from . import commands
18+
from . import plugins
1819
from .internal import main
1920

2021
logging.basicConfig(
2122
format='%(name)s: [%(levelname)s] %(message)s',
2223
level=logging.DEBUG,
2324
)
2425

26+
plugins.discover()
27+
2528
cli = main

ci/fireci/fireci/plugins.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import importlib
16+
import pkgutil
17+
import fireciplugins
18+
19+
20+
def discover():
21+
"""Discovers fireci plugins available on PYTHONPATH under firebaseplugins subpackages.
22+
23+
Discovery works by importing all direct subpackages of firebaseplugins and importing them,
24+
plugins are supposed to register ci_command's with fireci in their __init__.py files directly
25+
or by importing from their own subpackages.
26+
27+
Note: plugins *must* define the `firebaseplugins` package as a namespace package.
28+
See: https://packaging.python.org/guides/packaging-namespace-packages/
29+
"""
30+
modules = pkgutil.iter_modules(fireciplugins.__path__,
31+
fireciplugins.__name__ + ".")
32+
for module in modules:
33+
importlib.import_module(module.name)

ci/fireci/fireciplugins/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

0 commit comments

Comments
 (0)