Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: recipe_engine/doc.py

Issue 2847623002: [recipes.py] move doc arg parsing to its module (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The LUCI Authors. All rights reserved. 2 # Copyright 2013 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 from __future__ import print_function, absolute_import 6 from __future__ import print_function, absolute_import
7 7
8 import ast 8 import ast
9 import inspect 9 import inspect
10 import json 10 import json
11 import logging 11 import logging
12 import os 12 import os
13 import posixpath 13 import posixpath
14 import sys 14 import sys
15 import types as stdlib_types 15 import types as stdlib_types
16 16
17 from cStringIO import StringIO 17 from cStringIO import StringIO
18 18
19 from . import config 19 from . import config
20 from . import doc_pb2 as doc 20 from . import doc_pb2 as doc
21 from . import loader
21 from . import recipe_api 22 from . import recipe_api
22 from . import types 23 from . import types
23 from . import util 24 from . import util
24 25
25 from . import env 26 from . import env
26 27
27 from google.protobuf import json_format as jsonpb 28 from google.protobuf import json_format as jsonpb
28 from google.protobuf import text_format as textpb 29 from google.protobuf import text_format as textpb
29 30
30 import astunparse 31 import astunparse
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if isinstance(node, ast.ClassDef) and node.name == target: 450 if isinstance(node, ast.ClassDef) and node.name == target:
450 base.known_objects[k].klass.CopyFrom(parse_class(node, relpath, {})) 451 base.known_objects[k].klass.CopyFrom(parse_class(node, relpath, {}))
451 break 452 break
452 elif isinstance(node, ast.FunctionDef) and node.name == target: 453 elif isinstance(node, ast.FunctionDef) and node.name == target:
453 base.known_objects[k].func.CopyFrom(parse_func(node, relpath, {})) 454 base.known_objects[k].func.CopyFrom(parse_func(node, relpath, {}))
454 break 455 break
455 else: 456 else:
456 raise ValueError('could not find %r in %r' % (k, relpath)) 457 raise ValueError('could not find %r in %r' % (k, relpath))
457 458
458 459
459 def main(universe_view, recipe, kind): 460 def add_subparser(parser):
461 doc_kinds=('binarypb', 'jsonpb', 'textpb', 'markdown(github)',
462 'markdown(gitiles)')
463 doc_p = parser.add_parser(
464 'doc',
465 description='List all known modules reachable from the current package, '
466 'with their documentation')
467 doc_p.add_argument('recipe', nargs='?',
468 help='Restrict documentation to this recipe')
469 doc_p.add_argument('--kind', default='jsonpb', choices=doc_kinds,
470 help='Output this kind of documentation')
471
472 doc_p.set_defaults(command='doc', func=main)
473
474
475 def main(package_deps, args):
476 universe = loader.RecipeUniverse(package_deps, args.package)
477 universe_view = loader.UniverseView(universe, package_deps.root_package)
478
460 logging.basicConfig() 479 logging.basicConfig()
461 480
462 spec = universe_view.package.repo_spec.spec_pb() 481 spec = universe_view.package.repo_spec.spec_pb()
463 base_dir = universe_view.package.repo_root 482 base_dir = universe_view.package.repo_root
464 if spec.recipes_path: 483 if spec.recipes_path:
465 base_dir = join(base_dir, spec.recipes_path) 484 base_dir = join(base_dir, spec.recipes_path)
466 485
467 if recipe: 486 if args.recipe:
468 recipe_fullpath = universe_view.find_recipe(recipe) 487 recipe_fullpath = universe_view.find_recipe(args.recipe)
469 relpath = _to_posix(os.path.relpath(recipe_fullpath, base_dir)) 488 relpath = _to_posix(os.path.relpath(recipe_fullpath, base_dir))
470 node = parse_recipe(universe_view, base_dir, relpath, recipe) 489 node = parse_recipe(universe_view, base_dir, relpath, args.recipe)
471 else: 490 else:
472 node = parse_package(universe_view, base_dir, spec) 491 node = parse_package(universe_view, base_dir, spec)
473 492
474 _set_known_objects(node) 493 _set_known_objects(node)
475 494
476 if kind == 'jsonpb': 495 if args.kind == 'jsonpb':
477 sys.stdout.write(jsonpb.MessageToJson( 496 sys.stdout.write(jsonpb.MessageToJson(
478 node, including_default_value_fields=True, 497 node, including_default_value_fields=True,
479 preserving_proto_field_name=True)) 498 preserving_proto_field_name=True))
480 elif kind == 'binarypb': 499 elif args.kind == 'binarypb':
481 sys.stdout.write(node.SerializeToString()) 500 sys.stdout.write(node.SerializeToString())
482 elif kind == 'textpb': 501 elif args.kind == 'textpb':
483 sys.stdout.write(textpb.MessageToString(node)) 502 sys.stdout.write(textpb.MessageToString(node))
484 else: 503 else:
485 raise NotImplementedError('--kind=%s' % kind) 504 raise NotImplementedError('--kind=%s' % args.kind)
OLDNEW
« no previous file with comments | « no previous file | recipes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698