def run(self, path: Union[str, Path]) -> TestResult: print("IPYNB run path {}".format(path)) install_python(path) item_requirements = get_item_yaml_requirements(path) #install_requirements(path, ["papermill", "jupyter"] + item_requirements) install_requirements(path, ["papermill"] + item_requirements) click.echo(f"Running tests for {path}...") running_ipynb = Path(path).name + ".ipynb" click.echo(f"Running notebook {running_ipynb}") command = f'pipenv run papermill {running_ipynb} out.ipynb --log-output' completed_process: CompletedProcess = subprocess.run( f"cd {path} ;echo {command} ; {command}", stdout=sys.stdout, stderr=subprocess.PIPE, cwd=path, shell=True) meta_data = {"completed_process": completed_process, "test_path": path} click.echo(completed_process) if completed_process.returncode == 0: return TestResult.passed(status_code=0, meta_data=meta_data) return TestResult.failed( status_code=completed_process.returncode, meta_data=meta_data, )
def collect_temp_requirements(source_dir) -> Set[str]: click.echo("[Temporary project] Starting to collect requirements...") requirements = set() for directory in PathIterator(root=source_dir, rule=is_item_dir, as_path=True): item_requirements = get_item_yaml_requirements(directory) for item_requirement in item_requirements: requirements.add(item_requirement) requirements_txt = directory / "requirements.txt" if requirements_txt.exists(): with open(requirements_txt, "r") as f: lines = f.read().split("\n") for line in filter(lambda l: l, lines): requirements.add(line) parsed = set() for req in requirements: parsed.add(req.split("==")[0]) if _verbose: click.echo( f"[Temporary project] Done requirements ({', '.join(requirements)})" ) return requirements
def run(self, path: Union[str, Path]): install_python(path) item_requirements = get_item_yaml_requirements(path) install_requirements(path, ["pytest"] + item_requirements) click.echo(f"Running tests for {path}...") completed_process: CompletedProcess = subprocess.run( f"cd {path} ; pipenv run python -m pytest", stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path, shell=True, ) meta_data = {"completed_process": completed_process, "test_path": path} if completed_process.returncode == 0: return TestResult.passed(status_code=0, meta_data=meta_data) return TestResult.failed( status_code=completed_process.returncode, meta_data=meta_data, )