From 9da7676c47982cd03193fe7cf7042708cb106cb8 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Sat, 1 Apr 2023 00:19:03 -0400 Subject: [PATCH 1/5] tox to nox this commit switches current usages of tox to nox. the documentation isn't updated pending results of CI runs. --- .github/workflows/cron-staging.yml | 6 +- .github/workflows/docs.yml | 2 +- .github/workflows/docs_dev.yml | 2 +- .github/workflows/main.yml | 14 +-- .gitignore | 2 +- noxfile.py | 138 +++++++++++++++++++++++++++++ tools/deploy_documentation.sh | 2 +- tools/deploy_documentation_dev.sh | 2 +- tox.ini | 81 ----------------- 9 files changed, 153 insertions(+), 96 deletions(-) create mode 100644 noxfile.py delete mode 100644 tox.ini diff --git a/.github/workflows/cron-staging.yml b/.github/workflows/cron-staging.yml index 587439bd7e..40861ae004 100644 --- a/.github/workflows/cron-staging.yml +++ b/.github/workflows/cron-staging.yml @@ -35,12 +35,12 @@ jobs: ${{ runner.os }}-${{ matrix.python-version }}-pip- ${{ runner.os }}-${{ matrix.python-version }} - name: Install Deps - run: python -m pip install -U tox setuptools virtualenv wheel + run: python -m pip install -U nox setuptools virtualenv wheel - name: Install and Run Tests - run: tox -e terra-main + run: nox -e test-terra-main if: runner.os != 'macOS' - name: Install and Run Tests - run: tox -e terra-main + run: nox -e test-terra-main if: runner.os == 'macOS' env: OMP_NUM_THREADS: 1 \ No newline at end of file diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 26aed14338..dd3ec0dd13 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -18,7 +18,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -U virtualenv setuptools wheel tox + pip install -U virtualenv setuptools wheel nox sudo apt-get install graphviz pandoc - name: Build and publish env: diff --git a/.github/workflows/docs_dev.yml b/.github/workflows/docs_dev.yml index b8813717fa..bd2b89c2fe 100644 --- a/.github/workflows/docs_dev.yml +++ b/.github/workflows/docs_dev.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -U virtualenv setuptools wheel tox + pip install -U virtualenv setuptools wheel nox sudo apt-get install graphviz pandoc - name: Build and publish env: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 09a46c01e0..60fbdc7572 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,12 +40,12 @@ jobs: ${{ runner.os }}-${{ matrix.python-version }}-pip- ${{ runner.os }}-${{ matrix.python-version }} - name: Install Deps - run: python -m pip install -U tox setuptools virtualenv wheel + run: python -m pip install -U nox setuptools virtualenv wheel - name: Install and Run Tests - run: tox -e py + run: nox -e test if: runner.os != 'macOS' - name: Install and Run Tests - run: tox -e py + run: nox -e test if: runner.os == 'macOS' env: OMP_NUM_THREADS: 1 @@ -69,9 +69,9 @@ jobs: ${{ runner.os }}-${{ matrix.python-version }}-pip- ${{ runner.os }}-${{ matrix.python-version }}- - name: Install Deps - run: python -m pip install -U tox + run: python -m pip install -U nox - name: Run lint - run: tox -elint + run: nox -e lint docs: name: docs runs-on: ubuntu-latest @@ -94,10 +94,10 @@ jobs: ${{ runner.os }}- - name: Install Deps run: | - python -m pip install -U tox + python -m pip install -U nox sudo apt-get install -y pandoc graphviz - name: Build Docs - run: tox -edocs + run: nox -e docs - name: Compress Artifacts run: | mkdir artifacts diff --git a/.gitignore b/.gitignore index 28f40a879a..605b5878e8 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ -.tox/ +.nox/ .coverage .coverage.* .cache diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000000..eaf6528bff --- /dev/null +++ b/noxfile.py @@ -0,0 +1,138 @@ +"""Configuration file for nox.""" + +import nox + + +@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"], tags=["ci"]) +def test(session): + """Run CI tests.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + if session.posargs: + posargs = session.posargs + session.install("-r", "requirements-dev.txt") + session.install("-e", ".") + session.run("stestr", "run", *posargs) + + +@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"], tags=["cron"]) +def test_terra_main(session): + """Run CI tests against terra main branch.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + if session.posargs: + posargs = session.posargs + session.install("git+https://github.com/Qiskit/qiskit-terra", "-r", "requirements-dev.txt") + session.install("-e", ".") + session.run("stestr", "run", *posargs) + + +@nox.session(tags=["style"]) +def black(session): + """Runs black.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + session.install("-r", "requirements-dev.txt") + session.install("-e", ".") + session.run("black", "qiskit_experiments", "test", "tools", "setup.py", "docs/conf.py") + + +@nox.session(tags=["docs", "ci"]) +def docs(session): + """Build the full docs.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + session.install("-r", "requirements-dev.txt") + session.install(".") + session.run( + "sphinx-build", "-T", "-W", "--keep-going", "-b", "html", "docs/", "docs/_build/html" + ) + + +@nox.session(tags=["docs"]) +def docs_minimal(session): + """Build the docs without executing code in Jupyter Sphinx cells.""" + session.env["QISKIT_DOCS_SKIP_EXECUTE"] = "1" + session.install("-r", "requirements-dev.txt") + session.install(".") + session.run( + "sphinx-build", "-T", "-W", "--keep-going", "-b", "html", "docs/", "docs/_build/html" + ) + + +@nox.session(tags=["docs"]) +def docs_parallel(session): + """Build the full docs in parallel.""" + session.install("-r", "requirements-dev.txt") + session.install(".") + session.run( + "sphinx-build", + "-j", + "auto", + "-T", + "-W", + "--keep-going", + "-b", + "html", + "docs/", + "docs/_build/html", + ) + + +@nox.session(tags=["style", "lint", "ci"]) +def lint(session): + """Run black and pylint.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + session.install("-r", "requirements-dev.txt") + session.install("-e", ".") + session.run( + "black", "--check", "qiskit_experiments", "test", "tools", "setup.py", "docs/conf.py" + ) + session.run( + "pylint", + "-rn", + "-j", + "0", + "--rcfile=.pylintrc", + "qiskit_experiments/", + "test/", + "tools/", + "docs/conf.py", + ) + session.run( + "python", + "tools/verify_headers.py", + ) + + +@nox.session(tags=["lint"]) +def lint_incr(session): + """Runs lint only on changes compared against the main branch.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + session.install("-r", "requirements-dev.txt") + session.install("-e", ".") + session.run( + "black", "--check", "qiskit_experiments", "test", "tools", "setup.py", "docs/conf.py" + ) + session.run( + "git", + "fetch", + "-q", + "https://github.com/Qiskit/qiskit-experiments", + ":lint_incr_latest", + external=True, + ) + session.run( + "python", + "tools/pylint_incr.py", + "-rn", + "-j4", + "-sn", + "--paths", + ":/qiskit_experiments/*.py", + ":/test/*.py", + ":/tools/*.py", + ) + session.run( + "python", + "tools/verify_headers.py", + "qiskit_experiments", + "test", + "tools", + ) diff --git a/tools/deploy_documentation.sh b/tools/deploy_documentation.sh index 23fea2c370..6c3b18ef20 100755 --- a/tools/deploy_documentation.sh +++ b/tools/deploy_documentation.sh @@ -21,7 +21,7 @@ sudo apt-get install -y ./rclone.deb RCLONE_CONFIG_PATH=$(rclone config file | tail -1) # Build the documentation. -tox -edocs +nox -e docs echo "show current dir: " pwd diff --git a/tools/deploy_documentation_dev.sh b/tools/deploy_documentation_dev.sh index 529c1bd084..12d6383207 100755 --- a/tools/deploy_documentation_dev.sh +++ b/tools/deploy_documentation_dev.sh @@ -21,7 +21,7 @@ sudo apt-get install -y ./rclone.deb RCLONE_CONFIG_PATH=$(rclone config file | tail -1) # Build the documentation. -EXPERIMENTS_DEV_DOCS=1 tox -edocs +EXPERIMENTS_DEV_DOCS=1 nox -e docs echo "show current dir: " pwd diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 427fba47d7..0000000000 --- a/tox.ini +++ /dev/null @@ -1,81 +0,0 @@ -[tox] -minversion = 3.3.0 -envlist = py311,py310,py39,py38,py37,lint -isolated_build = true - -[testenv] -usedevelop = True -install_command = pip install -U {opts} {packages} -setenv = - VIRTUAL_ENV={envdir} - QISKIT_SUPPRESS_PACKAGING_WARNINGS=Y -deps = -r{toxinidir}/requirements-dev.txt -passenv = - OMP_NUM_THREADS - QISKIT_PARALLEL - RAYON_NUM_THREADS - QISKIT_IBM_* -commands = stestr run {posargs} - -[testenv:terra-main] -usedevelop = True -install_command = pip install -U {opts} {packages} -setenv = - VIRTUAL_ENV={envdir} - QISKIT_SUPPRESS_PACKAGING_WARNINGS=Y -deps = - git+https://github.com/Qiskit/qiskit-terra - -r{toxinidir}/requirements-dev.txt -passenv = - OMP_NUM_THREADS - QISKIT_PARALLEL - RAYON_NUM_THREADS - QISKIT_IBM_* -commands = stestr run {posargs} - - -[testenv:lint] -envdir = .tox/lint -commands = - black --check {posargs} qiskit_experiments test tools setup.py - pylint -rn -j 0 --rcfile={toxinidir}/.pylintrc qiskit_experiments/ test/ tools/ - python {toxinidir}/tools/verify_headers.py - -[testenv:lint-incr] -envdir = .tox/lint -basepython = python3 -allowlist_externals = git -commands = - black --check {posargs} qiskit_experiments test tools setup.py - -git fetch -q https://github.com/Qiskit/qiskit-experiments :lint_incr_latest - python {toxinidir}/tools/pylint_incr.py -rn -j4 -sn --paths :/qiskit_experiments/*.py :/test/*.py :/tools/*.py - python {toxinidir}/tools/verify_headers.py qiskit_experiments test tools - -[testenv:black] -envdir = .tox/lint -commands = black {posargs} qiskit_experiments test tools setup.py - -[testenv:docs] -usedevelop = False -passenv = EXPERIMENTS_DEV_DOCS -commands = - sphinx-build -T -W --keep-going -b html {posargs} docs/ docs/_build/html - -[testenv:docs-parallel] -usedevelop = False -passenv = EXPERIMENTS_DEV_DOCS -commands = - sphinx-build -j auto -T -W --keep-going -b html {posargs} docs/ docs/_build/html - -[testenv:docs-minimal] -usedevelop = False -passenv = EXPERIMENTS_DEV_DOCS -setenv = - QISKIT_DOCS_SKIP_EXECUTE = 1 -commands = - sphinx-build -T -W --keep-going -b html {posargs} docs/ docs/_build/html - -[pycodestyle] -max-line-length = 100 - - From 824fc42eee6db5c378f97f038692414e1deaeabe Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Sat, 1 Apr 2023 00:39:37 -0400 Subject: [PATCH 2/5] fixed posargs logic --- noxfile.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index eaf6528bff..8e3eb05770 100644 --- a/noxfile.py +++ b/noxfile.py @@ -7,10 +7,11 @@ def test(session): """Run CI tests.""" session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" - if session.posargs: - posargs = session.posargs session.install("-r", "requirements-dev.txt") session.install("-e", ".") + posargs = {} + if session.posargs: + posargs = session.posargs session.run("stestr", "run", *posargs) @@ -18,10 +19,11 @@ def test(session): def test_terra_main(session): """Run CI tests against terra main branch.""" session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" - if session.posargs: - posargs = session.posargs session.install("git+https://github.com/Qiskit/qiskit-terra", "-r", "requirements-dev.txt") session.install("-e", ".") + posargs = {} + if session.posargs: + posargs = session.posargs session.run("stestr", "run", *posargs) From ffe502a48a2f6f0d0be011408c4d3e67036b795b Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Sat, 1 Apr 2023 00:42:45 -0400 Subject: [PATCH 3/5] fix test version selection --- .github/workflows/cron-staging.yml | 4 ++-- .github/workflows/main.yml | 4 ++-- noxfile.py | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cron-staging.yml b/.github/workflows/cron-staging.yml index 40861ae004..37f8504ab1 100644 --- a/.github/workflows/cron-staging.yml +++ b/.github/workflows/cron-staging.yml @@ -37,10 +37,10 @@ jobs: - name: Install Deps run: python -m pip install -U nox setuptools virtualenv wheel - name: Install and Run Tests - run: nox -e test-terra-main + run: nox -e "test-terra-main-${{ matrix.python-version }}" if: runner.os != 'macOS' - name: Install and Run Tests - run: nox -e test-terra-main + run: nox -e "test-terra-main-${{ matrix.python-version }}" if: runner.os == 'macOS' env: OMP_NUM_THREADS: 1 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60fbdc7572..d768d9da11 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,10 +42,10 @@ jobs: - name: Install Deps run: python -m pip install -U nox setuptools virtualenv wheel - name: Install and Run Tests - run: nox -e test + run: nox -e "test-${{ matrix.python-version }}" if: runner.os != 'macOS' - name: Install and Run Tests - run: nox -e test + run: nox -e "test-${{ matrix.python-version }}" if: runner.os == 'macOS' env: OMP_NUM_THREADS: 1 diff --git a/noxfile.py b/noxfile.py index 8e3eb05770..4a9f73e048 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,8 +2,10 @@ import nox +PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"] -@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"], tags=["ci"]) + +@nox.session(python=PYTHON_VERSIONS, tags=["ci"]) def test(session): """Run CI tests.""" session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" @@ -15,7 +17,7 @@ def test(session): session.run("stestr", "run", *posargs) -@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"], tags=["cron"]) +@nox.session(python=PYTHON_VERSIONS, tags=["cron"]) def test_terra_main(session): """Run CI tests against terra main branch.""" session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" From e506f8fa5c99e31bb478f187956c03de72a2a617 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Sat, 1 Apr 2023 01:02:08 -0400 Subject: [PATCH 4/5] lint `docs/conf.py` --- docs/conf.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e73d8517a2..0e47bcc48c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,6 +10,8 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. +# pylint: disable=invalid-name, wrong-import-position, unused-argument + """ Sphinx documentation builder. """ @@ -178,23 +180,23 @@ def _get_versions(app, config): context = config.html_context start_version = (0, 5, 0) - proc = subprocess.run(["git", "describe", "--abbrev=0"], capture_output=True) + proc = subprocess.run(["git", "describe", "--abbrev=0"], capture_output=True, check=False) proc.check_returncode() current_version = proc.stdout.decode("utf8") current_version_info = current_version.split(".") if current_version_info[0] == "0": version_list = [ - "0.%s" % x for x in range(start_version[1], int(current_version_info[1]) + 1) + f"0.{x}" % x for x in range(start_version[1], int(current_version_info[1]) + 1) ] else: # TODO: When 1.0.0 add code to handle 0.x version list version_list = [] pass context["version_list"] = version_list - context["version_label"] = _get_version_label(current_version) + context["version_label"] = _get_version_label() -def _get_version_label(current_version): +def _get_version_label(): if not os.getenv("EXPERIMENTS_DEV_DOCS", None): return release else: @@ -202,18 +204,19 @@ def _get_version_label(current_version): def setup(app): + """Set up plugins.""" app.connect("config-inited", _get_versions) app.connect("autodoc-skip-member", maybe_skip_member) -# Hardcoded list of class variables to skip in autodoc to avoid warnings -# Should come up with better way to address this - from qiskit_experiments.curve_analysis import ParameterRepr from qiskit_experiments.curve_analysis import SeriesDef def maybe_skip_member(app, what, name, obj, skip, options): + """Hardcoded list of class variables to skip in autodoc to avoid warnings. + TODO: Fix class attribute generation to avoid hardcoding. + """ skip_names = [ "analysis", "set_run_options", From 794042dd1e493a45088803c446f325a92a728317 Mon Sep 17 00:00:00 2001 From: Helena Zhang Date: Sat, 1 Apr 2023 10:34:03 -0400 Subject: [PATCH 5/5] fixed f string --- docs/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0e47bcc48c..b55fe448df 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -185,9 +185,9 @@ def _get_versions(app, config): current_version = proc.stdout.decode("utf8") current_version_info = current_version.split(".") if current_version_info[0] == "0": - version_list = [ - f"0.{x}" % x for x in range(start_version[1], int(current_version_info[1]) + 1) - ] + version_list = list( + f"0.{x}" for x in range(start_version[1], int(current_version_info[1]) + 1) + ) else: # TODO: When 1.0.0 add code to handle 0.x version list version_list = []