From 4cf17c3993dfadc8241f8f83965289deefb721d3 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Tue, 7 Jul 2026 13:35:40 +0200 Subject: [PATCH] use stricter ruff rules --- corrlib/__init__.py | 8 +++--- corrlib/__main__.py | 2 +- corrlib/cli.py | 51 +++++++++++++++++------------------ corrlib/find.py | 43 ++++++++++++++--------------- corrlib/git_tools.py | 8 +++--- corrlib/initialization.py | 7 ++--- corrlib/input/__init__.py | 4 +-- corrlib/input/openQCD.py | 48 +++++++++++++++++++-------------- corrlib/input/sfcf.py | 12 ++++----- corrlib/integrity.py | 13 ++++----- corrlib/main.py | 23 ++++++++-------- corrlib/meas_io.py | 32 +++++++++++----------- corrlib/pars/openQCD/flags.py | 3 ++- corrlib/pars/openQCD/ms1.py | 6 ++--- corrlib/pars/openQCD/qcd2.py | 4 +-- corrlib/sql.py | 3 ++- corrlib/toml.py | 17 ++++++------ corrlib/tools.py | 2 +- corrlib/tracker.py | 22 +++++++-------- corrlib/version.py | 10 +++---- 20 files changed, 167 insertions(+), 151 deletions(-) diff --git a/corrlib/__init__.py b/corrlib/__init__.py index 4e1b364..1fd2bee 100644 --- a/corrlib/__init__.py +++ b/corrlib/__init__.py @@ -15,10 +15,10 @@ For now, we are interested in collecting primary IObservables only, as these are __app_name__ = "corrlib" -from .import input as input -from .initialization import create as create -from .meas_io import load_record as load_record -from .meas_io import load_records as load_records +from . import input as input from .find import find_project as find_project from .find import find_record as find_record from .find import list_projects as list_projects +from .initialization import create as create +from .meas_io import load_record as load_record +from .meas_io import load_records as load_records diff --git a/corrlib/__main__.py b/corrlib/__main__.py index 24f9c83..e719ee7 100644 --- a/corrlib/__main__.py +++ b/corrlib/__main__.py @@ -1,4 +1,4 @@ -from corrlib import cli, __app_name__ +from corrlib import __app_name__, cli def main() -> None: diff --git a/corrlib/cli.py b/corrlib/cli.py index a28c837..9d7fcfe 100644 --- a/corrlib/cli.py +++ b/corrlib/cli.py @@ -1,19 +1,18 @@ -from typing import Optional -import typer -from corrlib import __app_name__ - -from .initialization import create -from .toml import import_tomls, update_project, reimport_project -from .find import find_record, list_projects, list_ensembles, get_stat -from .tools import str2list -from .main import update_aliases -from .meas_io import drop_cache as mio_drop_cache -from .integrity import full_integrity_check - import os from importlib.metadata import version from pathlib import Path +import typer + +from corrlib import __app_name__ + +from .find import find_record, get_stat, list_ensembles, list_projects +from .initialization import create +from .integrity import full_integrity_check +from .main import update_aliases +from .meas_io import drop_cache as mio_drop_cache +from .toml import import_tomls, reimport_project, update_project +from .tools import str2list app = typer.Typer() @@ -26,7 +25,7 @@ def _version_callback(value: bool) -> None: @app.command() def update( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -42,7 +41,7 @@ def update( @app.command() def lister( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -73,7 +72,7 @@ def lister( @app.command() def alias_add( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -91,7 +90,7 @@ def alias_add( @app.command() def find( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -100,7 +99,7 @@ def find( corr: str = typer.Argument(), code: str = typer.Argument(), arg: str = typer.Option( - str('all'), + 'all', "--argument", "-a", ), @@ -125,7 +124,7 @@ def find( @app.command() def stat( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -141,7 +140,7 @@ def stat( @app.command() -def check(path: Path = typer.Option( +def check(path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -155,7 +154,7 @@ def check(path: Path = typer.Option( @app.command() def importer( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -163,7 +162,7 @@ def importer( files: str = typer.Argument( ), copy_file: bool = typer.Option( - bool(True), + True, "--save", "-s", ), @@ -179,7 +178,7 @@ def importer( @app.command() def reimporter( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -204,13 +203,13 @@ def reimporter( @app.command() def init( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", ), tracker: str = typer.Option( - str('datalad'), + 'datalad', "--tracker", "-t", ), @@ -224,7 +223,7 @@ def init( @app.command() def drop_cache( - path: Path = typer.Option( + path: Path = typer.Option( # noqa: B008 Path('.'), "--dataset", "-d", @@ -239,7 +238,7 @@ def drop_cache( @app.callback() def main( - version: Optional[bool] = typer.Option( + version: bool | None = typer.Option( None, "--version", "-v", diff --git a/corrlib/find.py b/corrlib/find.py index af21a4d..dd4be13 100644 --- a/corrlib/find.py +++ b/corrlib/find.py @@ -1,21 +1,22 @@ -import sqlite3 -import os -import json -import pandas as pd -import numpy as np -from .input.implementations import codes -from .tools import k2m, get_db_file -from .tracker import get -from .integrity import has_valid_times -from .sql import thin_sql_wrapper -from typing import Any, Optional -from pathlib import Path import datetime as dt +import json +import os +import sqlite3 from collections.abc import Callable -import warnings -from .meas_io import load_record +from pathlib import Path +from typing import Any + +import numpy as np +import pandas as pd from pyerrors import Corr, Obs +from .input.implementations import codes +from .integrity import has_valid_times +from .meas_io import load_record +from .sql import thin_sql_wrapper +from .tools import get_db_file, k2m +from .tracker import get + def _project_lookup_by_alias(path: Path, alias: str) -> str: """ @@ -63,7 +64,7 @@ def _project_lookup_by_id(path: Path, uuid: str) -> list[tuple[str, ...]]: return results -def _time_filter(results: pd.DataFrame, created_before: Optional[str]=None, created_after: Optional[Any]=None, updated_before: Optional[Any]=None, updated_after: Optional[Any]=None) -> pd.DataFrame: +def _time_filter(results: pd.DataFrame, created_before: str | None=None, created_after: str | None=None, updated_before: str | None=None, updated_after: str | None=None) -> pd.DataFrame: """ Filter the results from the database in terms of the creation and update times. @@ -112,7 +113,7 @@ def _time_filter(results: pd.DataFrame, created_before: Optional[str]=None, cre return results.drop(drops) -def _db_lookup(db: Path, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None) -> pd.DataFrame: +def _db_lookup(db: Path, ensemble: str, correlator_name: str, code: str, project: str | None=None, parameters: str | None=None) -> pd.DataFrame: """ Look up a correlator record in the database by the data given to the method. @@ -286,7 +287,7 @@ def openQCD_filter(results:pd.DataFrame, **kwargs: Any) -> pd.DataFrame: The filtered results. """ - warnings.warn("A filter for openQCD parameters is no implemented yet.", Warning) + raise Warning("A filter for openQCD parameters is no implemented yet.") return results @@ -319,10 +320,10 @@ def _code_filter(results: pd.DataFrame, code: str, **kwargs: Any) -> pd.DataFram raise ValueError(f"Code {code} is not known.") -def find_record(path: Path, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None, - created_before: Optional[str]=None, created_after: Optional[str]=None, updated_before: Optional[str]=None, updated_after: Optional[str]=None, - revision: Optional[str]=None, - customFilter: Optional[Callable[[pd.DataFrame], pd.DataFrame]] = None, +def find_record(path: Path, ensemble: str, correlator_name: str, code: str, project: str | None=None, parameters: str | None=None, + created_before: str | None=None, created_after: str | None=None, updated_before: str | None=None, updated_after: str | None=None, + revision: str | None=None, + customFilter: Callable[[pd.DataFrame], pd.DataFrame] | None = None, **kwargs: Any) -> pd.DataFrame: path = Path(path) db_file = get_db_file(path) diff --git a/corrlib/git_tools.py b/corrlib/git_tools.py index d77f109..7808ada 100644 --- a/corrlib/git_tools.py +++ b/corrlib/git_tools.py @@ -1,8 +1,10 @@ import os -from .tracker import save -import git from pathlib import Path +import git + +from .tracker import save + GITMODULES_FILE = '.gitmodules' @@ -25,7 +27,7 @@ def move_submodule(repo_path: Path, old_path: Path, new_path: Path) -> None: gitmodules_file_path = repo_path / GITMODULES_FILE # update paths in .gitmodules - with open(gitmodules_file_path, 'r') as file: + with open(gitmodules_file_path) as file: lines = [line.strip() for line in file] updated_lines = [] diff --git a/corrlib/initialization.py b/corrlib/initialization.py index 99f90d1..83a3b44 100644 --- a/corrlib/initialization.py +++ b/corrlib/initialization.py @@ -1,9 +1,10 @@ -from configparser import ConfigParser -import sqlite3 import os -from .tracker import save, init +import sqlite3 +from configparser import ConfigParser from pathlib import Path + from .tools import CONFIG_FILENAME +from .tracker import init, save def _create_db(db: Path) -> None: diff --git a/corrlib/input/__init__.py b/corrlib/input/__init__.py index be6d6b2..3ccbf28 100644 --- a/corrlib/input/__init__.py +++ b/corrlib/input/__init__.py @@ -2,6 +2,6 @@ Import functions for different codes. """ -from . import sfcf as sfcf -from . import openQCD as openQCD from . import implementations as implementations +from . import openQCD as openQCD +from . import sfcf as sfcf diff --git a/corrlib/input/openQCD.py b/corrlib/input/openQCD.py index 8f5a8a1..eb17fd3 100644 --- a/corrlib/input/openQCD.py +++ b/corrlib/input/openQCD.py @@ -1,14 +1,14 @@ -import pyerrors.input.openQCD as input -import datalad.api as dl -import os import fnmatch -from typing import Any, Optional +import os from pathlib import Path -import matplotlib.pyplot as plt -from ..pars.openQCD import ms1 -from ..pars.openQCD import qcd2 -from ..tools import get_plot_dir +from typing import Any +import datalad.api as dl +import matplotlib.pyplot as plt +import pyerrors.input.openQCD as input + +from ..pars.openQCD import ms1, qcd2 +from ..tools import get_plot_dir def load_ms1_infile(path: Path, project: str, file_in_project: str) -> dict[str, Any]: @@ -32,17 +32,17 @@ def load_ms1_infile(path: Path, project: str, file_in_project: str) -> dict[str, file = os.path.join(path, "projects", project, file_in_project) if not os.path.exists(file): - raise IOError(f"File {file} does not exist.") + raise OSError(f"File {file} does not exist.") ds = os.path.join(path, "projects", project) dl.get(file, dataset=ds) - with open(file, 'r') as fp: + with open(file) as fp: lines = fp.readlines() fp.close() param: dict[str, Any] = {} param['rw_fcts'] = [] param['rand'] = {} - for i, line in enumerate(lines): + for line in lines: if line.startswith('#'): continue if line.startswith('\n'): @@ -99,7 +99,7 @@ def load_ms3_infile(path: Path, project: str, file_in_project: str) -> dict[str, file = os.path.join(path, "projects", project, file_in_project) ds = os.path.join(path, "projects", project) dl.get(file, dataset=ds) - with open(file, 'r') as fp: + with open(file) as fp: lines = fp.readlines() fp.close() param = {} @@ -111,7 +111,7 @@ def load_ms3_infile(path: Path, project: str, file_in_project: str) -> dict[str, return param -def read_rwms(path: Path, project: str, dir_in_project: str, param: dict[str, Any], prefix: str, postfix: str="ms1", version: str='2.0', names: Optional[list[str]]=None, files: Optional[list[str]]=None) -> dict[str, Any]: +def read_rwms(path: Path, project: str, dir_in_project: str, param: dict[str, Any], prefix: str, postfix: str="ms1", version: str='2.0', names: list[str] | None=None, files: list[str] | None=None) -> dict[str, Any]: """ Read reweighting factor measurements from the project. @@ -146,7 +146,7 @@ def read_rwms(path: Path, project: str, dir_in_project: str, param: dict[str, An directory = os.path.join(dataset, dir_in_project) if files is None: files = [] - for root, ds, fs in os.walk(directory): + for _root, _ds, fs in os.walk(directory): for f in fs: if fnmatch.fnmatch(f, prefix + "*" + postfix + ".dat"): files.append(f) @@ -168,8 +168,8 @@ def read_rwms(path: Path, project: str, dir_in_project: str, param: dict[str, An return rw_dict -def extract_t0(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str="", names: Optional[list[str]]=None, files: Optional[list[str]]=None, - r_start: list[int]=[], r_stop: list[int]=[], r_step:int=1) -> dict[str, Any]: +def extract_t0(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str="", names: list[str] | None=None, files: list[str] | None=None, + r_start: list[int] | None=None, r_stop: list[int] | None=None, r_step:int=1) -> dict[str, Any]: """ Extract t0 measurements from the project. @@ -206,11 +206,15 @@ def extract_t0(path: Path, project: str, dir_in_project: str, ensemble: str, par Dictionary of t0 values in the pycorrlib style, with the parameters at hand. """ + if r_stop is None: + r_stop = [] + if r_start is None: + r_start = [] dataset = os.path.join(path, "projects", project) directory = os.path.join(dataset, dir_in_project) if files is None: files = [] - for root, ds, fs in os.walk(directory): + for _root, _ds, fs in os.walk(directory): for f in fs: if fnmatch.fnmatch(f, prefix + "*" + postfix + ".dat"): files.append(f) @@ -252,8 +256,8 @@ def extract_t0(path: Path, project: str, dir_in_project: str, ensemble: str, par return t0_dict -def extract_t1(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str = "", names: Optional[list[str]]=None, files: Optional[list[str]]=None, - r_start: list[int]=[], r_stop: list[int]=[], r_step:int=1) -> dict[str, Any]: +def extract_t1(path: Path, project: str, dir_in_project: str, ensemble: str, param: dict[str, Any], prefix: str, dtr_read: int, xmin: int, spatial_extent: int, fit_range: int = 5, postfix: str = "", names: list[str] | None=None, files: list[str] | None=None, + r_start: list[int] | None=None, r_stop: list[int] | None=None, r_step:int=1) -> dict[str, Any]: """ Extract t1 measurements from the project. @@ -290,10 +294,14 @@ def extract_t1(path: Path, project: str, dir_in_project: str, ensemble: str, par Dictionary of t1 values in the pycorrlib style, with the parameters at hand. """ + if r_stop is None: + r_stop = [] + if r_start is None: + r_start = [] directory = os.path.join(path, "projects", project, dir_in_project) if files is None: files = [] - for root, ds, fs in os.walk(directory): + for _root, _ds, fs in os.walk(directory): for f in fs: if fnmatch.fnmatch(f, prefix + "*" + postfix + ".dat"): files.append(f) diff --git a/corrlib/input/sfcf.py b/corrlib/input/sfcf.py index 1af366f..a12661d 100644 --- a/corrlib/input/sfcf.py +++ b/corrlib/input/sfcf.py @@ -1,11 +1,11 @@ -import pyerrors as pe -import datalad.api as dl import json import os -from typing import Any from fnmatch import fnmatch from pathlib import Path +from typing import Any +import datalad.api as dl +import pyerrors as pe bi_corrs: list[str] = ["f_P", "fP", "f_p", "g_P", "gP", "g_p", @@ -99,7 +99,7 @@ def read_param(path: Path, project: str, file_in_project: str) -> dict[str, Any] file = path / "projects" / project / file_in_project dl.get(file, dataset=path) - with open(file, 'r') as f: + with open(file) as f: lines = f.readlines() params: dict[str, Any] = {} @@ -291,7 +291,7 @@ def read_data(path: Path, project: str, dir_in_project: str, prefix: str, param: appended = (version[-1] == "a") ls = [] files_to_get = [] - for (dirpath, dirnames, filenames) in os.walk(directory): + for _dirpath, dirnames, filenames in os.walk(directory): if not appended: ls.extend(dirnames) else: @@ -299,7 +299,7 @@ def read_data(path: Path, project: str, dir_in_project: str, prefix: str, param: break if not appended: compact = (version[-1] == "c") - for i, item in enumerate(ls): + for item in ls: if fnmatch(item, prefix + "*"): rep_path = directory + '/' + item sub_ls = pe.input.sfcf._find_files(rep_path, prefix, compact, []) diff --git a/corrlib/integrity.py b/corrlib/integrity.py index 66ea4df..abffdb4 100644 --- a/corrlib/integrity.py +++ b/corrlib/integrity.py @@ -1,14 +1,15 @@ import datetime as dt -from pathlib import Path -from .tools import get_db_file, CONFIG_FILENAME -import pandas as pd -import sqlite3 -from .tracker import get -import pyerrors.input.json as pj import os +import sqlite3 from configparser import ConfigParser +from pathlib import Path from typing import Any +import pandas as pd +import pyerrors.input.json as pj + +from .tools import CONFIG_FILENAME, get_db_file +from .tracker import get path_opts = ['db', 'projects_path', 'archive_path', 'toml_imports_path', 'import_scripts_path'] diff --git a/corrlib/main.py b/corrlib/main.py index 5df8165..a0806cf 100644 --- a/corrlib/main.py +++ b/corrlib/main.py @@ -1,17 +1,18 @@ -import sqlite3 -import datalad.api as dl -import datalad.config as dlc import os -from .git_tools import move_submodule import shutil -from .find import _project_lookup_by_id -from .tools import list2str, str2list, get_db_file -from .tracker import get, save, unlock, clone, drop -from typing import Union, Optional +import sqlite3 from pathlib import Path +import datalad.api as dl +import datalad.config as dlc -def create_project(path: Path, uuid: str, owner: Union[str, None]=None, tags: Union[list[str], None]=None, aliases: Union[list[str], None]=None, code: Union[str, None]=None) -> None: +from .find import _project_lookup_by_id +from .git_tools import move_submodule +from .tools import get_db_file, list2str, str2list +from .tracker import clone, drop, get, save, unlock + + +def create_project(path: Path, uuid: str, owner: str | None=None, tags: list[str] | None=None, aliases: list[str] | None=None, code: str | None=None) -> None: """ Create a new project entry in the database. @@ -49,7 +50,7 @@ def create_project(path: Path, uuid: str, owner: Union[str, None]=None, tags: Un return -def update_project_data(path: Path, uuid: str, prop: str, value: Union[str, None] = None) -> None: +def update_project_data(path: Path, uuid: str, prop: str, value: str | None = None) -> None: """ Update/Edit a project entry in the database. Thin wrapper around sql3 call. @@ -102,7 +103,7 @@ def update_aliases(path: Path, uuid: str, aliases: list[str]) -> None: return -def import_project(path: Path, url: str, owner: Union[str, None]=None, tags: Optional[list[str]]=None, aliases: Optional[list[str]]=None, code: Optional[str]=None, isDataset: bool=True) -> str: +def import_project(path: Path, url: str, owner: str | None=None, tags: list[str] | None=None, aliases: list[str] | None=None, code: str | None=None, isDataset: bool=True) -> str: """ Import a datalad dataset into the backlogger. diff --git a/corrlib/meas_io.py b/corrlib/meas_io.py index 52e307e..cd5db2e 100644 --- a/corrlib/meas_io.py +++ b/corrlib/meas_io.py @@ -1,23 +1,23 @@ -from pyerrors.input import json as pj -import os -import sqlite3 -from .input import sfcf,openQCD import json -from typing import Union -from pyerrors import Obs, Corr, dump_object, load_object -from hashlib import sha256 -from .tools import get_db_file, cache_enabled, get_plot_dir -from .tracker import get, save, unlock +import os import shutil -from typing import Any +import sqlite3 +from hashlib import sha256 from pathlib import Path -from .integrity import _check_db2paths +from typing import Any +from pyerrors import Corr, Obs, dump_object, load_object +from pyerrors.input import json as pj + +from .input import openQCD, sfcf +from .integrity import _check_db2paths +from .tools import cache_enabled, get_db_file, get_plot_dir +from .tracker import get, save, unlock CACHE_DIR = ".cache" -def write_measurement(path: Path, ensemble: str, measurement: dict[str, dict[str, dict[str, Any]]], uuid: str, code: str, parameter_file: Union[str, None]) -> None: +def write_measurement(path: Path, ensemble: str, measurement: dict[str, dict[str, dict[str, Any]]], uuid: str, code: str, parameter_file: str | None) -> None: """ Write a measurement to the backlog. If the file for the measurement already exists, update the measurement. @@ -73,7 +73,7 @@ def write_measurement(path: Path, ensemble: str, measurement: dict[str, dict[str pars[subkey] = sfcf.get_specs(corr + "/" + subkey, parameters) elif code == "openQCD": - ms_type = list(measurement.keys())[0] + ms_type = next(iter(measurement.keys())) if ms_type == 'ms1': if parameter_file is not None: if parameter_file.endswith(".ms1.in"): @@ -138,7 +138,7 @@ def write_measurement(path: Path, ensemble: str, measurement: dict[str, dict[str return -def load_record(path: Path, meas_path: str) -> Union[Corr, Obs]: +def load_record(path: Path, meas_path: str) -> Corr | Obs: """ Load a list of records by their paths. @@ -157,7 +157,7 @@ def load_record(path: Path, meas_path: str) -> Union[Corr, Obs]: return load_records(path, [meas_path])[0] -def load_records(path: Path, meas_paths: list[str], preloaded: dict[str, Any] = {}, dry_run: bool = False) -> list[Union[Corr, Obs]]: +def load_records(path: Path, meas_paths: list[str], preloaded: dict[str, Any] | None = None, dry_run: bool = False) -> list[Corr | Obs]: """ Load a list of records by their paths. @@ -177,6 +177,8 @@ def load_records(path: Path, meas_paths: list[str], preloaded: dict[str, Any] = returned_data: list The loaded records. """ + if preloaded is None: + preloaded = {} path = Path(path) if dry_run: _check_db2paths(path, meas_paths) diff --git a/corrlib/pars/openQCD/flags.py b/corrlib/pars/openQCD/flags.py index 95be919..0ab429a 100644 --- a/corrlib/pars/openQCD/flags.py +++ b/corrlib/pars/openQCD/flags.py @@ -5,6 +5,7 @@ Reconstruct the outputs of flags. import struct from typing import Any, BinaryIO + # lat_parms.c def lat_parms_write_lat_parms(fp: BinaryIO) -> dict[str, Any]: """ @@ -29,7 +30,7 @@ def lat_parms_write_lat_parms(fp: BinaryIO) -> dict[str, Any]: kappas = [] m0s = [] # read kappas - for ik in range(nk): + for _ik in range(nk): t = fp.read(8) kappas.append(struct.unpack('d', t)[0]) t = fp.read(8) diff --git a/corrlib/pars/openQCD/ms1.py b/corrlib/pars/openQCD/ms1.py index 4c2aed5..b9b3fc1 100644 --- a/corrlib/pars/openQCD/ms1.py +++ b/corrlib/pars/openQCD/ms1.py @@ -1,7 +1,7 @@ -from . import flags - -from typing import Any from pathlib import Path +from typing import Any + +from . import flags def read_qcd2_ms1_par_file(fname: Path) -> dict[str, dict[str, Any]]: diff --git a/corrlib/pars/openQCD/qcd2.py b/corrlib/pars/openQCD/qcd2.py index e73c156..121c25f 100644 --- a/corrlib/pars/openQCD/qcd2.py +++ b/corrlib/pars/openQCD/qcd2.py @@ -1,8 +1,8 @@ -from . import flags - from pathlib import Path from typing import Any +from . import flags + def read_qcd2_par_file(fname: Path) -> dict[str, dict[str, Any]]: """ diff --git a/corrlib/sql.py b/corrlib/sql.py index f45ce31..fd8e786 100644 --- a/corrlib/sql.py +++ b/corrlib/sql.py @@ -1,8 +1,9 @@ import sqlite3 -from .tools import get_db_file from pathlib import Path from typing import Any +from .tools import get_db_file + def thin_sql_wrapper(path: Path, stmt: str) -> list[Any]: db_file = get_db_file(path) diff --git a/corrlib/toml.py b/corrlib/toml.py index c452dd8..a89e24b 100644 --- a/corrlib/toml.py +++ b/corrlib/toml.py @@ -8,18 +8,19 @@ the import of projects via TOML. """ -import tomllib as toml +import os import shutil +from pathlib import Path +from typing import Any import datalad.api as dl -from .tracker import save -from .input import sfcf, openQCD +import tomllib as toml + +from .input import openQCD, sfcf +from .input.implementations import codes as known_codes from .main import import_project, update_aliases from .meas_io import write_measurement -import os -from .input.implementations import codes as known_codes -from typing import Any -from pathlib import Path +from .tracker import save def replace_string(string: str, name: str, val: str) -> str: @@ -266,7 +267,7 @@ def reimport_project(path: Path, uuid: str) -> None: uuid of the project that is to be reimported. """ config_path = path / "import_scripts" / uuid - for p, filenames, dirnames in os.walk(config_path): + for _p, filenames, _dirnames in os.walk(config_path): for fname in filenames: import_toml(path, os.path.join(config_path, fname), copy_file=False) return diff --git a/corrlib/tools.py b/corrlib/tools.py index 8dec61a..f39a140 100644 --- a/corrlib/tools.py +++ b/corrlib/tools.py @@ -1,7 +1,7 @@ import os from configparser import ConfigParser -from typing import Any from pathlib import Path +from typing import Any CONFIG_FILENAME = ".corrlib" cached: bool = True diff --git a/corrlib/tracker.py b/corrlib/tracker.py index 1581fba..bd84bff 100644 --- a/corrlib/tracker.py +++ b/corrlib/tracker.py @@ -1,11 +1,12 @@ import os -from configparser import ConfigParser -import datalad.api as dl -from typing import Optional import shutil -from .tools import get_db_file, CONFIG_FILENAME +from configparser import ConfigParser from pathlib import Path +import datalad.api as dl + +from .tools import CONFIG_FILENAME, get_db_file + def get_tracker(path: Path) -> str: """ @@ -59,7 +60,7 @@ def get(path: Path, file: Path) -> None: return -def save(path: Path, message: str, files: Optional[list[Path]]=None) -> None: +def save(path: Path, message: str, files: list[Path] | None=None) -> None: """ Wrapper function to save a file to the dataset located at path with the specified tracker. @@ -79,8 +80,7 @@ def save(path: Path, message: str, files: Optional[list[Path]]=None) -> None: files = [path / f for f in files] dl.save(files, message=message, dataset=path) elif tracker == 'None': - Warning("Tracker 'None' does not implement save.") - pass + raise Warning("Tracker 'None' does not implement save.") else: raise ValueError(f"Tracker {tracker} is not supported.") @@ -122,8 +122,7 @@ def unlock(path: Path, file: Path) -> None: if tracker == 'datalad': dl.unlock(os.path.join(path, file), dataset=path) elif tracker == 'None': - Warning("Tracker 'None' does not implement unlock.") - pass + raise Warning("Tracker 'None' does not implement unlock.") else: raise ValueError(f"Tracker {tracker} is not supported.") return @@ -154,7 +153,7 @@ def clone(path: Path, source: str, target: str) -> None: return -def drop(path: Path, reckless: Optional[str]=None) -> None: +def drop(path: Path, reckless: str | None=None) -> None: """ Wrapper function to drop data from a dataset located at path with the specified tracker. @@ -170,8 +169,7 @@ def drop(path: Path, reckless: Optional[str]=None) -> None: if tracker == 'datalad': dl.drop(path, reckless=reckless) elif tracker == 'None': - Warning("Tracker 'None' does not implement drop.") - pass + raise Warning("Tracker 'None' does not implement drop.") else: raise ValueError(f"Tracker {tracker} is not supported.") return diff --git a/corrlib/version.py b/corrlib/version.py index 23dd03f..23ea4de 100644 --- a/corrlib/version.py +++ b/corrlib/version.py @@ -3,12 +3,12 @@ from __future__ import annotations __all__ = [ + "__commit_id__", "__version__", "__version_tuple__", + "commit_id", "version", "version_tuple", - "__commit_id__", - "commit_id", ] version: str @@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...] commit_id: str | None __commit_id__: str | None -__version__ = version = '0.3.1.dev0+g08de17e6b.d20260507' -__version_tuple__ = version_tuple = (0, 3, 1, 'dev0', 'g08de17e6b.d20260507') +__version__ = version = '0.3.1.dev22+g4b1c21309.d20260701' +__version_tuple__ = version_tuple = (0, 3, 1, 'dev22', 'g4b1c21309.d20260701') -__commit_id__ = commit_id = 'g08de17e6b' +__commit_id__ = commit_id = 'g4b1c21309'