def autobuild_documentation(tile): """Generate documentation for this module using a combination of sphinx and breathe""" docdir = os.path.join('#doc') docfile = os.path.join(docdir, 'conf.py') outdir = os.path.join('build', 'output', 'doc', tile.unique_id) outfile = os.path.join(outdir, '%s.timestamp' % tile.unique_id) env = Environment(ENV=os.environ, tools=[]) # Only build doxygen documentation if we have C firmware to build from if os.path.exists('firmware'): autobuild_doxygen(tile) env.Depends(outfile, 'doxygen') # There is no /dev/null on Windows # Also disable color output on Windows since it seems to leave powershell # in a weird state. if platform.system() == 'Windows': action = 'sphinx-build --no-color -b html %s %s > NUL' % (docdir[1:], outdir) else: action = 'sphinx-build -b html %s %s > /dev/null' % (docdir[1:], outdir) env.Command(outfile, docfile, action=env.Action(action, "Building Component Documentation")) Alias('documentation', outdir) env.Clean(outfile, outdir)
def build_python_distribution(tile): """Gather support/data files to create python wheel distribution.""" env = Environment(tools=[]) builddir = os.path.join('build', 'python') packagedir = os.path.join(builddir, tile.support_distribution) outdir = os.path.join('build', 'output', 'python') outsrcdir = os.path.join(outdir, 'src') if not tile.has_wheel: return buildfiles = [] datafiles = [] pkg_init = os.path.join(packagedir, '__init__.py') # Make sure we always clean up the temporary python directory that we are creating # so that there are no weird build issues env.Command(pkg_init, [], [ Delete(builddir), Mkdir(builddir), Mkdir(packagedir), Touch(pkg_init) ]) # Make sure build/output/python/src exists # We create a timestamp placeholder file so that other people can depend # on this directory and we always delete it so that we reclean everything # up and don't have any old files. outsrcnode = env.Command(os.path.join(outsrcdir, ".timestamp"), [], [ Delete(outsrcdir), Mkdir(outsrcdir), Touch(os.path.join(outsrcdir, ".timestamp"))]) for outpath, inpath in iter_support_files(tile): outfile = os.path.join(outsrcdir, outpath) buildfile = os.path.join(packagedir, outpath) target = env.Command(outfile, inpath, Copy("$TARGET", "$SOURCE")) env.Depends(target, outsrcnode) target = env.Command(buildfile, inpath, Copy("$TARGET", "$SOURCE")) env.Depends(target, pkg_init) if 'data' in os.path.normpath(buildfile).split(os.sep): datafile = os.path.join(tile.support_distribution, outpath) datafiles.append(datafile) buildfiles.append(buildfile) # Create setup.py file and then use that to build a python wheel and an sdist env['TILE'] = tile env['datafiles'] = datafiles support_sdist = "%s-%s.tar.gz" % (tile.support_distribution, tile.parsed_version.pep440_string()) wheel_output = os.path.join('build', 'python', 'dist', tile.support_wheel) sdist_output = os.path.join('build', 'python', 'dist', support_sdist) env.Clean(os.path.join(outdir, tile.support_wheel), os.path.join('build', 'python')) env.Command([os.path.join(builddir, 'setup.py'), os.path.join(builddir, 'MANIFEST.in'), wheel_output], ['module_settings.json'] + buildfiles, action=Action(generate_setup_and_manifest, "Building python distribution")) env.Depends(sdist_output, wheel_output) env.Command([os.path.join(outdir, tile.support_wheel)], [wheel_output], Copy("$TARGET", "$SOURCE")) env.Command([os.path.join(outdir, support_sdist)], [sdist_output], Copy("$TARGET", "$SOURCE")) # Also copy over all dependency wheels as well wheels = find_dependency_wheels(tile) if "python_universal" in tile.settings: required_version = "py2.py3" else: required_version = "py3" if sys.version_info[0] == 3 else "py2" for wheel in wheels: wheel_name = os.path.basename(wheel) wheel_basename = '-'.join(wheel.split('-')[:-3]) wheel_pattern = wheel_basename + "-*" + required_version + '*' wheel_source = glob.glob(wheel_pattern) wheel_real = glob.glob(wheel_basename + '*') if wheel_source: env.Command([os.path.join(outdir, wheel_name)], [wheel_source[0]], Copy("$TARGET", "$SOURCE")) else: print("This package is set up to require", required_version) print("Dependency version appears to be", wheel_real[0].split('/')[-1]) raise BuildError("dependent wheel not built with compatible python version")