| OLD | NEW |
| 1 # Copyright 2013-2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2013-2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import contextlib | 6 import contextlib |
| 7 import imp | 7 import imp |
| 8 import inspect | 8 import inspect |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 from .config import ConfigContext, ConfigGroupSchema | 12 from .config import ConfigContext, ConfigGroupSchema |
| 13 from .config_types import Path, ModuleBasePath, PackageBasePath | 13 from .config_types import Path, ModuleBasePath, PackageRepoBasePath |
| 14 from .config_types import RECIPE_MODULE_PREFIX | 14 from .config_types import RECIPE_MODULE_PREFIX |
| 15 from .recipe_api import RecipeApi, RecipeApiPlain, RecipeScriptApi | 15 from .recipe_api import RecipeApi, RecipeApiPlain, RecipeScriptApi |
| 16 from .recipe_api import Property, BoundProperty | 16 from .recipe_api import Property, BoundProperty |
| 17 from .recipe_api import UndefinedPropertyException, PROPERTY_SENTINEL | 17 from .recipe_api import UndefinedPropertyException, PROPERTY_SENTINEL |
| 18 from .recipe_test_api import RecipeTestApi, DisabledTestData | 18 from .recipe_test_api import RecipeTestApi, DisabledTestData |
| 19 from .util import scan_directory | 19 from .util import scan_directory |
| 20 | 20 |
| 21 | 21 |
| 22 class LoaderError(Exception): | 22 class LoaderError(Exception): |
| 23 """Raised when something goes wrong loading recipes or modules.""" | 23 """Raised when something goes wrong loading recipes or modules.""" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 API, CONFIG_CTX, TEST_API, and PROPERTIES. | 349 API, CONFIG_CTX, TEST_API, and PROPERTIES. |
| 350 | 350 |
| 351 |submod| is a recipe module (akin to python package) with submodules such as | 351 |submod| is a recipe module (akin to python package) with submodules such as |
| 352 'api', 'config', 'test_api'. This function scans through dicts of that | 352 'api', 'config', 'test_api'. This function scans through dicts of that |
| 353 submodules to find subclasses of RecipeApi, RecipeTestApi, etc. | 353 submodules to find subclasses of RecipeApi, RecipeTestApi, etc. |
| 354 """ | 354 """ |
| 355 fullname = '%s/%s' % (universe_view.package.name, name) | 355 fullname = '%s/%s' % (universe_view.package.name, name) |
| 356 submod.NAME = name | 356 submod.NAME = name |
| 357 submod.UNIQUE_NAME = fullname | 357 submod.UNIQUE_NAME = fullname |
| 358 submod.MODULE_DIRECTORY = Path(ModuleBasePath(submod)) | 358 submod.MODULE_DIRECTORY = Path(ModuleBasePath(submod)) |
| 359 submod.PACKAGE_DIRECTORY = Path(PackageBasePath(universe_view.package)) | 359 submod.PACKAGE_REPO_ROOT = Path(PackageRepoBasePath(universe_view.package)) |
| 360 submod.CONFIG_CTX = getattr(submod, 'CONFIG_CTX', None) | 360 submod.CONFIG_CTX = getattr(submod, 'CONFIG_CTX', None) |
| 361 | 361 |
| 362 if hasattr(submod, 'config'): | 362 if hasattr(submod, 'config'): |
| 363 for v in submod.config.__dict__.itervalues(): | 363 for v in submod.config.__dict__.itervalues(): |
| 364 if isinstance(v, ConfigContext): | 364 if isinstance(v, ConfigContext): |
| 365 assert not submod.CONFIG_CTX, ( | 365 assert not submod.CONFIG_CTX, ( |
| 366 'More than one configuration context: %s, %s' % | 366 'More than one configuration context: %s, %s' % |
| 367 (submod.config, submod.CONFIG_CTX)) | 367 (submod.config, submod.CONFIG_CTX)) |
| 368 submod.CONFIG_CTX = v | 368 submod.CONFIG_CTX = v |
| 369 assert submod.CONFIG_CTX, 'Config file, but no config context?' | 369 assert submod.CONFIG_CTX, 'Config file, but no config context?' |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 modapi = (getattr(mod, 'TEST_API', None) or RecipeTestApi)(module=mod) | 529 modapi = (getattr(mod, 'TEST_API', None) or RecipeTestApi)(module=mod) |
| 530 for k,v in deps.iteritems(): | 530 for k,v in deps.iteritems(): |
| 531 setattr(modapi.m, k, v) | 531 setattr(modapi.m, k, v) |
| 532 return modapi | 532 return modapi |
| 533 | 533 |
| 534 mapper = DependencyMapper(instantiator) | 534 mapper = DependencyMapper(instantiator) |
| 535 api = RecipeTestApi(module=None) | 535 api = RecipeTestApi(module=None) |
| 536 for k,v in toplevel_deps.iteritems(): | 536 for k,v in toplevel_deps.iteritems(): |
| 537 setattr(api, k, mapper.instantiate(v)) | 537 setattr(api, k, mapper.instantiate(v)) |
| 538 return api | 538 return api |
| OLD | NEW |