Skip to content
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

Add a hook to allow pants customizations to inject backends. #182

Closed
Closed
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
3 changes: 3 additions & 0 deletions src/python/pants/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ python_library(
python_library(
name = 'dev_backend_loader',
sources = ['dev_backend_loader.py'],
dependencies = [
pants('3rdparty/python/twitter/commons:twitter.common.collections'),
]
)

python_library(
Expand Down
18 changes: 16 additions & 2 deletions src/python/pants/base/dev_backend_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (nested_scopes, generators, division, absolute_import, with_statement,
print_function, unicode_literals)

def load_backends_from_source(build_file_parser):
from twitter.common.collections import OrderedSet


def load_backends_from_source(build_file_parser, additional_backends=None):
"""Installs pants backend packages to provide targets and helper functions to BUILD files and
goals to the cli.

:param build_file_parser: The parser to populate with target aliases and helper functions from
the backends.
:param additional_backends: An optional list of additional packages to load backends from.
"""
print("Loading pants backends from source")
backend_packages = [
'pants.backend.core',
Expand All @@ -9,7 +23,7 @@ def load_backends_from_source(build_file_parser):
'pants.backend.codegen',
'pants.backend.maven_layout',
]
for backend_package in backend_packages:
for backend_package in OrderedSet(backend_packages + (additional_backends or [])):
module = __import__(backend_package + '.register',
{}, # globals
{}, # locals
Expand Down
3 changes: 2 additions & 1 deletion src/python/pants/bin/pants_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def _run():
build_file_parser = BuildFileParser(root_dir=root_dir, run_tracker=run_tracker)
build_graph = BuildGraph(run_tracker=run_tracker)

load_backends_from_source(build_file_parser)
additional_backends = config.getlist('backends', 'packages')
load_backends_from_source(build_file_parser, additional_backends=additional_backends)

command_class, command_args = _parse_command(root_dir, argv)
command = command_class(run_tracker,
Expand Down