Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ruff version #6614

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/system_tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
import tempfile
import time

from aiida.common import StashMode, exceptions
from aiida.engine import run, submit
from aiida.engine.daemon.client import get_daemon_client
from aiida.engine.persistence import ObjectLoader
from aiida.engine.processes import CalcJob, Process
from aiida.manage.caching import enable_caching
from aiida.orm import CalcJobNode, Dict, Int, List, Str, load_code, load_node
from aiida.orm.nodes.caching import NodeCaching
from aiida.plugins import CalculationFactory, WorkflowFactory
from aiida.workflows.arithmetic.add_multiply import add, add_multiply
from workchains import (
ArithmeticAddBaseWorkChain,
CalcFunctionRunnerWorkChain,
Expand All @@ -39,6 +29,16 @@
WorkFunctionRunnerWorkChain,
)

from aiida.common import StashMode, exceptions
from aiida.engine import run, submit
from aiida.engine.daemon.client import get_daemon_client
from aiida.engine.persistence import ObjectLoader
from aiida.engine.processes import CalcJob, Process
from aiida.manage.caching import enable_caching
from aiida.orm import CalcJobNode, Dict, Int, List, Str, load_code, load_node
from aiida.orm.nodes.caching import NodeCaching
from aiida.plugins import CalculationFactory, WorkflowFactory
from aiida.workflows.arithmetic.add_multiply import add, add_multiply
from tests.utils.memory import get_instances

CODENAME_ADD = 'add@localhost'
Expand Down
1 change: 1 addition & 0 deletions .molecule/default/files/polish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import time

import click

from aiida.cmdline.params import options, types
from aiida.cmdline.utils import decorators

Expand Down
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ repos:
args: [--line-length=120, --fail-on-change]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.7.3
hooks:
- id: ruff-format
exclude: &exclude_ruff >
(?x)^(
docs/source/topics/processes/include/snippets/functions/parse_docstring_expose_ipython.py|
docs/source/topics/processes/include/snippets/functions/signature_plain_python_call_illegal.py|
)$
- id: ruff
exclude: *exclude_ruff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know what this did?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was excluding files docs/source/topics/processes/include/snippets/functions/parse_docstring_expose_ipython.py and docs/source/topics/processes/include/snippets/functions/signature_plain_python_call_illegal.py from linting and formatting.

I've moved this configuration to pyproject.toml which I think is a much better place for it. For example, you can now run ruff also manually outside of pre-commit and it will have the same configuration.

