Skip to content

Commit 5534620

Browse files
authored
Merge pull request #1 from CQCL/develop
initial commit
2 parents b4458ff + 91c7aaa commit 5534620

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6177
-22
lines changed

.github/workflows/build-test

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
set -evu
3+
4+
# Usage:
5+
#
6+
# build-test [mypy|nomypy]
7+
#
8+
# Arguments:
9+
# - mypy: include mypy check ("mypy" or "nomypy")
10+
#
11+
# Environment variables used:
12+
# - GITHUB_WORKSPACE: workspace directory
13+
#
14+
# WARNING: running this locally will delete any local files that
15+
# aren't strictly part of the git tree, including gitignored files!
16+
17+
MODULE=pytket-qiskit
18+
19+
MYPY=$1
20+
21+
PLAT=`python -c 'import platform; print(platform.system())'`
22+
23+
PYVER=`python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'`
24+
25+
git clean -dfx
26+
27+
echo "Module to test: ${MODULE}"
28+
29+
MODULEDIR="${GITHUB_WORKSPACE}"
30+
31+
ARTIFACTSDIR=${GITHUB_WORKSPACE}/wheelhouse
32+
33+
rm -rf ${ARTIFACTSDIR} && mkdir ${ARTIFACTSDIR}
34+
35+
python -m pip install --upgrade pip wheel build
36+
37+
# Generate and install the package
38+
python -m build
39+
for w in dist/*.whl ; do
40+
python -m pip install $w
41+
cp $w ${ARTIFACTSDIR}
42+
done
43+
44+
# Test and mypy:
45+
if [[ "${MYPY}" = "mypy" ]]
46+
then
47+
python -m pip install --upgrade mypy
48+
fi
49+
50+
cd ${GITHUB_WORKSPACE}/tests
51+
52+
python -m pip install --pre -r test-requirements.txt
53+
54+
pytest --doctest-modules
55+
56+
cd ..
57+
58+
if [[ "${MYPY}" = "mypy" ]]
59+
then
60+
${GITHUB_WORKSPACE}/mypy-check ${GITHUB_WORKSPACE}}
61+
fi

.github/workflows/build_and_test.yml

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Build and test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
push:
9+
branches:
10+
- develop
11+
- 'wheel/**'
12+
release:
13+
types:
14+
- created
15+
- edited
16+
17+
env:
18+
PYTKET_REMOTE_QISKIT_TOKEN: ${{ secrets.PYTKET_REMOTE_QISKIT_TOKEN }}
19+
20+
jobs:
21+
qiskit-checks:
22+
name: Qiskit - Build and test module
23+
strategy:
24+
matrix:
25+
os: ['ubuntu-20.04', 'macos-11', 'windows-2019']
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: '0'
31+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*
32+
- name: Set up Python 3.8
33+
if: github.event_name == 'push'
34+
uses: actions/setup-python@v3
35+
with:
36+
python-version: '3.8'
37+
- name: Build and test (3.8)
38+
if: github.event_name == 'push'
39+
shell: bash
40+
run: |
41+
./.github/workflows/build-test nomypy
42+
- name: Set up Python 3.9
43+
if: github.event_name == 'pull_request' || github.event_name == 'release' || contains(github.ref, 'refs/heads/wheel')
44+
uses: actions/setup-python@v3
45+
with:
46+
python-version: '3.9'
47+
- name: Build and test including remote checks (3.9) mypy
48+
if: (matrix.os == 'macos-11') && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'release' || contains(github.ref, 'refs/heads/wheel'))
49+
shell: bash
50+
run: |
51+
./.github/workflows/build-test mypy
52+
env:
53+
PYTKET_RUN_REMOTE_TESTS: 1
54+
- name: Build and test including remote checks (3.9) nomypy
55+
if: (matrix.os != 'macos-11') && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'release' || contains(github.ref, 'refs/heads/wheel'))
56+
shell: bash
57+
run: |
58+
./.github/workflows/build-test nomypy
59+
env:
60+
PYTKET_RUN_REMOTE_TESTS: 1
61+
- name: Set up Python 3.10
62+
if: github.event_name == 'push' || github.event_name == 'pull_request'
63+
uses: actions/setup-python@v3
64+
with:
65+
python-version: '3.10'
66+
- name: Build and test (3.10)
67+
if: github.event_name == 'push' || github.event_name == 'pull_request'
68+
shell: bash
69+
run: |
70+
./.github/workflows/build-test nomypy
71+
- uses: actions/upload-artifact@v3
72+
if: github.event_name == 'release' || contains(github.ref, 'refs/heads/wheel')
73+
with:
74+
name: artefacts
75+
path: wheelhouse/
76+
- name: Install docs dependencies
77+
if: (matrix.os == 'ubuntu-20.04') && (github.event_name == 'pull_request')
78+
run: |
79+
pip install -r .github/workflows/docs/requirements.txt
80+
- name: Build docs
81+
if: (matrix.os == 'ubuntu-20.04') && (github.event_name == 'pull_request')
82+
timeout-minutes: 20
83+
run: |
84+
./.github/workflows/docs/check-build-docs
85+
86+
87+
publish_to_pypi:
88+
name: Publish to pypi
89+
if: github.event_name == 'release'
90+
needs: qiskit-checks
91+
runs-on: ubuntu-20.04
92+
steps:
93+
- name: Download all wheels
94+
uses: actions/download-artifact@v3
95+
with:
96+
path: wheelhouse
97+
- name: Put them all in the dist folder
98+
run: |
99+
mkdir dist
100+
for w in `find wheelhouse/ -type f -name "*.whl"` ; do cp $w dist/ ; done
101+
- name: Publish wheels
102+
uses: pypa/gh-action-pypi-publish@release/v1
103+
with:
104+
user: __token__
105+
password: ${{ secrets.PYPI_PYTKET_QISKIT_API_TOKEN }}
106+
verbose: true
107+
108+
docs:
109+
name: Build and publish docs
110+
if: github.event_name == 'release'
111+
needs: publish_to_pypi
112+
runs-on: ubuntu-20.04
113+
steps:
114+
- uses: actions/checkout@v3
115+
with:
116+
fetch-depth: '0'
117+
- name: Set up Python 3.9
118+
uses: actions/setup-python@v3
119+
with:
120+
python-version: '3.9'
121+
- name: Download all wheels
122+
uses: actions/download-artifact@v3
123+
with:
124+
path: wheelhouse
125+
- name: Install pip, wheel
126+
run: pip install -U pip wheel
127+
- name: Install extensions
128+
run: for w in `find wheelhouse/ -type f -name "*.whl"` ; do pip install $w ; done
129+
- name: Install docs dependencies
130+
run: |
131+
pip install -r .github/workflows/docs/requirements.txt
132+
- name: Build docs
133+
timeout-minutes: 20
134+
run: |
135+
cd .github/workflows/docs
136+
mkdir extensions
137+
./build-docs -d ${GITHUB_WORKSPACE}/.github/workflows/docs/extensions
138+
- name: Configure git
139+
run: |
140+
git config --global user.email "tket-bot@cambridgequantum.com"
141+
git config --global user.name "«$GITHUB_WORKFLOW» github action"
142+
- name: Check out gh-pages branch
143+
run: git checkout gh-pages
144+
- name: Remove old docs
145+
run: git rm -r --ignore-unmatch docs/api
146+
- name: Add generated docs to repository
147+
run: |
148+
mkdir -p docs
149+
mv .github/workflows/docs/extensions docs/api
150+
git add -f docs/api
151+
git commit --allow-empty -m "Add generated documentation."
152+
- name: Publish docs
153+
run: git push origin gh-pages:gh-pages

.github/workflows/docs.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Pytket Qiskit Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- 'docs/**'
7+
schedule:
8+
# 04:00 every weekday morning
9+
- cron: '0 4 * * 1-5'
10+
11+
jobs:
12+
docs:
13+
name: build docs
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python 3.9
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: 3.9
21+
- name: Upgrade pip and install wheel
22+
run: pip install --upgrade pip wheel
23+
- name: Install pytket qiskit
24+
run: |
25+
pip install .
26+
- name: Install docs dependencies
27+
run: |
28+
pip install -r .github/workflows/docs/requirements.txt
29+
- name: Test building docs
30+
timeout-minutes: 20
31+
run: |
32+
cd .github/workflows/docs
33+
mkdir extensions
34+
./build-docs -d ${GITHUB_WORKSPACE}/.github/workflows/docs/extensions
35+
- uses: actions/upload-artifact@v3
36+
with:
37+
name: pytket-extension-docs
38+
path: .github/workflows/docs/extensions/
57.1 KB
Loading

.github/workflows/docs/build-docs

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import datetime
5+
from importlib import import_module
6+
from pathlib import Path
7+
import shutil
8+
import subprocess
9+
import sys
10+
11+
DOCS_DIR = Path(sys.argv[0]).absolute().parent
12+
MODULES_DIR = DOCS_DIR.parent.parent.parent
13+
PYTKET_DOCS_LINK = "https://cqcl.github.io/tket/pytket/api/index.html"
14+
PYTKET_EX_DOCS_LINK = "https://cqcl.github.io/pytket-extensions/api/index.html"
15+
PYTKET_QISKIT_PYPI_LINK = "https://pypi.org/project/pytket-qiskit/"
16+
PYTKET_QISKIT_GITHUB = "https://github.com/CQCL/pytket-qiskit"
17+
MODULE = "qiskit"
18+
19+
def get_module_version():
20+
m = import_module(f"pytket.extensions.{MODULE}")
21+
return m._metadata.__extension_version__.split(".")
22+
23+
24+
def remove_dir(dirpath):
25+
if dirpath.exists() and dirpath.is_dir():
26+
shutil.rmtree(dirpath)
27+
28+
29+
def fix_links(filepath):
30+
with open(filepath, "r", encoding="utf8") as f:
31+
content = f.read()
32+
content = content.replace("pytket._tket", "pytket")
33+
with open(filepath, "w", encoding="utf8") as f:
34+
f.write(content)
35+
36+
37+
def build_module_docs():
38+
v = get_module_version()
39+
mod_docs = MODULES_DIR / "docs"
40+
mod_build = mod_docs / "build"
41+
conf_copy = mod_docs / "conf.py"
42+
logo_copy = mod_docs / "Quantinuum_logo.png"
43+
shutil.copy(DOCS_DIR / "conf.py", conf_copy)
44+
shutil.copy(DOCS_DIR / "Quantinuum_logo.png", logo_copy)
45+
remove_dir(mod_build)
46+
index_rst = mod_docs / "index.rst"
47+
with open(mod_docs / "intro.txt", "r") as f:
48+
content = f.readlines()
49+
content.append(
50+
"\n.. toctree::\n\t:caption: More documentation:\n\t:maxdepth: 1\n\n"
51+
)
52+
content.append(f"\tpytket <{PYTKET_DOCS_LINK}>\n")
53+
content.append(f"\tpytket extensions <{PYTKET_EX_DOCS_LINK}>\n")
54+
content.append(
55+
"\n.. toctree::\n\t:caption: Links:\n\t:maxdepth: 1\n\n"
56+
)
57+
content.append(f"\tbug tracker <{PYTKET_QISKIT_GITHUB}/issues>\n")
58+
content.append(f"\tGitHub <{PYTKET_QISKIT_GITHUB}>\n")
59+
content.append(f"\tPyPi <{PYTKET_QISKIT_PYPI_LINK}>\n")
60+
61+
with open(index_rst, "w") as f:
62+
f.writelines(content)
63+
subprocess.run(
64+
[
65+
"sphinx-build",
66+
"-b",
67+
"html",
68+
"-D",
69+
f"project=pytket-{MODULE}",
70+
"-D",
71+
f"copyright={datetime.date.today().year} Cambridge Quantum Computing",
72+
"-D",
73+
f"version={'.'.join(v[:2])}",
74+
"-D",
75+
f"release={'.'.join(v)}",
76+
".",
77+
"build",
78+
],
79+
cwd=mod_docs,
80+
)
81+
for htmlfile in mod_build.rglob("*.html"):
82+
fix_links(htmlfile)
83+
fix_links(mod_build / "searchindex.js")
84+
conf_copy.unlink()
85+
logo_copy.unlink()
86+
index_rst.unlink()
87+
88+
89+
if __name__ == "__main__":
90+
parser = argparse.ArgumentParser(
91+
description="Build HTML documentation for pytket-qiskit."
92+
)
93+
parser.add_argument("-d", "--dest", help="copy artifacts into destination folder")
94+
args = parser.parse_args()
95+
96+
print("Building docs for modules:", MODULE)
97+
build_module_docs()
98+
99+
if args.dest is not None:
100+
dest = Path(args.dest)
101+
shutil.copytree(
102+
MODULES_DIR / "docs" / "build",
103+
dest,
104+
dirs_exist_ok=True,
105+
)
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
./.github/workflows/docs/build-docs 1>out.txt 2>err.txt
4+
cat out.txt err.txt
5+
ERRS=`cat err.txt`
6+
if [ ! -z $ERRS ]
7+
then
8+
echo "Docs build failed."
9+
exit 1
10+
fi

0 commit comments

Comments
 (0)