Skip to content

Commit

Permalink
bump ruff + auto-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 20, 2024
1 parent 54a9645 commit 1ebc9a7
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:
exclude: ^(.github/|tests/test_data/abinit/)
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.6
rev: v0.6.1
hooks:
- id: ruff
args: [--fix]
Expand Down
13 changes: 5 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,10 @@ target-version = "py39"
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN002",
"ANN003",
"ANN101", # missing self type annotation
"ANN102", # missing cls annotation
"ANN401",
"ARG002", # unused method argument
# "BLE001",
"ANN002", # Missing type annotation for *arg
"ANN003", # Missing type annotation for **kwargs
"ANN401", # typing.Any disallowed
"ARG002", # unused method argument
"C408", # Unnecessary (dict/list/tuple) call - remove call
"C901", # function too complex
"COM812", # trailing comma missing
Expand All @@ -180,7 +177,7 @@ ignore = [
"FBT001",
"FBT002",
"FIX002",
"G004", # logging uses fstring
"G004", # logging uses f-string
"ISC001",
"PD011", # pandas-use-of-dot-values
"PERF203", # try-except-in-loop
Expand Down
2 changes: 1 addition & 1 deletion tests/abinit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def abinit_integration_tests(pytestconfig):
return pytestconfig.getoption("abinit_integration")


@pytest.fixture()
@pytest.fixture
def mock_abinit(mocker, abinit_test_dir, abinit_integration_tests):
"""
This fixture allows one to mock running ABINIT.
Expand Down
8 changes: 4 additions & 4 deletions tests/aims/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def pytest_addoption(parser):
)


@pytest.fixture()
@pytest.fixture
def si():
return Structure(
lattice=Lattice(
Expand All @@ -45,7 +45,7 @@ def si():
)


@pytest.fixture()
@pytest.fixture
def o2():
return Molecule(species=["O", "O"], coords=[[0, 0, 0.622978], [0, 0, -0.622978]])

Expand All @@ -64,15 +64,15 @@ def ref_path():
return test_dir.resolve()


@pytest.fixture()
@pytest.fixture
def should_mock_aims(request):
try:
return not request.config.getoption("--generate-test-data")
except ValueError:
return True


@pytest.fixture()
@pytest.fixture
def mock_aims(monkeypatch, ref_path, should_mock_aims):
"""
This fixture allows one to mock (fake) running FHI-aims.
Expand Down
2 changes: 1 addition & 1 deletion tests/aims/test_files/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
TEST_DIR = Path(__file__).parent


@pytest.fixture()
@pytest.fixture
def tmp_dir():
"""Same as clean_dir but is fresh for every test"""
import os
Expand Down
14 changes: 7 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def clean_dir(debug_mode):
shutil.rmtree(new_path)


@pytest.fixture()
@pytest.fixture
def tmp_dir():
"""Same as clean_dir but is fresh for every test"""

Expand Down Expand Up @@ -79,7 +79,7 @@ def lpad(database, debug_mode):
lpad.db[coll].drop()


@pytest.fixture()
@pytest.fixture
def memory_jobstore():
store = JobStore(MemoryStore(), additional_stores={"data": MemoryStore()})
store.connect()
Expand All @@ -92,27 +92,27 @@ def log_to_stdout_auto_use():
initialize_logger()


@pytest.fixture()
@pytest.fixture
def si_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "Si.cif")


@pytest.fixture()
@pytest.fixture
def si_diamond(test_dir):
return Structure.from_file(test_dir / "structures" / "Si_diamond.cif")


@pytest.fixture()
@pytest.fixture
def al2_au_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "Al2Au.cif")


@pytest.fixture()
@pytest.fixture
def sr_ti_o3_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "SrTiO3.cif")


@pytest.fixture()
@pytest.fixture
def ba_ti_o3_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "BaTiO3.cif")

Expand Down
4 changes: 2 additions & 2 deletions tests/cp2k/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def cp2k_test_outputs(test_dir):
return Path(test_dir / "cp2k").glob("*/outputs")


