def build_docs(): """ Build the project documentation """ python_call('pip', ['install', 'src/python[docs]']) python_call('pip', ['install', '-r', 'src/python/requirements.txt']) python_call('ipykernel', ['install', '--user', '--name=myproj']) if Path('docs/build').exists(): shutil.rmtree('docs/build') call([ 'sphinx-apidoc', '--module-first', '-o', 'docs/source', 'src/python/myproj' ]) call(['sphinx-build', '-M', 'html', 'docs/source', 'docs/build', '-a'])
def docker_build(args, wheel_dir): """Build a Docker image for the project. Any extra arguments unspecified in this help are passed to `docker build` as is.""" pkg_offline = root / 'python-pkg-offline' try: # re-create python-pkg-offline directory shutil.rmtree(str(pkg_offline), ignore_errors=True) pkg_offline.mkdir(parents=True, exist_ok=True) if wheel_dir: # use provided package wheels, don't download via pip copy_project_wheels(wheel_dir, pkg_offline) else: reqs_path = root / 'src' / 'python' / 'requirements.txt' # download kernelai _kai_version = get_pkg_version(reqs_path, 'kernelai') python_call('pip', [ 'download', '--no-deps', '-d', str(pkg_offline), _kai_version ]) # download kernelviz _kviz_version = get_pkg_version(reqs_path, 'kernelviz') python_call('pip', [ 'download', '--no-deps', '-d', str(pkg_offline), _kviz_version ]) # build docker image # add image tag if only it is not already supplied by the user combined_args = compose_docker_run_args(optional_args=[ ('-t', str(root.name)) ], user_args=list(args)) command = ['docker', 'build'] + combined_args + [str(root)] msg = 'Running build:\n{}'.format(style(' '.join(command), fg='green')) secho(msg) call(command) finally: # remove python-pkg-offline shutil.rmtree(str(pkg_offline), ignore_errors=True)
def docker_run(image, run_args, args): """Run the pipeline in Docker container. Any extra arguments unspecified in this help are passed to `docker run` as is.""" run_args = shlex.split(run_args) image = image or str(root.name) # check that the image exists check_docker_image_exists(image) # default container name container_name = make_container_name(image, "run") _docker_run_args = compose_docker_run_args( host_root=str(root), container_root='/home/kernelai/my_proj_res', mount_volumes=DOCKER_DEFAULT_VOLUMES, optional_args=[("--rm", None), ("--name", container_name)], user_args=list(args)) command = ["docker", "run"] + _docker_run_args + [image] + run_args call(command)
def docker_jupyter_lab(port, image, args): """Run jupyter lab in Docker container. Any extra arguments unspecified in this help are passed to `docker run` as is.""" image = image or str(root.name) # check that the image exists check_docker_image_exists(image) # default container name container_name = make_container_name(image, "jupyter-lab") _docker_run_args = compose_docker_run_args( host_root=str(root), container_root='/home/kernelai/my_proj_res', mount_volumes=DOCKER_DEFAULT_VOLUMES, required_args=[("-p", "{}:8888".format(port))], optional_args=[("--rm", None), ("-it", None), ("--name", container_name)], user_args=list(args)) command = ["docker", "run"] + _docker_run_args \ + [image, "jupyter", "lab", "--ip", "0.0.0.0", "--no-browser"] call(command)
def activate_nbstripout(): """ Install the nbstripout git hook to automatically clean notebooks """ secho( ('Notebook output cells will be automatically cleared before commiting' ' to git.'), fg='yellow') try: import nbstripout # pylint: disable=unused-import except ImportError: raise ClickException(NO_NBSTRIPOUT_MESSAGE) try: res = subprocess.run( ['git', 'rev-parse', '--git-dir'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) if res.returncode: raise ClickException('Not a git repository. Run `git init` first.') except FileNotFoundError: raise ClickException('Git executable not found. Install Git first.') call(['nbstripout', '--install'])
def jupyter_lab(ip, args): """ Open jupyter lab with project specific variables loaded """ if '-h' not in args and '--help' not in args: ipython_mesage() call(['jupyter-lab', '--ip=' + ip] + list(args))
def package(): """ Package the project as a Python egg and wheel """ call([sys.executable, 'setup.py', 'bdist_egg'], cwd='src/python') call([sys.executable, 'setup.py', 'bdist_wheel'], cwd='src/python')
def ipython(args): """ Open ipython with project specific variables loaded """ if '-h' not in args and '--help' not in args: ipython_mesage() call(['ipython'] + list(args))