def build_extensions(extensions, dist_dir='dist'):
    ext_paths = get_ext_repo_paths()
    all_extensions = find_files(ext_paths, 'setup.py')

    paths_to_build = []
    for path in all_extensions:
        folder = os.path.dirname(path)
        long_name = os.path.basename(folder)
        if long_name in extensions:
            paths_to_build.append(folder)
            extensions.remove(long_name)
    # raise error if any extension wasn't found
    if extensions:
        raise CLIError('extension(s) not found: {}'.format(
            ' '.join(extensions)))

    original_cwd = os.getcwd()
    dist_dir = os.path.join(original_cwd, dist_dir)
    for path in paths_to_build:
        os.chdir(path)
        command = 'setup.py bdist_wheel -b bdist -d {}'.format(dist_dir)
        result = py_cmd(command,
                        "Building extension '{}'...".format(path),
                        is_module=False)
        if result.error:
            raise result.error  # pylint: disable=raising-bad-type
    os.chdir(original_cwd)
Пример #2
0
 def run(paths, rcfile, desc):
     if not paths:
         return None
     logger.debug("Using config file: %s", rcfile)
     logger.debug("Running on %s:\n%s", desc, "\n".join(paths))
     command = "flake8 --statistics --append-config={} {}".format(
         rcfile, " ".join(paths))
     return py_cmd(command, message="Running flake8 on {}...".format(desc))
Пример #3
0
 def run(paths, rcfile, desc):
     if not paths:
         return None
     logger.debug("Using rcfile file: %s", rcfile)
     logger.debug("Running on %s: %s", desc, "\n".join(paths))
     command = "pylint {} --ignore vendored_sdks,privates --rcfile={} -j {}".format(
         " ".join(paths), rcfile, multiprocessing.cpu_count()
     )
     return py_cmd(command, message="Running pylint on {}...".format(desc))
Пример #4
0
 def run(paths, config_file, desc):
     if not paths:
         return None
     config_path = os.path.join(get_azdev_config_dir(), 'config_files',
                                config_file)
     logger.info('Using config file: %s', config_path)
     logger.info('Running on %s: %s', desc, ' '.join(paths))
     command = 'flake8 --statistics --append-config={} {}'.format(
         config_path, ' '.join(paths))
     return py_cmd(command, message='Running flake8 on {}...'.format(desc))
Пример #5
0
 def run(paths, rcfile, desc):
     if not paths:
         return None
     config_path = os.path.join(get_azdev_config_dir(), 'config_files',
                                rcfile)
     logger.info('Using rcfile file: %s', config_path)
     logger.info('Running on %s: %s', desc, ' '.join(paths))
     command = 'pylint {} --ignore vendored_sdks,privates --rcfile={} -j {}'.format(
         ' '.join(paths), config_path, multiprocessing.cpu_count())
     return py_cmd(command, message='Running pylint on {}...'.format(desc))
Пример #6
0
    def run(paths, rcfile, desc, checkers=None, env=None, disable_all=False, enable=None):
        if not paths:
            return None
        logger.debug("Using rcfile file: %s", rcfile)
        logger.debug("Running on %s: %s", desc, "\n".join(paths))
        command = "pylint {} --ignore vendored_sdks,privates --rcfile={} -j {}".format(
            " ".join(paths), rcfile, multiprocessing.cpu_count()
        )
        if checkers is not None:
            command += ' --load-plugins {}'.format(",".join(checkers))
        if disable_all:
            command += ' --disable=all'
        if enable is not None:
            command += ' --enable {}'.format(",".join(enable))

        return py_cmd(command, message="Running pylint on {}...".format(desc), env=env)
Пример #7
0
def _benchmark_cmd_timer(raw_command):
    s = timeit.default_timer()
    py_cmd("azure.cli {}".format(raw_command), is_module=True)
    e = timeit.default_timer()
    return round(e - s, 4)
def _compare_module_against_pypi(results, root_dir, mod, mod_path):
    import zipfile

    version_pattern = re.compile(r'.*azure_cli[^-]*-(\d*.\d*.\d*).*')

    downloaded_path = None
    downloaded_version = None
    build_path = None
    build_version = None

    build_dir = os.path.join(root_dir, mod, 'local')
    pypi_dir = os.path.join(root_dir, mod, 'public')

    # download the public PyPI package and extract the version
    logger.info('Checking %s...', mod)
    result = pip_cmd('download {} --no-deps -d {}'.format(mod, root_dir)).result
    try:
        result = result.decode('utf-8')
    except AttributeError:
        pass
    for line in result.splitlines():
        line = line.strip()
        if line.endswith('.whl') and line.startswith('Saved'):
            downloaded_path = line.replace('Saved ', '').strip()
            downloaded_version = version_pattern.match(downloaded_path).group(1)
            break
        if line.startswith('No matching distribution found'):
            downloaded_path = None
            downloaded_version = 'Unavailable'
            break
    if not downloaded_version:
        raise CLIError('Unexpected error trying to acquire {}: {}'.format(mod, result))

    # build from source and extract the version
    setup_path = os.path.normpath(mod_path.strip())
    os.chdir(setup_path)
    py_cmd('setup.py bdist_wheel -d {}'.format(build_dir))
    if len(os.listdir(build_dir)) != 1:
        raise CLIError('Unexpectedly found multiple build files found in {}.'.format(build_dir))
    build_path = os.path.join(build_dir, os.listdir(build_dir)[0])
    build_version = version_pattern.match(build_path).group(1)

    results[mod].update({
        'local_version': build_version,
        'public_version': downloaded_version
    })

    # OK if package is new
    if downloaded_version == 'Unavailable':
        results[mod]['status'] = 'OK'
        return results
    # OK if local version is higher than what's on PyPI
    if LooseVersion(build_version) > LooseVersion(downloaded_version):
        results[mod]['status'] = 'OK'
        return results

    # slight difference in dist-info dirs, so we must extract the azure folders and compare them
    with zipfile.ZipFile(str(downloaded_path), 'r') as z:
        z.extractall(pypi_dir)

    with zipfile.ZipFile(str(build_path), 'r') as z:
        z.extractall(build_dir)

    errors = _compare_folders(os.path.join(pypi_dir), os.path.join(build_dir))
    # clean up empty strings
    errors = [e for e in errors if e]
    if errors:
        subheading('Differences found in {}'.format(mod))
        for error in errors:
            logger.warning(error)
    results[mod]['status'] = 'OK' if not errors else 'BUMP'

    # special case: to make a release, these MUST be bumped, even if it wouldn't otherwise be necessary
    if mod in ['azure-cli', 'azure-cli-core']:
        if results[mod]['status'] == 'OK':
            logger.warning('%s version must be bumped to support release!', mod)
            results[mod]['status'] = 'BUMP'

    return results