From 4af0be838cb6b6f36fc825893f3bd64c2b3c2213 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Mon, 27 Nov 2023 06:38:22 +0100 Subject: [PATCH] Pre-commit: Add automatic formatters for TOML and YAML files Reference YAML files in the unit test suite are excluded. --- .github/workflows/cd.yml | 160 +++++++++++++++++++-------------------- .github/workflows/ci.yml | 92 +++++++++++----------- .pre-commit-config.yaml | 73 ++++++++++-------- pyproject.toml | 150 ++++++++++++++++++------------------ 4 files changed, 242 insertions(+), 233 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 7775a57..c4ec393 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,113 +1,113 @@ name: cd on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+*' + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+* jobs: - validate-release-tag: + validate-release-tag: - if: github.repository == 'microsoft/aiida-pyscf' - runs-on: ubuntu-latest + if: github.repository == 'microsoft/aiida-pyscf' + runs-on: ubuntu-latest - steps: - - name: Checkout source - uses: actions/checkout@v2 + steps: + - name: Checkout source + uses: actions/checkout@v2 - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: '3.10' + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' - - name: Validate the tag version against the package version - run: python .github/workflows/validate_release_tag.py $GITHUB_REF + - name: Validate the tag version against the package version + run: python .github/workflows/validate_release_tag.py $GITHUB_REF - pre-commit: + pre-commit: - needs: [validate-release-tag] - runs-on: ubuntu-latest + needs: [validate-release-tag] + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v2 - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - cache: 'pip' - cache-dependency-path: pyproject.toml + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: pip + cache-dependency-path: pyproject.toml - - name: Update pip and install wheel - run: pip install -U pip wheel + - name: Update pip and install wheel + run: pip install -U pip wheel - - name: Install Python package and dependencies - run: pip install -e .[pre-commit,tests] + - name: Install Python package and dependencies + run: pip install -e .[pre-commit,tests] - - name: Run pre-commit - run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) + - name: Run pre-commit + run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) - tests: + tests: - needs: [validate-release-tag] - runs-on: ubuntu-latest - timeout-minutes: 60 + needs: [validate-release-tag] + runs-on: ubuntu-latest + timeout-minutes: 60 - strategy: - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11'] - services: - rabbitmq: - image: rabbitmq:latest - ports: - - 5672:5672 + services: + rabbitmq: + image: rabbitmq:latest + ports: + - 5672:5672 - steps: - - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v2 - - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: pyproject.toml + - name: Install Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: pyproject.toml - - name: Install system dependencies - run: sudo apt update && sudo apt install postgresql + - name: Install system dependencies + run: sudo apt update && sudo apt install postgresql - - name: Update pip and install wheel - run: pip install -U pip wheel + - name: Update pip and install wheel + run: pip install -U pip wheel - - name: Install Python package and dependencies - run: pip install -e .[tests] + - name: Install Python package and dependencies + run: pip install -e .[tests] - - name: Run pytest - env: - AIIDA_WARN_v3: true - run: pytest -sv tests + - name: Run pytest + env: + AIIDA_WARN_v3: true + run: pytest -sv tests - publish: + publish: - name: Publish to PyPI - needs: [pre-commit, tests] - runs-on: ubuntu-latest + name: Publish to PyPI + needs: [pre-commit, tests] + runs-on: ubuntu-latest - steps: - - name: Checkout source - uses: actions/checkout@v2 + steps: + - name: Checkout source + uses: actions/checkout@v2 - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: '3.10' + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' - - name: Install flit - run: pip install flit~=3.4 + - name: Install flit + run: pip install flit~=3.4 - - name: Build and publish - run: flit publish - env: - FLIT_USERNAME: __token__ - FLIT_PASSWORD: ${{ secrets.PYPI_KEY }} + - name: Build and publish + run: flit publish + env: + FLIT_USERNAME: __token__ + FLIT_PASSWORD: ${{ secrets.PYPI_KEY }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3e2144..2c4a6fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,65 +4,65 @@ on: [push, pull_request] jobs: - pre-commit: + pre-commit: - runs-on: ubuntu-latest + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v2 - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - cache: 'pip' - cache-dependency-path: pyproject.toml + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: pip + cache-dependency-path: pyproject.toml - - name: Update pip and install wheel - run: pip install -U pip wheel + - name: Update pip and install wheel + run: pip install -U pip wheel - - name: Install Python package and dependencies - run: pip install -e .[pre-commit,tests] + - name: Install Python package and dependencies + run: pip install -e .[pre-commit,tests] - - name: Run pre-commit - run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) + - name: Run pre-commit + run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) - tests: + tests: - runs-on: ubuntu-latest - timeout-minutes: 60 + runs-on: ubuntu-latest + timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] + strategy: + fail-fast: false + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11'] - services: - rabbitmq: - image: rabbitmq:latest - ports: - - 5672:5672 + services: + rabbitmq: + image: rabbitmq:latest + ports: + - 5672:5672 - steps: - - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v2 - - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: pyproject.toml + - name: Install Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: pyproject.toml - - name: Install system dependencies - run: sudo apt update && sudo apt install postgresql + - name: Install system dependencies + run: sudo apt update && sudo apt install postgresql - - name: Update pip and install wheel - run: pip install -U pip wheel + - name: Update pip and install wheel + run: pip install -U pip wheel - - name: Install Python package and dependencies - run: pip install -e .[tests] + - name: Install Python package and dependencies + run: pip install -e .[tests] - - name: Run pytest - env: - AIIDA_WARN_v3: true - run: pytest -sv tests + - name: Run pytest + env: + AIIDA_WARN_v3: true + run: pytest -sv tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aa282b1..6ed59e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,36 +1,45 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.2.0' - hooks: - - id: double-quote-string-fixer - - id: end-of-file-fixer - - id: fix-encoding-pragma - - id: mixed-line-ending - - id: trailing-whitespace +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: double-quote-string-fixer + - id: end-of-file-fixer + - id: fix-encoding-pragma + - id: mixed-line-ending + - id: trailing-whitespace -- repo: https://github.com/ikamensh/flynt/ - rev: '0.76' - hooks: - - id: flynt +- repo: https://github.com/ikamensh/flynt/ + rev: '0.76' + hooks: + - id: flynt -- repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.1.6' - hooks: - - id: ruff-format - - id: ruff - args: [--fix, --exit-non-zero-on-fix, --show-fixes] +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.11.0 + hooks: + - id: pretty-format-toml + args: [--autofix] + - id: pretty-format-yaml + args: [--autofix] + exclude: tests/.*.yml -- repo: local - hooks: - - id: mypy - name: mypy - entry: mypy - args: [--config-file=pyproject.toml] - language: python - types: [python] - require_serial: true - pass_filenames: true - files: >- - (?x)^( - src/.*py| - )$ +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff-format + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --show-fixes] + +- repo: local + hooks: + - id: mypy + name: mypy + entry: mypy + args: [--config-file=pyproject.toml] + language: python + types: [python] + require_serial: true + pass_filenames: true + files: >- + (?x)^( + src/.*py| + )$ diff --git a/pyproject.toml b/pyproject.toml index b847cd4..2f5af5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,42 +1,39 @@ [build-system] -requires = ['flit_core>=3.4,<4'] build-backend = 'flit_core.buildapi' +requires = ['flit_core>=3.4,<4'] [project] -name = 'aiida-pyscf' -dynamic = ['description', 'version'] authors = [ - {name = 'Sebastiaan P. Huber', email = 'mail@sphuber.net'}, - {name = 'Adam Grofe', email = 'v-adamgrofe@microsoft.com'} + {name = 'Sebastiaan P. Huber', email = 'mail@sphuber.net'}, + {name = 'Adam Grofe', email = 'v-adamgrofe@microsoft.com'} ] -readme = 'README.md' -license = {file = 'LICENSE.txt'} classifiers = [ - 'Development Status :: 3 - Alpha', - 'Framework :: AiiDA', - 'License :: OSI Approved :: MIT License', - 'Operating System :: POSIX :: Linux', - 'Operating System :: MacOS :: MacOS X', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Topic :: Scientific/Engineering' + 'Development Status :: 3 - Alpha', + 'Framework :: AiiDA', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX :: Linux', + 'Operating System :: MacOS :: MacOS X', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Topic :: Scientific/Engineering' ] -keywords = ['aiida', 'workflows', 'pyscf'] -requires-python = '>=3.8' dependencies = [ - 'aiida-core[atomic_tools]~=2.3', - 'aiida-shell>=0.5.3', - 'dill', - 'numpy', - 'pint', - 'pyscf[geomopt]~=2.2,<2.4', + 'aiida-core[atomic_tools]~=2.3', + 'aiida-shell>=0.5.3', + 'dill', + 'numpy', + 'pint', + 'pyscf[geomopt]~=2.2,<2.4' ] - -[project.urls] -Source = 'https://github.com/microsoft/aiida-pyscf' +dynamic = ['description', 'version'] +keywords = ['aiida', 'workflows', 'pyscf'] +license = {file = 'LICENSE.txt'} +name = 'aiida-pyscf' +readme = 'README.md' +requires-python = '>=3.8' [project.entry-points.'aiida.calculations'] 'pyscf.base' = 'aiida_pyscf.calculations.base:PyscfCalculation' @@ -49,79 +46,82 @@ Source = 'https://github.com/microsoft/aiida-pyscf' [project.optional-dependencies] pre-commit = [ - 'mypy==1.3.0', - 'pre-commit~=2.17', + 'mypy==1.3.0', + 'pre-commit~=2.17' ] tests = [ - 'packaging', - 'pgtest~=1.3,>=1.3.1', - 'pytest~=7.2', - 'pytest-regressions', + 'packaging', + 'pgtest~=1.3,>=1.3.1', + 'pytest~=7.2', + 'pytest-regressions' ] +[project.urls] +Source = 'https://github.com/microsoft/aiida-pyscf' + [tool.flit.module] name = 'aiida_pyscf' [tool.flit.sdist] exclude = [ - 'tests', - '.gitignore', - '.pre-commit-config.yaml', + 'tests', + '.gitignore', + '.pre-commit-config.yaml' ] [tool.flynt] -line-length = 120 fail-on-change = true - -[tool.ruff] line-length = 120 -select = [ - 'E', # pydocstyle - 'W', # pydocstyle - 'F', # pyflakes - 'I', # isort - 'N', # pep8-naming - 'D', # pydocstyle - 'PLC', # pylint-convention - 'PLE', # pylint-error - 'PLR', # pylint-refactor - 'PLW', # pylint-warning - 'RUF', # ruff -] -ignore = [ - 'D203', # Incompatible with D211 `no-blank-line-before-class` - 'D213', # Incompatible with D212 `multi-line-summary-second-line` - 'PLR2004', # Magic value used in comparison -] - -[tool.ruff.format] -quote-style = 'single' [tool.mypy] -show_error_codes = true check_untyped_defs = true -scripts_are_modules = true -warn_unused_ignores = true -warn_redundant_casts = true no_warn_no_return = true +scripts_are_modules = true +show_error_codes = true show_traceback = true +warn_redundant_casts = true +warn_unused_ignores = true [[tool.mypy.overrides]] -module = 'aiida_pyscf.*' -follow_imports = 'skip' check_untyped_defs = true +follow_imports = 'skip' +module = 'aiida_pyscf.*' [[tool.mypy.overrides]] +ignore_missing_imports = true module = [ - 'ase.*', - 'dill.*', - 'pint.*', - 'plumpy.*', - 'ruamel.*', + 'ase.*', + 'dill.*', + 'pint.*', + 'plumpy.*', + 'ruamel.*' ] -ignore_missing_imports = true [tool.pytest.ini_options] filterwarnings = [ - 'ignore:Creating AiiDA configuration folder.*:UserWarning' + 'ignore:Creating AiiDA configuration folder.*:UserWarning' +] + +[tool.ruff] +ignore = [ + 'D203', # Incompatible with D211 `no-blank-line-before-class` + 'D213', # Incompatible with D212 `multi-line-summary-second-line` + 'PLR2004' # Magic value used in comparison ] +line-length = 120 +select = [ + 'E', # pydocstyle + 'W', # pydocstyle + 'F', # pyflakes + 'I', # isort + 'N', # pep8-naming + 'D', # pydocstyle + 'PLC', # pylint-convention + 'PLE', # pylint-error + 'PLR', # pylint-refactor + 'PLW', # pylint-warning + 'RUF' # ruff +] + +[tool.ruff.format] +quote-style = 'single'