def initialize_task_manager( manager: TaskManager, proj: str, task_register: str, directory: Path, substitutions: Dict[str, str], ) -> None: """Load internal and external tasks to the task manager.""" # register task-manager targets from this package assert manager.script( get_resource(os.path.join("lib_tasks", "conf.py")), "register", proj, directory, substitutions, ), "Couldn't register package tasks from '{get_resource(task_register)}'!" # register task-manager targets for the project proj_tasks = directory.joinpath(task_register) if proj_tasks.is_file(): assert manager.script( proj_tasks, "register", proj, directory, substitutions, ), "Couldn't register project tasks from '{proj_tasks}'!"
def entry(args: argparse.Namespace) -> int: """Execute the requested task.""" if not args.file.is_file(): if args.file.name != str(DEFAULT_FILE): LOG.error("'%s' not found", args.file) return 1 args.file = get_resource(os.path.join("data", "header.mk")) # load configuration data, if configuration data is found substitutions, targets = get_data(args.config, args.targets, args.prefix) proj = project(args.dir, args.proj) task_register = os.path.join("tasks", "conf.py") manager = TaskManager() initialize_task_manager( manager, proj, task_register, args.dir, substitutions ) # determine which tasks aren't resolved by the task manager unresolved, executor = manager.prepare_execute(targets, **substitutions) # execute tasks handled by the task manager try: get_event_loop().run_until_complete(executor()) except TaskFailed as exc: print(exc) return 1 retcode = 1 # Handle Make targets if it makes sense to run make. if unresolved and not args.disable_make: invocation_args = ["make", "-C", str(args.dir), "-f"] with build_makefile( args.file, args.dir, proj, substitutions ) as makefile: invocation_args.append(makefile) invocation_args += list(unresolved) LOG.debug(invocation_args) try: result = subprocess.run(invocation_args, check=True) retcode = result.returncode except subprocess.CalledProcessError as exc: retcode = exc.returncode except KeyboardInterrupt: pass # Set the return code to zero if all targets were resolved. elif not unresolved: retcode = 0 else: print( f"The following targets were not resovled: {', '.join(unresolved)}" ) return retcode
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register documentation tasks to the manager.""" manager.register(PydepsTask("python-deps", cwd, project), []) del substitutions return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register unit testing tasks to the manager.""" manager.register(PythonTester("python-test", cwd, project), []) manager.register(PythonTester("python-test-{pattern}", cwd, project), []) del substitutions return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register datazen tasks to the manager.""" manager.register(DatazenTask("dz-sync", cwd), []) del project del substitutions return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register YAML linting tasks to the manager.""" manager.register(Yamllint("yaml-lint-{location}", cwd), []) del project del substitutions return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register package building tasks to the manager.""" # Make sure 'wheel' is also installed so we can build a wheel. reqs = ["venv", "python-install-build"] manager.register(PythonBuild("python-build", cwd, once=False), reqs) manager.register(PythonBuild("python-build-once", cwd), reqs) del project del substitutions return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register package tasks to the manager.""" # Set up initial data so that every task has easy access to common # definitions. init_data = { "__dirs__": { "build": cwd.joinpath("build"), "venv": venv_dir(cwd), "venv_bin": venv_bin(cwd), "proj": cwd.joinpath(project), }, "__files__": { "python": venv_bin(cwd, "python") }, } # Register a task that would always fail for testing. manager.register(FailTask("fail")) # Register the initialization task. manager.register(DictMerger("vmklib.init", init_data, substitutions)) # Load additional modules. result = True for dep in [ register_venv, register_python_lint, register_python_package, register_python_yaml, register_python_build, register_python_sa, register_python_test, register_datazen, register_python_docs, ]: if result: result = dep(manager, project, cwd, substitutions) return result
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register virtual environment tasks to the manager.""" # Ensure that a valid version is set. set_if_not(substitutions, "python_version", _python_version()) # The target that actually creates the initial environment. manager.register(Venv("venv{python_version}", cwd), []) # Add a "phony" style target to just create the virtual environment. Here # We would also add dependencies like requirement-file installs. manager.register(Phony("venv"), ["venv{python_version}"]) # Look for requirements files. requirements_files = [ cwd.joinpath("requirements.txt"), cwd.joinpath("dev_requirements.txt"), cwd.joinpath(project, "requirements.txt"), cwd.joinpath(project, "dev_requirements.txt"), ] # Register requirements' install tasks. manager.register( RequirementsInstaller( "python{python_version}-project-requirements", *list(filter(lambda x: x.is_file(), requirements_files)), ), ["vmklib.init", "venv{python_version}"], ) manager.register( Phony("python-project-requirements"), ["python{python_version}-project-requirements"], ) manager.register_to("venv", ["python-project-requirements"]) return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register Python package tasks to the manager.""" del project del cwd del substitutions manager.register( PythonPackage("python{python_version}-install-{package}"), [] ) manager.register( Phony("python-install-{package}"), ["python{python_version}-install-{package}"], ) manager.register(PythonPackage("python-editable", "-e", package="."), []) return True
def register( manager: TaskManager, project: str, cwd: Path, substitutions: Dict[str, str], ) -> bool: """Register Python linting tasks to the manager.""" manager.register(PythonLinter("python-lint-{linter}", cwd, project), []) line_length = ["--line-length", str(substitutions.get("line_length", 79))] isort_args = line_length + [ "--profile", substitutions.get("isort_profile", "black"), "--fss", "-m", "3", ] manager.register( PythonLinter( "python-format-check-isort", cwd, project, "--check-only", *isort_args, linter="isort", ), [], ) manager.register( PythonLinter( "python-format-isort", cwd, project, *isort_args, linter="isort", ), [], ) manager.register( PythonLinter( "python-format-check-black", cwd, project, "--check", *line_length, linter="black", ), [], ) manager.register( PythonLinter( "python-format-black", cwd, project, *line_length, linter="black", ), # Depend on 'isort' so that we don't format multiple files at the same # time. ["python-format-isort"], ) manager.register( Phony("python-format-check"), ["python-format-check-black", "python-format-check-isort"], ) manager.register( Phony("python-format"), # 'black' depends on 'isort' already. ["python-format-black"], ) manager.register( Phony("python-lint"), [ "python-lint-flake8", "python-lint-pylint", "python-format-check", ], ) return True