proxygen
utils Namespace Reference

Functions

def recursively_flatten_list (l)
 
def run_command (cmd, kwargs)
 
def make_temp_dir (d)
 
def _inner_read_config (path)
 
def read_fbcode_builder_config (filename)
 
def steps_for_spec (builder, spec, processed_modules=None)
 
def build_fbcode_builder_config (config)
 

Function Documentation

def utils._inner_read_config (   path)
private
Helper to read a named config file.
The grossness with the global is a workaround for this python bug:
https://bugs.python.org/issue21591
The bug prevents us from defining either a local function or a lambda
in the scope of read_fbcode_builder_config below.

Definition at line 42 of file utils.py.

References read_fbcode_builder_config().

43  '''
44  Helper to read a named config file.
45  The grossness with the global is a workaround for this python bug:
46  https://bugs.python.org/issue21591
47  The bug prevents us from defining either a local function or a lambda
48  in the scope of read_fbcode_builder_config below.
49  '''
50  global _project_dir
51  full_path = os.path.join(_project_dir, path)
52  return read_fbcode_builder_config(full_path)
53 
54 
def _inner_read_config(path)
Definition: utils.py:42
def read_fbcode_builder_config(filename)
Definition: utils.py:55
def utils.build_fbcode_builder_config (   config)

Definition at line 93 of file utils.py.

References steps_for_spec().

Referenced by shell_builder.ShellFBCodeBuilder.copy_local_repo().

94  return lambda builder: builder.build(
95  steps_for_spec(builder, config['fbcode_builder_spec'](builder))
96  )
97 
def steps_for_spec(builder, spec, processed_modules=None)
Definition: utils.py:70
def build_fbcode_builder_config(config)
Definition: utils.py:93
def utils.make_temp_dir (   d)

Definition at line 34 of file utils.py.

35  os.mkdir(d)
36  try:
37  yield d
38  finally:
39  shutil.rmtree(d, ignore_errors=True)
40 
41 
def make_temp_dir(d)
Definition: utils.py:34
def utils.read_fbcode_builder_config (   filename)

Definition at line 55 of file utils.py.

Referenced by _inner_read_config(), and shell_builder.ShellFBCodeBuilder.copy_local_repo().

56  # Allow one spec to read another
57  # When doing so, treat paths as relative to the config's project directory.
58  # _project_dir is a "local" for _inner_read_config; see the comments
59  # in that function for an explanation of the use of global.
60  global _project_dir
61  _project_dir = os.path.dirname(filename)
62 
63  scope = {'read_fbcode_builder_config': _inner_read_config}
64  with open(filename) as config_file:
65  code = compile(config_file.read(), filename, mode='exec')
66  exec(code, scope)
67  return scope['config']
68 
69 
def read_fbcode_builder_config(filename)
Definition: utils.py:55
def utils.recursively_flatten_list (   l)

Definition at line 19 of file utils.py.

References type.

Referenced by shell_builder.ShellFBCodeBuilder._render_impl(), and docker_builder.DockerFBCodeBuilder._render_impl().

20  return itertools.chain.from_iterable(
21  (recursively_flatten_list(i) if type(i) is list else (i,))
22  for i in l
23  )
24 
25 
PskType type
def recursively_flatten_list(l)
Definition: utils.py:19
def utils.run_command (   cmd,
  kwargs 
)

Definition at line 26 of file utils.py.

References folly.format().

Referenced by docker_builder.DockerFBCodeBuilder.copy_local_repo().

26 def run_command(*cmd, **kwargs):
27  'The stdout of most fbcode_builder utilities is meant to be parsed.'
28  logging.debug('Running: {0} with {1}'.format(cmd, kwargs))
29  kwargs['stdout'] = sys.stderr
30  subprocess.check_call(cmd, **kwargs)
31 
32 
33 @contextmanager
def run_command(cmd, kwargs)
Definition: utils.py:26
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
Definition: Format.h:271
def utils.steps_for_spec (   builder,
  spec,
  processed_modules = None 
)
Sets `builder` configuration, and returns all the builder steps
necessary to build `spec` and its dependencies.

Traverses the dependencies in depth-first order, honoring the sequencing
in each 'depends_on' list.

Definition at line 70 of file utils.py.

Referenced by build_fbcode_builder_config().

70 def steps_for_spec(builder, spec, processed_modules=None):
71  '''
72  Sets `builder` configuration, and returns all the builder steps
73  necessary to build `spec` and its dependencies.
74 
75  Traverses the dependencies in depth-first order, honoring the sequencing
76  in each 'depends_on' list.
77  '''
78  if processed_modules is None:
79  processed_modules = set()
80  steps = []
81  for module in spec.get('depends_on', []):
82  if module not in processed_modules:
83  processed_modules.add(module)
84  steps.extend(steps_for_spec(
85  builder,
86  module.fbcode_builder_spec(builder),
87  processed_modules
88  ))
89  steps.extend(spec.get('steps', []))
90  return steps
91 
92 
def steps_for_spec(builder, spec, processed_modules=None)
Definition: utils.py:70
Definition: Traits.h:592