args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Script to benchmark the performance of the AiiDA workflow engine on a given installation."""

import click

from aiida.cmdline.params import options
from aiida.cmdline.utils import decorators, echo

Expand Down
3 changes: 2 additions & 1 deletion docs/source/internals/includes/snippets/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
import click
from flask_restful import Resource

from aiida import load_profile
from aiida.restapi import common
from aiida.restapi.api import AiidaApi, App
from aiida.restapi.run_api import run_api
from flask_restful import Resource


class NewResource(Resource):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env runaiida
from aiida.engine import run
from serialize_workchain import SerializeWorkChain

from aiida.engine import run

if __name__ == '__main__':
print(run(SerializeWorkChain, a=1, b=1.2, c=True))
# Result: {'a': 1, 'b': 1.2, 'c': True}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aiida.engine import ToContext, WorkChain
from child import ChildWorkChain

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rearrangement is not that great, but whatever.

from aiida.engine import ToContext, WorkChain


class ComplexParentWorkChain(WorkChain):
@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env runaiida

from complex_parent import ComplexParentWorkChain

from aiida.engine import run
from aiida.orm import Bool, Float, Int
from complex_parent import ComplexParentWorkChain

if __name__ == '__main__':
result = run(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env runaiida

from simple_parent import SimpleParentWorkChain

from aiida.engine import run
from aiida.orm import Bool, Float, Int
from simple_parent import SimpleParentWorkChain

if __name__ == '__main__':
result = run(SimpleParentWorkChain, a=Int(1), b=Float(1.2), c=Bool(True))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from aiida.engine import ToContext, WorkChain
from child import ChildWorkChain

from aiida.engine import ToContext, WorkChain


class SimpleParentWorkChain(WorkChain):
@classmethod
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ testpaths = [
xfail_strict = true

[tool.ruff]
exclude = [
'docs/source/topics/processes/include/snippets/functions/parse_docstring_expose_ipython.py',
'docs/source/topics/processes/include/snippets/functions/signature_plain_python_call_illegal.py'
]
line-length = 120

[tool.ruff.format]
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/cmdline/groups/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def list_options(self, entry_point: str) -> list:
# ``typing.Union[str, None].__args__`` will return the tuple ``(str, NoneType)``. So to get the real type,
# we simply remove all ``NoneType`` and the remaining type should be the type of the option.
if hasattr(field_info.annotation, '__args__'):
args = list(filter(lambda e: e != type(None), field_info.annotation.__args__))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the few changes, I think this is correct, but please check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edan-bainglass I think you familiar with this part?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way a different result can be achieved is when a custom type overwrites the equal function. That is not the case for NoneType, so it is ok.

args = list(filter(lambda e: e is not type(None), field_info.annotation.__args__))
# Click parameters only support specifying a single type, so we default to the first one even if the
# pydantic model defines multiple.
field_type = args[0]
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/engine/processes/workchains/workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _resolve_nested_context(self, key: str) -> tuple[AttributeDict, str]:
# (subclasses of AttributeDict) but after resolution of an Awaitable this will be the value itself
# * assumption: a resolved value is never a plain AttributeDict, on the other hand if a resolved Awaitable
# would be an AttributeDict we can append things to it since the order of tasks is maintained.
if type(ctx) != AttributeDict:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeDict is a class inheriting from dict so the __eq__ function of the type is not overwritten so it is okay here

if type(ctx) is not AttributeDict:
raise ValueError(
f'Can not update the context for key `{key}`:'
f' found instance of `{type(ctx)}` at `{".".join(ctx_path[:index+1])}`, expected AttributeDict'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

from __future__ import annotations

from aiida.common.log import AIIDA_LOGGER
from alembic import op

from aiida.common.log import AIIDA_LOGGER

LOGGER = AIIDA_LOGGER.getChild(__file__)

revision = 'main_0002'
Expand All @@ -39,9 +40,10 @@ def drop_hashes(conn, hash_extra_key: str, entry_point_string: str | None = None
value should be a complete entry point string, e.g., ``aiida.node:process.calculation.calcjob`` to drop the hash
of all ``CalcJobNode`` rows.
"""
from sqlalchemy.sql import text

from aiida.orm.utils.node import get_type_string_from_class
from aiida.plugins import load_entry_point_from_string
from sqlalchemy.sql import text

if entry_point_string is not None:
entry_point = load_entry_point_from_string(entry_point_string)
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from io import StringIO

import pytest

from aiida.common.links import LinkType
from aiida.engine import ProcessState
from aiida.orm import CalcFunctionNode, Dict, load_node
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import pytest

from aiida.engine import WorkChain, run_get_node, while_
from aiida.orm import InstalledCode, Int
from aiida.plugins.factories import CalculationFactory
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from io import StringIO

import pytest

from aiida.common import NotExistent
from aiida.orm import Data, load_node

Expand Down
5 changes: 3 additions & 2 deletions tests/brokers/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

import pytest
import requests
from kiwipy.rmq import RmqThreadCommunicator
from packaging.version import parse

from aiida.brokers.rabbitmq import client, utils
from aiida.engine.processes import ProcessState, control
from aiida.orm import Int
from kiwipy.rmq import RmqThreadCommunicator
from packaging.version import parse

pytestmark = pytest.mark.requires_rmq

