def invoke_stage(target_stage: str, stages: Dict[str, Stage], file_system: FileSystem, program_arguments: Dict[str, Any], configuration: Dict[str, Any], remote_proxy: RemoteProxy) -> None: resources = {} pipeline = create_pipeline(target_stage, stages, file_system, program_arguments, configuration) project_directory = file_system.get_working_directory() cache_path = join(project_directory, 'target', 'cache.pickle') for activation, stage_name in pipeline: stage = stages[stage_name] stage_resources = StageResources( stage_name, activation, { resource: resources[resource] for resource in stage.requirements[activation] }, stage.output) stage_program_arguments = get_stage_program_arguments( stage_name, program_arguments) if stage.cacheable: with Cache(file_system, cache_path) as cache: cache[stage_name] = stage_cache = cache.get(stage_name, {}) stage.invoker(file_system, stage_resources, stage_cache, stage_program_arguments, configuration, remote_proxy) else: stage.invoker(file_system, stage_resources, None, stage_program_arguments, configuration, remote_proxy) for resource in stage.output: if resource not in stage_resources: raise ResourceNotSuppliedError( f"stage '{stage_name}' didn't supply resource '{resource}'" ) resources.update(stage_resources.resources)
def has_headers_only(file_system: FileSystem, program_arguments: Dict[str, Any], configuration: Dict[str, Any]): sources_root = join(file_system.get_working_directory(), 'sources') files = file_system.files_in_directory(sources_root) return not program_arguments['global']['executable'] and all( f.endswith('.hpp') or f.endswith('.test.cpp') for f in files)
def has_non_executable_sources(file_system: FileSystem, program_arguments: Dict[str, Any], configuration: Dict[str, Any]): sources_root = join(file_system.get_working_directory(), 'sources') files = file_system.files_in_directory(sources_root) return (not program_arguments['global']['executable'] and all(basename(f) != 'executable.cpp' for f in files) and any( f.endswith('.cpp') and not f.endswith('.test.cpp') for f in files))
def load_pralinefile(file_system: FileSystem, resources: StageResources, cache: Dict[str, Any], program_arguments: Dict[str, Any], configuration: Dict[str, Any], remote_proxy: RemoteProxy): resources[ 'project_directory'] = project_directory = file_system.get_working_directory( ) pralinefile_path = join(project_directory, 'Pralinefile') try: resources['pralinefile'] = pralinefile = pralinefile_from_path( file_system, pralinefile_path) except FileNotFoundError as e: raise FileNotFoundError( f"no Pralinefile was found in current working directory {project_directory}" ) from e architecture = file_system.get_architecture() if architecture not in pralinefile['architectures']: raise UnsupportedArchitectureError( f"system architecture '{architecture}' is not supported -- supported architectures for this project are {pralinefile['architectures']}" ) platform = file_system.get_platform() if platform not in pralinefile['platforms']: raise UnsupportedPlatformError( f"{platform} is not supported -- supported architectures are {pralinefile['platforms']}" ) mode = 'release' if program_arguments['global'][ 'release'] else pralinefile['modes'][0] logging_level = program_arguments['global']['logging_level'] matching_compilers = [ compiler for compiler in get_compilers(file_system, architecture, platform, mode, logging_level) if compiler.matches() ] compilers = [ compiler for compiler in matching_compilers if compiler.get_name() in pralinefile['compilers'] ] if not compilers: raise NoMatchingCompilerFoundError( f"no suitable compiler was found -- matching compilers are {[c.get_name() for c in matching_compilers]} while specified compilers are {pralinefile['compilers']}" ) resources['compiler'] = compilers[0]
from praline.server.configuration import configuration import logging.config logging.config.dictConfig(configuration['logging']) from flask import Flask, send_from_directory, request, Response, jsonify from praline.common.file_system import FileSystem, join from praline.common.hashing import hash_archive from praline.common.package import get_package_dependencies_recursively from typing import Dict file_system = FileSystem() server = Flask(__name__, root_path=file_system.get_working_directory()) repository_path = join(configuration['repository'], 'packages') @server.route('/package/<package>', methods=['GET', 'PUT']) def package(package) -> Response: file_system.create_directory_if_missing(repository_path) if request.method == 'GET': return send_from_directory(repository_path, package, as_attachment=True) elif request.method == 'PUT': package_path = join(repository_path, package) if file_system.exists(package_path): return Response( f"package '{package}' already exists -- increment the version and try again", status=409,
def has_executable(file_system: FileSystem, program_arguments: Dict[str, Any], configuration: Dict[str, Any]): sources_root = join(file_system.get_working_directory(), 'sources') files = file_system.files_in_directory(sources_root) return program_arguments['global']['executable'] or any( basename(f) == 'executable.cpp' for f in files)