@pytest.fixture()
@pytest.fixture
def mock_cp2k(monkeypatch, cp2k_test_dir):
"""
This fixture allows one to mock (fake) running CP2K.
Expand Down Expand Up @@ -169,7 +169,7 @@ def fake_run_cp2k(
logger.info("Generated fake cp2k outputs")


@pytest.fixture()
@pytest.fixture
def check_input():
from pymatgen.io.cp2k.inputs import Cp2kInput

Expand Down
2 changes: 1 addition & 1 deletion tests/qchem/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def qchem_test_dir(test_dir):
return test_dir / "qchem"


@pytest.fixture()
@pytest.fixture
def mock_qchem(
monkeypatch: MonkeyPatch, qchem_test_dir: Path
) -> Generator[Callable[[Any, Any], Any], None, None]:
Expand Down
2 changes: 1 addition & 1 deletion tests/vasp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def lobster_test_dir(test_dir):
return test_dir / "lobster"


@pytest.fixture()
@pytest.fixture
def mock_vasp(
monkeypatch: MonkeyPatch, vasp_test_dir: Path
) -> Generator[Callable[[Any, Any], Any], None, None]:
Expand Down
2 changes: 1 addition & 1 deletion tests/vasp/lobster/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def lobster_test_dir(test_dir):
return test_dir / "lobster"


@pytest.fixture()
@pytest.fixture
def mock_lobster(monkeypatch, lobster_test_dir):
"""
This fixture allows one to mock (fake) running LOBSTER.
Expand Down
42 changes: 20 additions & 22 deletions tutorials/blob_storage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
"metadata": {},
"outputs": [],
"source": [
"from atomate2.vasp.flows.core import StaticMaker\n",
"from jobflow import JobStore, run_locally\n",
"from maggma.stores import MemoryStore\n",
"from pymatgen.core import Structure\n",
"from mock_vasp import mock_vasp, TEST_DIR\n",
"from mock_vasp import TEST_DIR, mock_vasp\n",
"from monty.json import MontyDecoder\n",
"from pymatgen.core import Structure\n",
"from pymatgen.io.vasp import Chgcar\n",
"import numpy as np\n",
"\n",
"def decode(d):\n",
" return MontyDecoder().process_decoded(d)\n",
"from atomate2.vasp.flows.core import StaticMaker\n",
"\n",
"jobstore = JobStore(MemoryStore(), additional_stores={\"data\": MemoryStore()})\n",
"job_store = JobStore(MemoryStore(), additional_stores={\"data\": MemoryStore()})\n",
"si_structure = Structure.from_file(TEST_DIR / \"structures\" / \"Si.cif\")\n",
"ref_paths = {\"static\": \"Si_band_structure/static\"}"
]
Expand Down Expand Up @@ -71,7 +68,7 @@
"metadata": {},
"outputs": [],
"source": [
"static_maker = StaticMaker(task_document_kwargs={\"store_volumetric_data\": (\"chgcar\",)})\n"
"static_maker = StaticMaker(task_document_kwargs={\"store_volumetric_data\": (\"chgcar\",)})"
]
},
{
Expand Down Expand Up @@ -113,13 +110,13 @@
"# create the job\n",
"job = static_maker.make(si_structure)\n",
"# run the job in a mock vasp environment\n",
"# make sure to send the results to the temporary jobstore\n",
"# make sure to send the results to the temporary job store\n",
"with mock_vasp(ref_paths=ref_paths) as mf:\n",
" responses = run_locally(\n",
" job,\n",
" create_folders=True,\n",
" ensure_success=True,\n",
" store=jobstore,\n",
" store=job_store,\n",
" raise_immediately=True,\n",
" )"
]
Expand All @@ -139,11 +136,12 @@
},
"outputs": [],
"source": [
"with jobstore as s:\n",
" result = s.get_output(job.uuid, load=True)\n",
"with job_store as js:\n",
" result = js.get_output(job.uuid, load=True)\n",
"\n",
"chgcar = decode(result[\"vasp_objects\"][\"chgcar\"])\n",
"assert isinstance(chgcar, Chgcar)\n"
"chgcar = MontyDecoder().process_decoded(result[\"vasp_objects\"][\"chgcar\"])\n",
"if not isinstance(chgcar, Chgcar):\n",
" raise TypeError(f\"{type(chgcar)=}\")"
]
},
{
Expand All @@ -159,9 +157,9 @@
"metadata": {},
"outputs": [],
"source": [
"with jobstore as s:\n",
" result_no_obj = s.get_output(job.uuid)\n",
"result_no_obj[\"vasp_objects\"]\n"
"with job_store as js:\n",
" result_no_obj = js.get_output(job.uuid)\n",
"result_no_obj[\"vasp_objects\"]"
]
},
{
Expand All @@ -177,9 +175,9 @@
"metadata": {},
"outputs": [],
"source": [
"seach_data = result_no_obj[\"vasp_objects\"][\"chgcar\"]\n",
"with jobstore.additional_stores[\"data\"] as s:\n",
" blob_data = s.query_one(criteria={\"blob_uuid\": seach_data[\"blob_uuid\"]})"
"search_data = result_no_obj[\"vasp_objects\"][\"chgcar\"]\n",
"with job_store.additional_stores[\"data\"] as js:\n",
" blob_data = js.query_one(criteria={\"blob_uuid\": search_data[\"blob_uuid\"]})"
]
},
{
Expand All @@ -195,7 +193,7 @@
"metadata": {},
"outputs": [],
"source": [
"chgcar2 = decode(blob_data[\"data\"])"
"chgcar2 = MontyDecoder().process_decoded(blob_data[\"data\"])"
]
}
],
Expand All @@ -210,7 +208,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1ebc9a7

Please sign in to comment.