diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4922faef..cd9018c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,26 +49,22 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal - # Run ruff (subsumes pyupgrade, isort, flake8+plugins, and more) + # Python linting and formatting using ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.1 + rev: v0.1.4 hooks: - id: ruff args: ["--fix", "--show-fixes"] - - # Run code formatting with Black - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.0 # Keep in sync with blacken-docs - hooks: - - id: black-jupyter + types_or: [python, pyi, jupyter] + - id: ruff-format + types_or: [python, pyi, jupyter] # Also run Black on examples in the documentation - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: - - black==23.10.0 # keep in sync with black hook + additional_dependencies: [black==23.*] # CMake format and lint the CMakeLists.txt files - repo: https://github.com/cheshirekow/cmake-format-precommit @@ -81,7 +77,7 @@ repos: # Clang-format the C++ part of the code base automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.3 + rev: v17.0.4 hooks: - id: clang-format types_or: [c++, c, cuda] diff --git a/docs/source/conf.py b/docs/source/conf.py index 73110f24..d4a72b27 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,5 @@ """Sphinx configuration file.""" + from __future__ import annotations import warnings diff --git a/pyproject.toml b/pyproject.toml index 6dec01a0..e22810e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,6 +141,7 @@ filterwarnings = [ 'ignore:.*qiskit.__qiskit_version__.*:DeprecationWarning:qiskit:', 'ignore:.*qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals*:DeprecationWarning:qiskit', 'ignore:.*Building a flow controller with keyword arguments is going to be deprecated*:PendingDeprecationWarning:qiskit', + 'ignore:.*encountered in det.*:RuntimeWarning:numpy.linalg:', ] [tool.coverage] @@ -151,9 +152,6 @@ report.exclude_also = [ 'if TYPE_CHECKING:', ] -[tool.black] -line-length = 120 - [tool.mypy] files = ["src/mqt", "test/python"] @@ -171,9 +169,14 @@ module = ["qiskit.*"] ignore_missing_imports = true [tool.ruff] -include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"] -select = [ - "E", "F", "W", # flake8 +line-length = 120 +extend-include = ["*.ipynb"] +src = ["src"] +preview = true +unsafe-fixes = true + +[tool.ruff.lint] +extend-select = [ "A", # flake8-builtins "ANN", # flake8-annotations "ARG", # flake8-unused-arguments @@ -212,16 +215,11 @@ select = [ ] extend-ignore = [ "ANN101", # Missing type annotation for self in method - "ANN102", # Missing type annotation for cls in classmethod - "E501", # Line too long (Black is enough) "PLR", # Design related pylint codes ] -src = ["src"] -flake8-unused-arguments.ignore-variadic-names = true isort.required-imports = ["from __future__ import annotations"] -line-length = 120 -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "*.pyi" = ["D"] # pydocstyle "*.ipynb" = [ "D", # pydocstyle diff --git a/src/mqt/qcec/__init__.py b/src/mqt/qcec/__init__.py index 1db4ca03..8ef93e78 100644 --- a/src/mqt/qcec/__init__.py +++ b/src/mqt/qcec/__init__.py @@ -3,6 +3,7 @@ This file is part of the MQT QCEC library released under the MIT license. See README.md or go to https://github.com/cda-tum/qcec for more information. """ + from __future__ import annotations from ._version import version as __version__ diff --git a/src/mqt/qcec/types.py b/src/mqt/qcec/types.py index 0ff60201..42245122 100644 --- a/src/mqt/qcec/types.py +++ b/src/mqt/qcec/types.py @@ -1,4 +1,5 @@ """Types for the QCEC module.""" + from __future__ import annotations from typing import Literal diff --git a/src/mqt/qcec/verify_compilation_flow.py b/src/mqt/qcec/verify_compilation_flow.py index b86de492..58f8854b 100644 --- a/src/mqt/qcec/verify_compilation_flow.py +++ b/src/mqt/qcec/verify_compilation_flow.py @@ -17,6 +17,7 @@ from importlib import resources from qiskit import QuantumCircuit +from qiskit.transpiler.passes import ContainsInstruction from . import ApplicationScheme, Configuration, EquivalenceCheckingManager from .compilation_flow_profiles import AncillaMode, generate_profile_name @@ -30,8 +31,6 @@ def __check_if_circuit_contains_measurements(circuit: QuantumCircuit) -> None: Args: circuit: The circuit to check. """ - from qiskit.transpiler.passes import ContainsInstruction - analysis_pass = ContainsInstruction("measure") analysis_pass(circuit) if not analysis_pass.property_set["contains_measure"]: diff --git a/test/python/test_compilation_flow_profiles.py b/test/python/test_compilation_flow_profiles.py index a1109f0b..7b110202 100644 --- a/test/python/test_compilation_flow_profiles.py +++ b/test/python/test_compilation_flow_profiles.py @@ -12,6 +12,8 @@ else: from importlib import resources +import difflib + import pytest from mqt import qcec @@ -61,8 +63,6 @@ def test_generated_profiles_are_still_valid(optimization_level: int, ancilla_mod if equal: return - import difflib - ref_profile = path.read_text().splitlines(keepends=True) gen_profile = Path(profile_name).read_text().splitlines(keepends=True) diff = difflib.unified_diff(ref_profile, gen_profile, fromfile="reference", tofile="generated", n=0) diff --git a/test/python/test_construction.py b/test/python/test_construction.py index e824e48f..770debf2 100644 --- a/test/python/test_construction.py +++ b/test/python/test_construction.py @@ -2,6 +2,8 @@ from __future__ import annotations +from pathlib import Path + import pytest from qiskit import QuantumCircuit @@ -29,8 +31,6 @@ def test_constructor_with_configuration(example_circuit: QuantumCircuit) -> None def test_default_constructor_with_file(example_circuit: QuantumCircuit) -> None: """Test constructing an instance from two circuit files with all default arguments.""" - from pathlib import Path - filename = "test.qasm" example_circuit.qasm(filename=filename) qcec.EquivalenceCheckingManager(circ1=filename, circ2=filename) diff --git a/test/python/test_verify.py b/test/python/test_verify.py index fd80d221..84e7840d 100644 --- a/test/python/test_verify.py +++ b/test/python/test_verify.py @@ -3,7 +3,8 @@ from __future__ import annotations import pytest -from qiskit import QuantumCircuit +from qiskit import QuantumCircuit, transpile +from qiskit.providers.fake_provider import FakeAthens from mqt import qcec @@ -67,9 +68,6 @@ def test_compiled_circuit_without_measurements() -> None: It makes sure that circuits compiled without measurements are handled correctly. """ - from qiskit import transpile - from qiskit.providers.fake_provider import FakeAthens - qc = QuantumCircuit(1) qc.x(0) qc_compiled = transpile(qc, backend=FakeAthens())