This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge djmitche/build-relengapi:issue169 (PR #169)
- Loading branch information
Showing
10 changed files
with
224 additions
and
56 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
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import ConfigParser | ||
import pkg_resources | ||
|
||
_blueprints = None | ||
_distributions = None | ||
|
||
|
||
def _fetch(): | ||
# get blueprints, dists, and so on from pkg_resources. | ||
# | ||
# We're careful to load all of the blueprints exactly once and before | ||
# registering any of them, as this ensures everything is imported before | ||
# any of the @bp.register-decorated methods are called | ||
global _blueprints | ||
global _distributions | ||
|
||
if not _distributions: | ||
_distributions = {} | ||
for dist in pkg_resources.WorkingSet(): | ||
dist.relengapi_metadata = {} | ||
_distributions[dist.key] = dist | ||
|
||
if not _blueprints: | ||
_blueprints = [] | ||
entry_points = (list(pkg_resources.iter_entry_points('relengapi_blueprints')) | ||
+ list(pkg_resources.iter_entry_points('relengapi.blueprints'))) | ||
for ep in entry_points: | ||
bp = ep.load() | ||
# make sure we have only one copy of each Distribution | ||
bp.dist = _distributions[ep.dist.key] | ||
if not bp.dist.relengapi_metadata: | ||
relengapi_metadata = _get_relengapi_metadata(bp.dist) | ||
if relengapi_metadata: | ||
bp.dist.relengapi_metadata = relengapi_metadata | ||
_blueprints.append(bp) | ||
|
||
|
||
def _get_relengapi_metadata(dist): | ||
req = dist.as_requirement() | ||
try: | ||
setup_cfg = pkg_resources.resource_stream(req, 'setup.cfg') | ||
except Exception: | ||
return {} | ||
cfg = ConfigParser.RawConfigParser() | ||
cfg.readfp(setup_cfg) | ||
if not cfg.has_section('relengapi'): | ||
return {} | ||
|
||
return {o: cfg.get('relengapi', o) for o in cfg.options('relengapi')} | ||
|
||
|
||
def get_blueprints(): | ||
_fetch() | ||
return _blueprints | ||
|
||
|
||
def get_distributions(): | ||
_fetch() | ||
return _distributions |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
from nose.tools import eq_ | ||
from relengapi.lib import introspection | ||
|
||
|
||
def test_get_blueprints(): | ||
blueprints = introspection.get_blueprints() | ||
base_blueprint = [bp for bp in blueprints if bp.name == 'base'][0] | ||
eq_(base_blueprint.dist.project_name, 'relengapi') | ||
|
||
|
||
def test_get_distributions(): | ||
distributions = introspection.get_distributions() | ||
eq_(distributions['relengapi'].project_name, 'relengapi') | ||
|
||
|
||
def test_get_relengapi_metadata_this_dist(): | ||
distributions = introspection.get_distributions() | ||
meta = introspection._get_relengapi_metadata(distributions['relengapi']) | ||
assert 'repository_of_record' in meta | ||
|
||
|
||
def test_get_relengapi_metadata_no_data(): | ||
distributions = introspection.get_distributions() | ||
meta = introspection._get_relengapi_metadata(distributions['flask']) | ||
eq_(meta, {}) |
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