Skip to content

Commit 8c7dad6

Browse files
Specify virtual env (#1601)
This PR adds a command line option to the `qml` tool to specify a new or existing virtual environment to use for installing the demo dependencies.
1 parent 9c99f5c commit 8c7dad6

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

documentation/qml-cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ Instructs the build process to use the latest development (unreleased) versions
176176
qml build --dev demo_name
177177
```
178178

179+
##### `--venv`
180+
181+
Specify a new or existing virtual environment to use for installing the demo dependencies. If omitted, the defaul virtual environment name of `.venv-build` will be used.
182+
183+
```bash
184+
qml build --venv .my_env
185+
```
186+
179187

180188
## Viewing Build Outputs
181189

lib/qml/app/app.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import typer
22
from qml.context import Context
3-
from qml.lib import demo, repo, cli, fs, template
3+
from qml.lib import demo, cli, template
44
import shutil
55
import logging
6-
from typing import Annotated, Optional
6+
from typing import Annotated
77
import typing
88
import re
99
import json
@@ -39,7 +39,7 @@ def help():
3939
@app.command()
4040
def build(
4141
demo_names: Annotated[
42-
Optional[list[str]],
42+
list[str] | None,
4343
typer.Argument(
4444
help="Names of demos to build. If not provided, build all demos."
4545
),
@@ -55,6 +55,7 @@ def build(
5555
bool, typer.Option(help="Continue if sphinx-build fails for a demo")
5656
] = False,
5757
dev: Annotated[bool, typer.Option(help="Whether to use dev dependencies")] = False,
58+
venv: Annotated[str | None, typer.Option(help="Name of the virtual environment to install build dependencies")] = None,
5859
) -> None:
5960
"""
6061
Build the named demos.
@@ -66,7 +67,7 @@ def build(
6667
quiet: Suppress sphinx output if True.
6768
keep_going: Continue building even if some demos fail.
6869
dev: Use development dependencies.
69-
70+
venv: Name of the virtual environment to install build dependencies.
7071
Raises:
7172
typer.Exit: If build process fails.
7273
"""
@@ -104,6 +105,7 @@ def build(
104105
quiet=quiet,
105106
keep_going=keep_going,
106107
dev=dev,
108+
venv=venv,
107109
)
108110

109111
except Exception as e:
@@ -165,8 +167,8 @@ def _collect_authors() -> list[dict]:
165167

166168

167169
def _setup_thumbnails(
168-
demo_dir: Path, small_thumb: Optional[Path], large_thumb: Optional[Path]
169-
) -> tuple[Optional[str], Optional[str]]:
170+
demo_dir: Path, small_thumb: Path | None, large_thumb: Path | None
171+
) -> tuple[str | None, str | None]:
170172
"""Verify thumbnail files exist and return their paths."""
171173
small_thumbnail_path = None
172174
large_thumbnail_path = None
@@ -184,8 +186,8 @@ def _create_demo_files(
184186
title: str,
185187
description: str,
186188
authors: list[str],
187-
small_thumbnail: Optional[str],
188-
large_thumbnail: Optional[str],
189+
small_thumbnail: str | None,
190+
large_thumbnail: str | None,
189191
) -> None:
190192
"""Create demo.py and metadata.json files."""
191193
try:

lib/qml/lib/demo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def build(
152152
quiet: bool = False,
153153
keep_going: bool = False,
154154
dev: bool = False,
155+
venv: str | None = None,
155156
) -> None:
156157
"""Build the provided demos using 'sphinx-build', optionally
157158
executing them to generate plots and cell outputs.
@@ -169,7 +170,8 @@ def build(
169170
done = 0
170171
logger.info("Building %d demos", len(demos))
171172

172-
build_venv = Virtualenv(ctx.build_venv_path)
173+
build_venv = Virtualenv(ctx.repo_root / venv) if venv else Virtualenv(ctx.build_venv_path)
174+
logger.info("Using build environment: %s", build_venv.path)
173175
cmds.pip_install(
174176
build_venv.python,
175177
requirements=ctx.build_requirements_file,

poetry.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ---------------------------
44
[project]
55
name = "qml"
6-
version = "0.0.0"
6+
version = "0.1.0"
77
description = "Introductions to key concepts in quantum computing, as well as tutorials and implementations from cutting-edge quantum computing research."
88
readme = "README.md"
99
license = "Apache-2.0"

0 commit comments

Comments
 (0)