-
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial @rules for Options computation via the engine.
- Loading branch information
Showing
9 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import collections | ||
|
||
from pants.engine.rules import RootRule, rule | ||
from pants.engine.selectors import Select | ||
from pants.init.options_initializer import OptionsInitializer | ||
from pants.option.options_bootstrapper import OptionsBootstrapper | ||
from pants.util.objects import datatype | ||
|
||
|
||
class OptionsParseRequest(datatype(['args', 'env'])): | ||
"""Represents a request for Options computation.""" | ||
|
||
@classmethod | ||
def create(cls, args, env): | ||
assert isinstance(args, (list, tuple)) | ||
return cls( | ||
tuple(args), | ||
tuple(env.items() if isinstance(env, dict) else env) | ||
) | ||
|
||
|
||
class Options(datatype(['options', 'build_config'])): | ||
"""Represents the result of an Options computation.""" | ||
|
||
|
||
@rule(Options, [Select(OptionsParseRequest)]) | ||
def parse_options(parse_request): | ||
options_bootstrapper = OptionsBootstrapper( | ||
env=dict(parse_request.env), | ||
args=parse_request.args | ||
) | ||
options_initializer = OptionsInitializer(options_bootstrapper) | ||
options, build_config = options_initializer.setup(init_logging=False, init_subsystems=False) | ||
options.freeze() | ||
return Options(options, build_config) | ||
|
||
|
||
def create_options_parsing_rules(): | ||
return [ | ||
parse_options, | ||
RootRule(Options), | ||
RootRule(OptionsParseRequest), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/python/pants_test/engine/legacy/test_options_parsing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import os | ||
import unittest | ||
from contextlib import contextmanager | ||
|
||
from pants.base.build_environment import get_buildroot | ||
from pants.engine.legacy.options_parsing import Options, OptionsParseRequest | ||
from pants.init.engine_initializer import EngineInitializer | ||
from pants_test.engine.util import init_native | ||
|
||
|
||
class TestEngineOptionsParsing(unittest.TestCase): | ||
|
||
_native = init_native() | ||
|
||
@contextmanager | ||
def scheduler(self, build_root=None, native=_native): | ||
build_root = build_root or get_buildroot() | ||
work_dir = os.path.join(build_root, '.pants.d') | ||
scheduler = EngineInitializer.setup_legacy_graph( | ||
[], | ||
work_dir, | ||
build_file_imports_behavior='allow', | ||
build_root=build_root, | ||
native=native | ||
) | ||
yield scheduler.scheduler.new_session() | ||
|
||
def test_options_parsing_request(self): | ||
with self.scheduler() as scheduler: | ||
products = scheduler.product_request( | ||
Options, | ||
[ | ||
OptionsParseRequest.create( | ||
['./pants', '-ldebug', 'binary', 'src/python::'], | ||
dict(PANTS_ENABLE_PANTSD='True', PANTS_BINARIES_BASEURLS='["https://bins.com"]') | ||
) | ||
] | ||
) | ||
options = products[0].options | ||
self.assertIn('binary', options.goals) | ||
global_options = options.for_global_scope() | ||
self.assertEquals(global_options.level, 'debug') | ||
self.assertEquals(global_options.enable_pantsd, True) | ||
self.assertEquals(global_options.binaries_baseurls, ['https://bins.com']) |