diff --git a/.github/workflows/cron-staging.yml b/.github/workflows/cron-staging.yml index 587439bd7e..37f8504ab1 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-${{ matrix.python-version }}" if: runner.os != 'macOS' - name: Install and Run Tests - run: tox -e 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/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..d768d9da11 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-${{ matrix.python-version }}" if: runner.os != 'macOS' - name: Install and Run Tests - run: tox -e py + run: nox -e "test-${{ matrix.python-version }}" 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/docs/conf.py b/docs/conf.py index e73d8517a2..b55fe448df 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) - ] + 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 = [] 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", diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000000..4a9f73e048 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,142 @@ +"""Configuration file for nox.""" + +import nox + +PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"] + + +@nox.session(python=PYTHON_VERSIONS, tags=["ci"]) +def test(session): + """Run CI tests.""" + session.env["QISKIT_SUPPRESS_PACKAGING_WARNINGS"] = "Y" + session.install("-r", "requirements-dev.txt") + session.install("-e", ".") + posargs = {} + if session.posargs: + posargs = session.posargs + session.run("stestr", "run", *posargs) + + +@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" + 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) + + +@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 - -