Expand Down
1 change: 1 addition & 0 deletions tests/calculations/arithmetic/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Tests for the `ArithmeticAddCalculation` plugin."""

import pytest

from aiida import orm
from aiida.calculations.arithmetic.add import ArithmeticAddCalculation
from aiida.common import datastructures
Expand Down
1 change: 1 addition & 0 deletions tests/calculations/test_templatereplacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io

import pytest

from aiida import orm
from aiida.common import datastructures

Expand Down
1 change: 1 addition & 0 deletions tests/calculations/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os

import pytest

from aiida import orm
from aiida.common import datastructures

Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_archive_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import zipfile

import pytest

from aiida.cmdline.commands import cmd_archive
from aiida.orm import Computer, Dict, Group, InstalledCode
from aiida.storage.sqlite_zip.migrator import list_versions
from aiida.tools.archive import ArchiveFormatSqlZip

from tests.utils.archives import get_archive_file

pytest.mark.usefixtures('chdir_tmp_path')
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_archive_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"""Tests for `verdi archive import`."""

import pytest

from aiida.cmdline.commands import cmd_archive
from aiida.orm import Group
from aiida.storage.sqlite_zip.migrator import list_versions
from aiida.tools.archive import ArchiveFormatSqlZip

from tests.utils.archives import get_archive_file

ARCHIVE_PATH = 'export/migrate'
Expand Down
4 changes: 2 additions & 2 deletions tests/cmdline/commands/test_calcjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import io

import pytest
from click.testing import CliRunner

from aiida import orm
from aiida.cmdline.commands import cmd_calcjob as command
from aiida.common.datastructures import CalcJobState
Expand All @@ -19,8 +21,6 @@
from aiida.orm.nodes.data.remote.base import RemoteData
from aiida.plugins import CalculationFactory
from aiida.plugins.entry_point import get_entry_point_string_from_class
from click.testing import CliRunner

from tests.utils.archives import import_test_archive


Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import click
import pytest

from aiida.cmdline.commands import cmd_code
from aiida.cmdline.params.options.commands.code import validate_label_uniqueness
from aiida.common.exceptions import MultipleObjectsError, NotExistent
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pytest
import yaml

from aiida import orm
from aiida.cmdline.commands.cmd_computer import (
computer_configure,
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Tests for ``verdi config``."""

import pytest

from aiida import get_profile
from aiida.cmdline.commands import cmd_verdi

Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from unittest.mock import patch

import pytest

from aiida import get_profile
from aiida.cmdline.commands import cmd_daemon
from aiida.engine.daemon.client import DaemonClient
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdline/commands/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import numpy as np
import pytest

from aiida import orm
from aiida.cmdline.commands import cmd_group
from aiida.cmdline.commands.cmd_data import (
Expand All @@ -33,7 +34,6 @@
from aiida.engine import calcfunction
from aiida.orm import ArrayData, BandsData, CifData, Dict, Group, KpointsData, RemoteData, StructureData, TrajectoryData
from aiida.orm.nodes.data.cif import has_pycifrw

from tests.static import STATIC_DIR


Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re

import pytest

from aiida.cmdline.commands import cmd_devel
from aiida.orm import Node, ProcessNode, QueryBuilder, WorkChainNode

Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Tests for the `verdi group` command."""

import pytest

from aiida import orm
from aiida.cmdline.commands import cmd_group
from aiida.cmdline.utils.echo import ExitCode
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_group_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from textwrap import dedent

import pytest
from click.testing import CliRunner

from aiida import orm
from aiida.cmdline.commands.cmd_group import group_path_ls
from click.testing import CliRunner


@pytest.fixture
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import warnings

import pytest

from aiida import orm
from aiida.cmdline.commands import cmd_node
from aiida.cmdline.utils.echo import ExitCode
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Tests for the `verdi plugin list` command."""

import pytest

from aiida.cmdline.commands import cmd_plugin
from aiida.parsers import Parser
from aiida.plugins import BaseFactory
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import textwrap

import pytest

from aiida.cmdline.commands.cmd_presto import get_default_presto_profile_name, verdi_presto
from aiida.manage.configuration import profile_context
from aiida.manage.configuration.config import Config
Expand Down
Loading
Loading